'java.lang.NoClassDefFoundError: com.google.common.base.CharMatcher

i'm trying run my app on Lollipop devices, after Lollipop the app run fine, but, in 5.0 or less version of Android my app crash and this error returned:

Process: com.myApp.agr1010, PID: 4353 java.lang.NoClassDefFoundError: com.google.common.base.CharMatcher

But, my Build.Gradle already include MultiDexEnable true

This my Build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"
    defaultConfig {
        applicationId "com.myApp.agr1010"
        minSdkVersion 21
        targetSdkVersion 29
        multiDexEnabled true
        versionCode 3
        versionName "0.8.9-Alpha Release"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation('com.google.guava:guava:29.0-jre')
    implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
    implementation 'com.google.android.gms:play-services-auth:18.1.0'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.3.0'
    implementation 'androidx.navigation:navigation-ui:2.3.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation 'androidx.work:work-runtime:2.4.0'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.0-rc01' // Material Design Google
    implementation 'androidx.core:core:1.3.1'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.android.support:multidex:1.0.3'
    // and a lot of implementation...
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.google.firebase.crashlytics'

And my complete logCat:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
    Process: com.myApp.agr1010, PID: 4353
    java.lang.NoClassDefFoundError: com.google.common.base.CharMatcher
        at com.google.common.base.Splitter.on(Splitter.java:127)
        at io.grpc.internal.GrpcUtil.<clinit>(GrpcUtil.java:197)
        at io.grpc.internal.AbstractManagedChannelImplBuilder.<clinit>(AbstractManagedChannelImplBuilder.java:90)
        at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:46)
        at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:26)
        at io.grpc.ManagedChannelBuilder.forTarget(ManagedChannelBuilder.java:76)
        at com.google.firebase.firestore.remote.GrpcCallProvider.initChannel(GrpcCallProvider.java:113)
        at com.google.firebase.firestore.remote.GrpcCallProvider.lambda$initChannelTask$6(GrpcCallProvider.java:256)
        at com.google.firebase.firestore.remote.GrpcCallProvider$$Lambda$5.call(GrpcCallProvider.java)
        at com.google.android.gms.tasks.zzz.run(com.google.android.gms:play-services-tasks@@17.0.2:2)
        at com.google.firebase.firestore.util.ThrottledForwardingExecutor.lambda$execute$0(ThrottledForwardingExecutor.java:54)
        at com.google.firebase.firestore.util.ThrottledForwardingExecutor$$Lambda$1.run(ThrottledForwardingExecutor.java)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)

I already tried add MultiDex to Androidx and android support, but, same problem happens again, how i can solve this?



Solution 1:[1]

Add implementation 'com.google.guava:guava:30.0-android' instead of this line from your gradle file implementation('com.google.guava:guava:29.0-jre')

Adding only android dependency seems to be working.

Solution 2:[2]

If you replace

implementation('com.google.guava:guava:29.0-jre')

for this

implementation ('com.google.guava:guava') {
    version {
        strictly '29.0-android'
    }
}

it should work. (You can use this guava version, or any later version)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2