Xsi*_*ims 5 android kotlin android-lint android-studio kotlin-coroutines
我已经尝试过使缓存无效。清理构建和重建项目也已完成。但我仍然不断收到以下未解决的参考:Dispatchers、launch、withContext、delay...但是 CoroutineScope没有标记为未解决的参考,即import kotlinx.coroutines。* 未标记为未知,并且该项目正在编译(它已经工作了几个月,它不是最近的项目)。
安卓工作室:4.0.1
设置 > 语言和框架 > Kotlin :当前kotlin 插件版本:1.4.10-release-Studio4.0-1
构建.gradle
buildscript {
ext {
// KOTLIN
kotlin_coroutines_version = '1.3.5'
kotlin_version = '1.3.71'
...
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Run Code Online (Sandbox Code Playgroud)
模块构建.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), '../proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
testOptions {
unitTests.returnDefaultValues = true
unitTests {
all {
testLogging {
events 'passed', 'skipped', 'failed'
}
}
}
}
}
dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
}
Run Code Online (Sandbox Code Playgroud)
编辑: 我的代码示例,但请记住此错误出现在我的项目中的所有文件中(几乎 100 个文件)。我的代码正在运行,因为我可以在一周内对其进行处理。
init {
CoroutineScope(Dispatchers.Main).launch {
...
withContext(Dispatchers.IO) {
delay(1000 * 5)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我找到了两种方法来修复它(尽管仍然不确定为什么会发生这个错误):
在我的笔记本电脑上,我只是将 Android Studio 更新到版本 4.1.0,重新启动后,所有 lint 错误都消失了。
在我同事的笔记本电脑上,我们kotlin_coroutines_version从 1.3.5 升级到 1.4.0+ :
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1864 次 |
| 最近记录: |