【问题标题】:Unresolved id with Kotlin Android Extensions on Gradle 3.3.0 and Android Studio 3.3.0Gradle 3.3.0 和 Android Studio 3.3.0 上的 Kotlin Android 扩展无法解析 id
【发布时间】:2019-02-03 21:39:58
【问题描述】:

在我更新我的 Android Studio 并升级到 3.3.0 版本后,我无法编译我的应用程序。 Kotlin Android Extensions 提供的视图不起作用。对于我引用的所有视图,我都遇到了“未解决的参考: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 没有被删除。

【问题讨论】:

  • 您是否在 Android Studio 设置中更新了Kotlin plugin
  • 是的,我已经用 Android Studio 中的最后一个稳定版本更新了所有内容。
  • 被引用的 ID 是否仍然存在于您的 xml 布局文件中?
  • 一些 ID 从 xml 布局文件中消失了,因为我编辑了我的问题。具体原因我也不知道。

标签: android android-studio gradle kotlin kotlin-android-extensions


【解决方案1】:

请尝试如下

  • 文件 |使缓存无效/重新启动
  • 删除 .idea 文件夹
  • 运行 gradlew clean
  • 重新导入项目

如果问题仍然存在,那么只需删除 apply plugin: 'kotlin-android-extensions' ,同步 gradle 插件,然后我再次添加它。

【讨论】:

  • 只是添加到建议列表中,删除 .cache 文件夹可能对这种情况也有帮助。
猜你喜欢
  • 1970-01-01
  • 2019-06-18
  • 1970-01-01
  • 2019-01-18
  • 2019-06-10
  • 2015-12-19
  • 2013-06-10
  • 2015-04-14
  • 1970-01-01
相关资源
最近更新 更多