【问题标题】:java.lang.NoClassDefFoundError: com.google.common.base.CharMatcherjava.lang.NoClassDefFoundError: com.google.common.base.CharMatcher
【发布时间】:2020-09-22 18:41:26
【问题描述】:

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

Process: 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'
    // 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'

还有我完整的 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 支持,但是,同样的问题再次发生,我该如何解决?

【问题讨论】:

  • 是的,我愿意。我更新了我的 gradle 版本并在 build.gradles 中定义了使用的路径。我建议(build.gradle 和 proprietiers 文件中的版本不同)去 File>Settings>Build, Execution and Deployment,并配置 Gradle 版本发现,在项目结构中版本不同也可能导致问题。
  • 感谢回复 :) 你的 gradle 版本和 gradle 插件版本是多少?
  • 当前是' classpath 'com.android.tools.build:gradle:4.0.2' '
  • 检查'gradle-wrapper.properties' gradle 版本是否是最新的(你可以在发行说明上查看最新版本)

标签: java android gradle android-gradle-plugin build.gradle


【解决方案1】:

添加 implementation 'com.google.guava:guava:30.0-android' 而不是 gradle 文件中的这一行 implementation('com.google.guava:guava:29.0-jre')

似乎只添加 android 依赖项。

【讨论】:

  • 妈的,intellij在自动版本更新上把android版本换成了jre版本
【解决方案2】:

如果你替换

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

为此

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

}

它应该工作。 (你可以使用这个番石榴版本,或者任何更高版本)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多