使用 proguard 签名的 APK 给出了 IncompatibleClassChangeError

Sigend APK with proguard gives IncompatibleClassChangeError

我正在尝试 运行 使用 proguard 签署 apk,它给了我

IncompatibleClassChangeError 在 fasterxml 反序列化部分 运行 期间发生错误。

这是错误日志:

java.lang.IncompatibleClassChangeError: Couldn't find kotlin.Metadata.bv
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:659)
at libcore.reflect.AnnotationAccess.annotationSetToAnnotations(AnnotationAccess.java:633)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotations(AnnotationAccess.java:161)
at java.lang.Class.getDeclaredAnnotations(Class.java:743)
at com.fasterxml.jackson.databind.util.ClassUtil.findClassAnnotations(:1095)
at com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver.resolveClassAnnotations(:154)
at com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver.resolveFully(:118)
at com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver.resolve(:69)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector._resolveAnnotatedClass(:282)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.collectProperties(:192)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.forDeserialization(:112)
at com.fasterxml.jackson.databind.introspect.BasicClassIntrospector.forDeserialization(:16)
at com.fasterxml.jackson.databind.DeserializationConfig.introspect(:731)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(:324)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(:477)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(:4190)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(:4009)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(:3023)
at com.khcai.mifrooshe.deserializers.AppVersionHitoryModelDeserializer.a(:25)
at com.khcai.mifrooshe.networking.GetAppVersionHistoryClient.a(:39)
at com.khcai.mifrooshe.activity.HomeActivity$versionChangeLog.a(:277)
at com.khcai.mifrooshe.activity.HomeActivity$versionChangeLog.invoke(:62)
at org.jetbrains.anko.AsyncKt$doAsync.invoke(:140)
at org.jetbrains.anko.AsyncKt$doAsync.invoke()
at org.jetbrains.anko.AsyncKt$sam$Callable1a5578.call()
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access1(ScheduledThreadPoolExecutor.java:154)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

和我的 proguard 设置:

-ignorewarnings
-keep class * {
    public private *;
}

-keep class kotlin.reflect.** { *; }

-keepclassmembers class ** extends com.fasterxml.jackson.databind.ser.std.** {
   public <init>(...);
}

-keepclassmembers class ** extends com.fasterxml.jackson.databind.deser.std.** {
   public <init>(...);
}


-keep class com.squareup.okhttp.** { *; }
-keep class android.support.v7.widget.** { *; }
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
-keep class org.apache.http.** { *; }

-keepattributes *Annotation*,EnclosingMethod,Signature
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-keep class org.codehaus.** { *; }
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility {
    public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; }
-keep public class your.class.** {
    public void set*(***);
    public *** get*();
}

和 gradle 文件中的包列表:

  buildTypes {
        release {
            debuggable true
            minifyEnabled true
            shrinkResources true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation (name:'rangeseekbar-debug', ext:'aar')
    implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:support-core-utils:28.0.0'
    implementation "com.android.support:exifinterface:28.0.0"
    implementation 'com.android.support:support-core-ui:28.0.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:gridlayout-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "org.jetbrains.anko:anko:$anko_version"
    implementation 'com.squareup.okhttp3:okhttp:3.10.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.9.8'
    implementation 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.github.GrenderG:Toasty:1.2.5'
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
    implementation 'com.github.esafirm.android-image-picker:imagepicker:1.12.0'
    implementation 'org.apache.commons:commons-io:1.3.2'
    implementation 'com.github.hamsaadev:Persian-Date-Picker-Dialog:V1.2'
    implementation 'jp.wasabeef:blurry:2.1.1'
    implementation 'com.github.firdausmaulan:GlideSlider:1.3.1'
    implementation 'com.github.yalantis:ucrop:2.2.2'
    implementation('io.socket:socket.io-client:1.0.0') {
        exclude group: 'org.json', module: 'json'
    }
    implementation 'com.squareup.picasso:picasso:2.71828'
}

apply plugin: 'com.google.gms.google-services'

项目 运行 当我使用调试设置或通过设置这些

删除混淆器时很好

minifyEnabled,shrinkResources,useProguard到false.

甚至本指南也没有帮助:

update README.md to include proguard rule for kotlin.reflect

任何意见和建议将不胜感激。

如果您在三星 Android 5.x 设备上看到此内容,则这是以下内容的副本:

除了这个答案之外还有这个 issue filed on the jackson kotlin repo