【发布时间】:2019-12-11 11:07:30
【问题描述】:
问题已解决: 发布在下面的答案部分
问题
将 kotlin 版本升级到 1.3.61 后。我无法使用withContext、Dispatchers IO, Main 没有任何效果。它显示未解决的参考。 kotlin 的新更新中是否有任何错误?要不然是啥?因为之前一切正常。
我已经打开了我的旧项目相同的错误unresolved reference,每个协程函数都像我说的withContext() 等。但是suspend 关键字正在使用小协程图标/标记也显示,当我尝试调用另一个suspend功能。
我尝试什么?
将 kotlin 版本降级为 1.3.50 或尝试升级协程版本 1.3.61(这很愚蠢)但没有任何效果..
不断尝试寻找,但不幸的是找不到任何解决方法。
制作了一个新项目并尝试在 onCreate() 方法中使用,但仍然相同。
编辑:
添加 gradles:
build.gradle(Module:应用程序)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.daggerpractise"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Dagger 2
implementation 'com.google.dagger:dagger:2.15'
kapt 'com.google.dagger:dagger-compiler:2.15'
// For android
implementation 'com.google.dagger:dagger-android:2.15'
implementation 'com.google.dagger:dagger-android-support:2.15'
// if you use the support libraries
kapt 'com.google.dagger:dagger-android-processor:2.15'
// AndroidX support design (for nav drawer)
// def material_version = "1.0.0-rc02"
def material_version = "1.0.0"
implementation "com.google.android.material:material:$material_version"
implementation 'com.github.bumptech.glide:glide:4.10.0'
kapt 'com.github.bumptech.glide:compiler:4.10.0'
//MVVM and livedata
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.1'
// RxJava
def rxjava_version = '2.1.1'
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
// Rx-Retrofit Call Adapter
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.5.0'
// Retrofit call adapter
// Kotlin Android Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2'
}
build.gradle(项目:DaggerPractise)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
【问题讨论】:
-
你们是否都包括: implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2' ?
-
@NicolaGallazzi 两者都是,但我删除了一次
core,但也没有用。 -
请发布您的应用程序 gradle
-
@NicolaGallazzi 更新了,看看看看。
标签: android android-studio kotlin kotlin-coroutines