【问题标题】:Unresolved Reference R after Androidx MigrationAndroidx 迁移后未解决的参考 R
【发布时间】:2018-10-30 08:13:21
【问题描述】:

在 Gradle 脚本的 build.gradle(模块:app)中更新我的依赖项后,我的所有布局、字符串、由 R 定义的所有引用都不可用。我在模块应用程序中有以下代码:

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex')) {
                details.useVersion "28.0.0"
            }

            if(details.requested.group == 'androidx.lifecycle'  && !details.requested.name.contains('multidex'))
            {
                details.useVersion "2.0.0"
            }

        }
    }
}

dependencies 
{


 implementation 'androidx.test:runner:1.1.0'
    implementation 'androidx.test.espresso:espresso-core:3.1.0'
        //    androidTestImplementation 'com.android.support.test:runner:1.0.2'
        //    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    // lifecycle components
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-viewmodel:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-core:2.0.0'
    kapt 'androidx.lifecycle:lifecycle-compiler:2.0.0'

    //    implementation 'android.arch.lifecycle:extensions:1.1.1'
    //    kapt "android.arch.lifecycle:compiler:1.1.1"

    // room components
        //    implementation 'android.arch.persistence.room:runtime:1.1.1'
    implementation 'androidx.room:room-runtime:2.0.0'

    //    data binding components
    annotationProcessor "com.android.databinding:compiler:3.1.4"
    implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

    //implementation 'com.google.dagger:dagger-android:2.16'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    // if you use the support libraries
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.15'
    compile project(path: ':data')
}

在通过项目浏览器搜索项目时,项目似乎不再有 R 文件。

【问题讨论】:

  • 重建/重新打开项目,可能是clean caches 并注意错误。 R 在编译过程中生成。
  • @zapl 不起作用
  • 我收到以下 gradle 错误:Android 依赖项 'com.android.support:animated-vector-drawable' 的编译 (25.0.0) 和运行时 (28.0.0) 类路径的版本不同。您应该通过 DependencyResolution 手动设置相同的版本
  • 您不能修复data 项目中的依赖关系或该依赖关系的来源吗? (要弄清楚:stackoverflow.com/questions/39008887/…
  • 一旦我修复了一个依赖问题,就会出现另一个问题。

标签: android kotlin android-gradle-plugin androidx


【解决方案1】:

我在迁移到 androidx 后遇到了这样的问题。经过一番努力,我发现问题在于我使用了最新的 Gradle 插件(如下所示),而我的 Android Studio 版本不是最新的(它是 3.2)。

com.android.tools.build:gradle:3.3.0

当我将我的 gradle 插件更改为较低版本(如下所示)时,一切正常。

com.android.tools.build:gradle:3.2.1

解决方案:

所以解决方案是使用与您的 Android Studio 版本相匹配的 Gradle 插件(和 Gradle 包装器)版本。

【讨论】:

  • @jeppla Gradle 插件版本在项目级build.gradle 文件中设置。
猜你喜欢
  • 1970-01-01
  • 2019-07-15
  • 2019-10-13
  • 2019-08-24
  • 2021-04-28
  • 1970-01-01
  • 2019-03-23
  • 2019-01-08
  • 1970-01-01
相关资源
最近更新 更多