5

After updating my dependencies in the build.gradle (Module: app) in Gradle Scripts, all my layout, strings, all references that are defined by R are not available. I have the following code in the Module app:

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')
}

On searching the project, via the project explorer the project no longer seems to have an R file.

George
  • 2,865
  • 6
  • 35
  • 59
  • rebuild / reopen the project, maybe [clean caches](https://stackoverflow.com/questions/31884361/what-does-the-invalidate-caches-restart-do-in-android-studio) and look out for errors. `R` is generated during compilation. – zapl Oct 30 '18 at 08:24
  • @zapl that did not work – George Oct 30 '18 at 08:39
  • I get the following gradle error: Android dependency 'com.android.support:animated-vector-drawable' has different version for the compile (25.0.0) and runtime (28.0.0) classpath. You should manually set the same version via DependencyResolution – George Oct 30 '18 at 08:39
  • can't you fix the dependencies in the `data` project or wherever that dependency comes from? (to figure that out: https://stackoverflow.com/questions/39008887/how-do-i-show-dependencies-tree-in-android-studio) – zapl Oct 30 '18 at 08:43
  • Once i fix one dependency issue another one crops up. – George Oct 30 '18 at 09:11
  • Hey any luck on above? I am facing similar issue after migrating existing project to androidx namespace - Android dependency 'androidx.appcompat:appcompat' has different version for the compile (1.0.0) and runtime (1.1.0-alpha01) classpath. You should manually set the same version via DependencyResolution – Namrata Bagerwal Dec 11 '18 at 06:39
  • @NamrataBagerwal hope this is not late but the solution to your problem is to add the 1.1.0-alpha01 in your dependencies use either implementation or api "androidx.appcompat:appcompat: 1.10-alpha01" – George Jan 16 '19 at 13:25

1 Answers1

7

I encountered such problem after migrating to androidx. After some efforts, I found out that problem was about me using the latest Gradle plugin (as displayed below) while my Android Studio version was not the latest (it was 3.2).

com.android.tools.build:gradle:3.3.0

When I changed my gradle plugin to lower version (like below) everything went ok.

com.android.tools.build:gradle:3.2.1

Solution :

So the solution is to use the Gradle plugin (and Gradle wrapper) version which matches your Android Studio version.

Mostafa Arian Nejad
  • 1,278
  • 1
  • 19
  • 32