kriloleg
kriloleg

Reputation: 59

How to fix issues with NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string on Android

Recently, I faced an issue that I'm not able to solve for a week, reading different sources with advices. But, nothing helped.

So, the issues is in NoClassDefFoundError that appeared after upgrading:

  1. Gradle Wrapper from 5.x to 6.x
  2. Gradle Build Tool
  3. Firebase dependencies (which are actually brings these classes I have problems with)

What I have already tried to fix an issue:

  1. Tried to downgrade Firbase libraries (I have only core, ads and analytic)
  2. Tried to disable transitive basemenet dependency
  3. Tried to apply BOM to sync dependencies
  4. Tried to upgrade/downgrade android build plugin
  5. Tried to find issue with existing green-dao version, but it looks good

Here are dependencies from my build.gradle file:


dependencies {

    implementation "com.jakewharton.timber:timber:$timberVersion"

    //Reactive
    implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: rxJavaVersion
    implementation group: 'io.reactivex.rxjava2', name: 'rxandroid', version: androidRxJavaVersion

    // Firebase dependencies
    implementation platform("com.google.firebase:firebase-bom:$androidFirebaseBomVersion")

    implementation 'com.google.firebase:firebase-core'
    implementation 'com.google.firebase:firebase-ads'
    implementation 'com.google.firebase:firebase-crashlytics'

    // Android lifecycle
    implementation "androidx.lifecycle:lifecycle-runtime:$androidLifeCycleVersion"
    implementation "androidx.lifecycle:lifecycle-extensions:$androidLifeCycleVersion"
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    annotationProcessor "androidx.lifecycle:lifecycle-compiler:$androidLifeCycleVersion"

    // Android support
    //TODO once can be replaced with com.google.android.material
    implementation "com.google.android.material:material:$androidMaterialVersion"
    implementation 'androidx.browser:browser:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.appcompat:appcompat:$androidAppCompatVersion"
    implementation "androidx.constraintlayout:constraintlayout:$androidSupportConstraintLayoutVersion"

    implementation 'androidx.multidex:multidex:2.0.1'

    implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"

    // Dependency injection (Dagger)
    implementation "com.google.dagger:dagger:$daggerVersion"
    implementation "com.google.dagger:dagger-android:$daggerVersion"
    annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

    // Database
    implementation "org.sqldroid:sqldroid:$sqlDroidVersion"
    implementation "org.flywaydb:flyway-core:$flywayVersion"

    // UI
    implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion"
    implementation "com.github.hotchemi:android-rate:$androidRateVersion"
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation "com.nex3z:flow-layout:$flowLayoutVersion"

    // Utils
    implementation "com.annimon:stream:$streamVersion"
    implementation "com.google.code.findbugs:jsr305:$findBugsVersion"
    implementation "net.objecthunter:exp4j:$exp4jVersion"

    // Checkout
    implementation "org.solovyev.android:checkout:$checkoutVersion"

    /**
     * Test dependencies
     */
    // Unit tests
    testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: hamcrestAllVersion
    testImplementation("junit:junit:$junitVersion") {
        exclude group: 'org.hamcrest', module: 'hamcrest-core'
    }
    testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
    testImplementation('androidx.arch.core:core-testing:2.1.0') {
        exclude group: "com.android.support", module: "support-annotations"
    }
    testImplementation 'net.sf.kxml:kxml2:2.3.0'

    // Integration tests
    androidTestImplementation "junit:junit:$junitVersion"

    // Espresso dependencies
    androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
    androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
    androidTestImplementation "com.google.code.findbugs:jsr305:$jsr305Version"

    androidTestImplementation "androidx.test:runner:$testRunnerVersion"
    androidTestImplementation "androidx.test:rules:$testRunnerVersion"
    androidTestUtil "androidx.test:orchestrator:$testOrchestratorVersion"

    androidTestImplementation "commons-io:commons-io:$commonsIOVersion"
    androidTestImplementation group: 'com.google.guava', name: 'guava', version: guavaVersion

    // Spoon
    androidTestImplementation "com.squareup.spoon:spoon-client:$spoonClientVersion"
}

Here is the stacktrace:

09-15 11:07:13.467  1129  1129 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;                                                                                                                                                                                                            
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source)                                                                                                                                                                                                         
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.google.firebase.FirebaseOptions.fromResource(FirebaseOptions.java:156)                                        
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:244)                                                                                                                                                                                                                             
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)                                                                                                                                                                                                        
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)                                             
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)                                                                                                                                                                                                                           
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)                        
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.app.ActivityThread.installProvider(ActivityThread.java:6420)                                              
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)                                                                                                                                                                                                                    
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)                                                                                                                                                                                                                      
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.app.ActivityThread.-wrap3(ActivityThread.java)                                                                                                                                                                                                                                          
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)                                                                                                                                                                                                                            
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:102)                                                                                                                                                                                                                                            
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:154)                                                                                                                                                                                                                                                         
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:6776)                                                                                                                                                                                                                                       
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)                                                                                                                                                                                                                                                  
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)                                                                                                                                                                                                                
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)                                                                                                                                                                                                                                   
09-15 11:07:13.467  1129  1129 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.R$string" on path: DexPathList[[zip file "/data/app/com.myestimates.buildercalcfree-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myestimates.buildercalcfree-2/lib/arm, /system/lib, /vendor/lib]]  
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)                                            
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:380)                                                                                                                                                                                                                                           
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)                                                             
09-15 11:07:13.467  1129  1129 E AndroidRuntime:        ... 18 more

Maybe this is something common issue, but I have no idea how to deal with it.

Thanks

Upvotes: 1

Views: 3208

Answers (1)

kriloleg
kriloleg

Reputation: 59

So, after few days of digging around I have found a solution. So, to make it work I had to:

  1. Downgrade Android Gradle Plugin to 3.5.3 version
  2. Downgrade Gordon plugin to 1.0.6 version
  3. Migrated fabric-crashlytic to firebase-crashlytic. With adding plugin of the last as well, otherwise, errors occur.

All other updates could be set, but this 3 items have to be sticked to the versions mentioned.

Upvotes: 3

Related Questions