简体   繁体   English

Gson的NoClassDefFoundError仅不适用于棒棒糖

[英]NoClassDefFoundError on Gson not working on Lollipop only

So, everything with my app was working totally fine until one day I tried to perform a test using my Lollipop 5.1 phone and it crashed when using the Retrofit and OkHttp libraries. 因此,直到有一天我尝试使用Lollipop 5.1手机执行测试,并且使用RetrofitOkHttp库时,该应用程序崩溃,我的应用程序所有内容都可以正常工作。

UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/Gson;

The error log takes me to my Application class, to the initialization of the Gson object (the Gson class is totally there). 错误日志将我带到我的Application类,到Gson对象的初始化(Gson类完全存在)。

public static Gson getGson() { return gson; }

private void initGson() {
    gson = new Gson();
}

Many answers suggest me to use Multidex. 许多答案建议我使用Multidex。 I've already tried enabling multidex, and there's no difference: 我已经尝试过启用multidex,并且没有什么区别:

defaultConfig {
    applicationId yourApplicationId
    minSdkVersion 16
    targetSdkVersion 22
    multiDexEnabled true
    versionCode 74
    versionName '3.0.1'
}

And on the Application class, inside the onCreate method: 在Application类的onCreate方法中:

MultiDex.install(getAppContext());

The app crashes exclusively on Android 5.0 and 5.1, it works fine on Kitkat , Marshmallow and Nougat . 该应用程序仅在Android 5.0和5.1上崩溃,在KitkatMarshmallowNougat上运行良好。

EDIT I'll include the full build.gradle file: 编辑我将包括完整的build.gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'com.jakewharton.butterknife'


android {
signingConfigs {
    ------
}
compileSdkVersion 25
buildToolsVersion '25.0.2'
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
defaultConfig {
    applicationId yourApplicationId
    minSdkVersion 16
    targetSdkVersion 22
    multiDexEnabled true
    versionCode 74
    versionName '3.0.1'

}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
repositories {
    jcenter()
    mavenCentral()
    maven { url "https://jitpack.io" }

}
dataBinding {
    enabled = true
}

productFlavors {
    -----
}
}
dependencies {

//noinspection GradleCompatible

//noinspection UseOfBundledGooglePlayServices

//compile fileTree(dir: 'libs', include: ['*.jar'])

//compile files('libs/gson-2.2.4.jar')
compile files('libs/android-query.0.26.7.jar')
compile('com.code-troopers.betterpickers:library:2.5.4') {
    exclude group: 'com.nineoldandroids', module: 'library'
}
compile('com.github.sd6352051:NiftyNotification:1.2') {
    exclude group: 'com.nineoldandroids', module: 'library'
}
compile('com.hwangjr.rxbus:rxbus:1.0.3') {
    exclude group: 'com.hwangjr.utils', module: 'timber'
}
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:support-v13:25.3.1'
compile 'com.android.support:mediarouter-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.mixpanel.android:mixpanel-android:5.1.4'
compile 'com.google.android.gms:play-services:11.4.2'
compile 'com.github.traex.rippleeffect:library:1.3'
compile 'com.facebook.android:facebook-android-sdk:4.11.0'
compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
compile 'com.github.orangegangsters:swipy:1.2.2@aar'
compile 'com.daimajia.swipelayout:library:1.2.0@aar'
compile 'com.jakewharton:butterknife:8.6.0'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.google.code.gson:gson:2.8.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.jjobes:slideDateTimePicker:1.0.2'
compile 'com.github.paolorotolo:appintro:4.1.0'
compile 'com.github.ybq:Android-SpinKit:1.1.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.3.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'
compile 'me.zhanghai.android.materialprogressbar:library:1.4.1'
compile 'com.github.halysongoncalves:pugnotification:1.8.1'
compile 'biz.kasual:materialnumberpicker:1.2.1'
compile 'com.github.iwgang:simplifyspan:1.1'
compile 'uk.co.chrisjenx:calligraphy:2.3.0'
compile 'com.afollestad:sectioned-recyclerview:0.2.3'
compile 'com.marshalchen.ultimaterecyclerview:library:0.7.2'
compile 'me.relex:circleindicator:1.2.2@aar'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'io.conekta:conektasdk:2.1'
compile 'com.google.zxing:core:3.2.1'
compile 'net.hockeyapp.android:HockeySDK:4.0.0'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.basgeekball:awesome-validation:2.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.google.gms.google-services'

I solved this by importing only the Google services libraries that I needed instead of the whole package, so instead of doing this: 我通过仅导入所需的Google服务库而不是整个程序包来解决此问题,所以不要这样做:

compile 'com.google.android.gms:play-services:11.4.2'

I import each library separately. 我分别导入每个库。 Apparently it was loading too many libraries at the same time and it caused some weird issues to pop up. 显然,它同时加载了太多库,这导致一些奇怪的问题弹出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GSON“NoClassDefFoundError com/google/gson/Gson” - GSON “NoClassDefFoundError com/google/gson/Gson” gson JsonDeserializer导致NoClassDefFoundError - gson JsonDeserializer is causing NoClassDefFoundError 仅在Lollipop上:java.lang.NoClassDefFoundError:解析失败:Lcom / squareup / picasso / Picasso; - Only on Lollipop: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/picasso/Picasso; java.lang.NoClassDefFoundError:使用Amazon S3上传图片时Android上的Pre-Lollipop上的com.google.gson.stream.JsonReader错误 - java.lang.NoClassDefFoundError: com.google.gson.stream.JsonReader error on Pre-Lollipop in android while uploading image with Amazon S3 Spark / Java:GSON依赖项中的NoClassDefFoundError - Spark/Java: NoClassDefFoundError in GSON dependency Gson java.lang.NoClassDefFoundError - Gson java.lang.NoClassDefFoundError 改造在棒棒糖下不起作用 - Retrofit is not working below Lollipop java.lang.NoClassDefFoundError:解析失败:Lcom/google/gson/Gson; - java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/Gson; 获取java.lang.NoClassDefFoundError:com / google / gson / Gson - Getting java.lang.NoClassDefFoundError: com/google/gson/Gson java.lang.NoClassDefFoundError:com / google / gson / Gson - java.lang.NoClassDefFoundError: com/google/gson/Gson
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM