Jac*_*Saf 5 kotlin android-studio android-gradle-plugin kotlin-coroutines coroutinescope
尝试使用 room api 并且必须处理异步任务,你知道为什么。我选择了 kotlin 协程和 androidx.lifecycle。尝试编写一些代码并在 IDE 中显示 2 个错误
无法访问“kotlinx.coroutines.CoroutineScope”,它是“androidx.lifecycle.LifecycleCoroutineScope”的超类型。检查模块类路径是否缺少或冲突的依赖项无法访问类“kotlinx.coroutines.Job”。检查模块类路径是否存在缺少或冲突的依赖项 错误
这是我的 gradle 模块
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.jacksafblaze.sqlitedemo"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures{
viewBinding true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "androidx.room:room-ktx:2.3.0"
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0"
implementation'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
implementation'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:5'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Run Code Online (Sandbox Code Playgroud)
和 gradle 项目
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
我尝试使缓存无效并重新启动,从头开始重新创建应用程序,并重新安装 android studio,但我仍然收到此错误。
将 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' 升级为 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0-RC' 一切正常
| 归档时间: |
|
| 查看次数: |
3727 次 |
| 最近记录: |