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

huangapple go评论73阅读模式
英文:

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

问题

我尝试在Lollipop设备上运行我的应用程序,在Lollipop之后,应用程序可以正常运行,但是在Android 5.0或更低版本上,我的应用程序会崩溃并返回以下错误:

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

但是,我的Build.Gradle已经包含了MultiDexEnable true

这是我的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'
    // 其他许多依赖...
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'com.google.firebase.crashlytics'

以及我的完整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)

我已经尝试将MultiDex添加到Androidx和Android Support中,但是问题仍然存在,我该如何解决这个问题?

英文:

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: &#39;com.android.application&#39;

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

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

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

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.&lt;clinit&gt;(GrpcUtil.java:197)
        at io.grpc.internal.AbstractManagedChannelImplBuilder.&lt;clinit&gt;(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?

答案1

得分: 7

添加以下代码:
implementation 'com.google.guava:guava:30.0-android'
替换掉你的 Gradle 文件中的这行代码:
implementation('com.google.guava:guava:29.0-jre')

只添加 Android 依赖似乎可以正常工作。

英文:

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

Adding only android dependency seems to be working.

答案2

得分: 1

如果你将

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

替换为

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

它应该可以工作。(你可以使用这个 guava 版本,或者任何更新的版本)

英文:

If you replace

implementation(&#39;com.google.guava:guava:29.0-jre&#39;)

for this

implementation (&#39;com.google.guava:guava&#39;) {
    version {
        strictly &#39;29.0-android&#39;
    }
}

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

huangapple
  • 本文由 发表于 2020年9月23日 02:41:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/64015869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定