Android Studio 3.6.1 with Gradle Plugin Version 3.6.1 and Gradle Version 5.6.4 not working
Asked Answered
B

8

4

My application is working very well. I have just updated Android Studio 3.6.1,

After updating Android Studio I got this dialog and I am going to update the version of the Gradle Plugin as below.

enter image description here

After updating, My application getting crashed and getting the following errors.

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;
        at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source:4)
        at com.google.firebase.FirebaseOptions.fromResource(com.google.firebase:firebase-common@@19.3.0:156)
        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@19.3.0:244)
        at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@19.3.0:51)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1940)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1915)
        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@19.3.0:45)
        at android.app.ActivityThread.installProvider(ActivityThread.java:6770)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6317)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6232)
        at android.app.ActivityThread.access$1200(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1792)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7078)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)

My Project Level build.gradle is:

buildscript {
    ext.objectboxVersion = '2.5.0'
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath 'com.google.gms:google-services:4.3.3'

        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.1"
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // Add dependency
        classpath 'io.fabric.tools:gradle:1.31.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and My App Level build.gradle is:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: "androidx.navigation.safeargs"

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.sohamerp.marsremedies"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    dataBinding {
        enabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    //implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.2.0-alpha05'

    implementation 'com.github.mukeshsolanki:android-otpview-pinview:2.1.0'

    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'

    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    annotationProcessor 'androidx.annotation:annotation:1.1.0'

    implementation "com.github.firdausmaulan:GlideSlider:1.5.1"

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

    implementation 'org.greenrobot:eventbus:3.1.1'

    debugImplementation "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseImplementation "io.objectbox:objectbox-android:$objectboxVersion"

    implementation 'com.intuit.sdp:sdp-android:1.0.6'
}
// apply the plugin after the dependencies block

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.objectbox'

There is only one solution which I have tried is reverting back the version of Gradle which I have updated but what if I want to use the latest versions.

Update:

One of my projects is working with some version of Android Studio and Gradle. Here is Firebase SDK is different in both project so I am thinking that Firebase is Project.

Any help? What should I do?

Buckeye answered 3/3, 2020 at 5:46 Comment(11)
i have same problem with 3.6.0 and 3.6.1Lassa
Have you tried Invalidate Caches / Restart ?Concatenate
Yes, I have tried Invalidate Caches/Restart, Clean Project, deleted .gradle once, Everything.Buckeye
remove old build from device or emulator and then try to run !! did you tried?Arabia
@a-r i have tried.Lassa
you just change the android Gradle plugin version is 3.1.4 and the Gradle version is 5.4 on the project structure optionsShoon
we dont want to downgrade. my another project work perfectly with android Gradle plugin 3.6.0Lassa
@AR I have tried but not working.Buckeye
This error is related to firebase sdk, I have searched a lot but didn't find any solution.Buckeye
@pratik-butani i have same firebase dependencies in another project and its work with no problem on android grade 3.6.0Lassa
look this #60546000Cower
P
2
buildToolsVersion "29.0.2"

remove this line from build.gradle

Potoroo answered 3/3, 2020 at 9:38 Comment(2)
kindly, can you explain that why do you think that this solution will fix it? I have a similar scenario, that my app is working fine on AS 3.5 and Gradle 3.5.3 but upon upgrading, Firebase seems not to get and parse data properly because I am getting Process: com.xx.xx.debug, PID: 14810 h.d.t.c: The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: github.com/ReactiveX/RxJava/wiki/Error-Handling | java.util.NoSuchElementException: List is empty. at h.d.v.b.a$t.a(:704) ...Alliterative
buildToolsVersion specify the SDK release version sometime it has some bugs and library issue so we need to figure out that in which version is compatible with our application. If you remove buildToolsVersion, So it will follow SDK version, not specific release. please check this image: prnt.sc/rbb9n5 Details: developer.android.com/studio/releases/build-toolsPotoroo
B
3

I have tried many ways to solve this problem as follow:

1st solution: I have tried the solution of Mayur Sojitra and it worked for one day. (Next day I got the same problem again.)

2nd solution: I have tried to revert back with a lower version of Gradle that is 3.5.0 and It's working but I wanted to use the latest version only. (Way to find a new solution)

3rd solution: I am using firebase dependencies and I thought that error is coming because of Firebase version conflicts with Gradle so I have updated all the firebase repository. (May this is also working for you)

4th solution: I have used ObjectBox library so updated that version to the latest 2.5.1.

5th solution: Finally I caught the problem that My Internet Connection is restricted (as per company rules) and My Gradle and other dependencies are not downloading successfully so I thought updating all dependencies and download it successfully will be the solution for this weird question.

Do let me know If you have any questions or still get a problem.

Thank you.

Buckeye answered 4/3, 2020 at 6:36 Comment(0)
P
2
buildToolsVersion "29.0.2"

remove this line from build.gradle

Potoroo answered 3/3, 2020 at 9:38 Comment(2)
kindly, can you explain that why do you think that this solution will fix it? I have a similar scenario, that my app is working fine on AS 3.5 and Gradle 3.5.3 but upon upgrading, Firebase seems not to get and parse data properly because I am getting Process: com.xx.xx.debug, PID: 14810 h.d.t.c: The exception was not handled due to missing onError handler in the subscribe() method call. Further reading: github.com/ReactiveX/RxJava/wiki/Error-Handling | java.util.NoSuchElementException: List is empty. at h.d.v.b.a$t.a(:704) ...Alliterative
buildToolsVersion specify the SDK release version sometime it has some bugs and library issue so we need to figure out that in which version is compatible with our application. If you remove buildToolsVersion, So it will follow SDK version, not specific release. please check this image: prnt.sc/rbb9n5 Details: developer.android.com/studio/releases/build-toolsPotoroo
S
1

It seems like you're mixing old fabric&crashlytics with new firebase&crashlytics. Try:

Project Level build.gradle:

buildscript {
    ext.objectboxVersion = '2.5.0'
    repositories {
        google()
        jcenter()
//        maven {
//            url 'https://maven.fabric.io/public'
//        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.1'
        classpath 'com.google.gms:google-services:4.3.3'

        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.1"
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // Add dependency
//        classpath 'io.fabric.tools:gradle:1.31.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App Level build.gradle:

apply plugin: 'com.android.application'
apply plugin: "androidx.navigation.safeargs"
//apply plugin: 'io.fabric'
apply plugin: 'com.google.firebase.crashlytics'

android {
    compileSdkVersion 29
//    buildToolsVersion "29.0.2"    // buildtools is now automatically determined, based on compileSDKVersion
    defaultConfig {
        applicationId "com.sohamerp.marsremedies"
        minSdkVersion 19
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    dataBinding {
        enabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    //implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.2.0-alpha05'

    implementation 'com.github.mukeshsolanki:android-otpview-pinview:2.1.0'

    implementation 'com.squareup.retrofit2:retrofit:2.7.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'

    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.firebase:firebase-core:17.2.2'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.1.0'
//    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.google.firebase:firebase-crashlytics:17.0.0'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    annotationProcessor 'androidx.annotation:annotation:1.1.0'

    implementation "com.github.firdausmaulan:GlideSlider:1.5.1"

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'

    implementation 'org.greenrobot:eventbus:3.1.1'

    debugImplementation "io.objectbox:objectbox-android-objectbrowser:$objectboxVersion"
    releaseImplementation "io.objectbox:objectbox-android:$objectboxVersion"

    implementation 'com.intuit.sdp:sdp-android:1.0.6'
}
// apply the plugin after the dependencies block

apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.objectbox'
Sphenogram answered 13/5, 2020 at 19:42 Comment(0)
M
0

If you're still looking at this, I just got an update to 3.6.2 and it specifically did some firebase-related update (although my code doesn't use firebase..) immediately after restart.

Minda answered 4/4, 2020 at 3:22 Comment(0)
F
0

I ran into the same error. However, I succeeded in building in the following way.

- classpath 'com.google.firebase:firebase-plugins:1.1.1'
+ classpath 'com.google.firebase:firebase-plugins:1.2.0'
Floruit answered 9/4, 2020 at 11:4 Comment(0)
C
0

Possible solution:

Upgrade the version of plugins in Top-level build.gradle.

Detail:

I upgraded the Gradle version from 5.4.1 to 5.6.4, and the plugin version from 3.5.3 to 3.6.2, and then I encountered a problem that the class could not find.

I have used Realm in the project and the top-level build.gradle is:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    /.../
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "io.realm:realm-gradle-plugin:5.8.0"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

This problem seems like some library/plugin does not process R classes in R.jar but in R.java after the Gradle plugin version greater than 3.6.0. See here for detail.

And the solution is to upgrade Realm to a newer version, for me is 6.0.2. See here for detail.

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "io.realm:realm-gradle-plugin:6.0.2" // <- modify
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
Cleora answered 16/4, 2020 at 8:57 Comment(0)
S
0

gradle 5.6.4 having some sync problem . go to the gradle-wrapper.properties and change the url to this

distributionUrl=https://services.gradle.org/distributions/gradle-6.0-all.zip

Skirr answered 24/4, 2020 at 18:27 Comment(0)
C
0

I tried many suggestions from stackoverflow(here), github forums etc. Checked gradle and gradle plugin versions if there is any compatibility problems. Only worked : I clean .idea and .gradle file, exit AndroidS, and I open my react native proj on Android studio and I did open from file choose android folder, after that waited android studio finish indexing(really waited this time) and press hammer icon for build and wait again patiently and build-run on simulator successfully.

I didn't wait before, I guess I didn't imagine that Android studio takes so much time to index-run-build

I am sharing if somebody still stuck, key was waiting for me, good luck

Champac answered 5/5, 2020 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.