英文:
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: '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?
答案1
得分: 7
添加以下代码:
implementation 'com.google.guava:guava:30.0-android'
替换掉你的 Gradle 文件中的这行代码:
implementation('com.google.guava:guava:29.0-jre')
只添加 Android 依赖似乎可以正常工作。
英文:
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.
答案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('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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论