将 Android Studio 和 gradle 更新到版本 3.3.0 后,我无法编译我的应用程序。 Kotlin Android 扩展提供的 View 不起作用。我引用的所有 View 均出现“未解析的引用:xxx”编译错误。
在 gradle 和 Android Studio 的先前版本中,我的代码可以正常工作。 我尝试清理并重建我的项目,使缓存无效并重新启动 Android Studio 并创建一个新项目并将我的代码复制并粘贴到其中,但这一切都不起作用。
我的项目.gradle包含:
buildscript {
ext.kotlin_version = "1.3.20"
ext.play_sevices_version="16.0.0"
repositories {
google()
mavenCentral()
jcenter()
maven {
url "https://maven.fabric.io/public"
}
}
dependencies {
classpath "com.android.tools.build:gradle:3.3.0"
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
classpath "com.google.gms:google-services:4.2.0"
classpath "io.fabric.tools:gradle:1.25.4"
}
}
我的应用程序 .gradle 包含:
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
apply plugin: "kotlin-kapt"
apply plugin: "com.google.gms.google-services"
apply plugin: "io.fabric"
android {
compileSdkVersion 28
defaultConfig {
....
minSdkVersion 16
targetSdkVersion 28
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.2-alpha01'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.github.StephenVinouze:KinApp:1.0.2'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-ads:17.1.3'
implementation "com.google.android.gms:play-services-maps:$play_sevices_version"
implementation "com.google.android.gms:play-services-location:$play_sevices_version"
implementation "com.google.android.gms:play-services-places:$play_sevices_version"
implementation 'com.google.android.gms:play-services-analytics:16.0.7'
implementation 'com.taskail:simple-places-search-dialog:1.0'
implementation 'com.github.duanhong169:colorpicker:1.1.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'androidx.room:room-runtime:2.1.0-alpha04'
kapt "androidx.room:room-compiler:2.1.0-alpha04"
implementation 'androidx.paging:paging-runtime:2.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.1'
}
编辑: 当我更新我的项目依赖项时,Android Studio 并将其迁移为使用“androidx”,布局文件中声明的一些 id 被删除(我不知道为什么,但我认为当我的操作也尝试执行 clean 时可能会发生这种情况)项目删除了不必要的 ids 声明),约束布局中使用的 ids 未删除。
最佳答案
请尝试如下
- 文件|使缓存无效/重新启动
- 删除 .idea 文件夹
- 运行 gradlew clean
- 重新导入项目
如果问题仍然存在,那么只需删除 apply plugin: 'kotlin-android-extensions' ,同步 gradle 插件,然后再次添加它。
关于android - Gradle 3.3.0 和 Android Studio 3.3.0 上的 Kotlin Android 扩展未解析 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54507862/