kotlin开发sdk混淆配置踩坑记录

问题1:使用代理by lazy延迟初始化成员变量,混淆后报错问题:

java.lang.AbstractMethodError: abstract method "java.lang.Object kotlin.jvm.functions.Function0.invoke()"
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.ted.floo.connect.Session.getMSessionSet(Unknown Source:2)
        at com.ted.floo.connect.Session.addSessionListener(flooSDK:564)
        at com.ted.floo.service.ImUserService.<init>(flooSDK:59)
        at com.ted.floo.ImClient.<init>(flooSDK:25)
        at com.ted.floo.floodemo.MainActivity$client$2.invoke(MainActivity.kt:81)
        at com.ted.floo.floodemo.MainActivity$client$2.invoke(MainActivity.kt:28)
        at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74)
        at com.ted.floo.floodemo.MainActivity.getClient(Unknown Source:2)
        at com.ted.floo.floodemo.MainActivity$login$1.run(MainActivity.kt:172)
        at java.lang.Thread.run(Thread.java:923)

解决方法:

-keep @kotlin.Metadata class *
-keepclasseswithmembers @kotlin.Metadata class * { *; }#主要是这一行代码其作用

 问题2:混淆后OKHttp内部类无法调用:

java.lang.AbstractMethodError: abstract method "okhttp3.Response okhttp3.Interceptor.intercept(okhttp3.Interceptor$Chain)"
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:229)
        at okhttp3.RealCall$AsyncCall.execute(RealCall.java:172)
        at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:923)

解决方法:

//*RetrofitClient$是你自定义的调用了自定义拦截器的类
-keepclasseswithmembers @kotlin.Metadata class com.ted.floo.connect.http.*RetrofitClient$*{
      *;
}
-dontskipnonpubliclibraryclassmembers
-dontskipnonpubliclibraryclasses
-dontoptimize
-allowaccessmodification
-dontusemixedcaseclassnames
-ignorewarnings
-verbose

#保留行号
-renamesourcefileattribute flooSDK
-keepattributes SourceFile,LineNumberTable
-keepattributes Exceptions,InnerClasses,Signature,EnclosingMethod
#No prechecking
-dontpreverify

# 避免混淆注解
-keepattributes *Annotation*
# 避免混淆枚举的两个方法
-keepclassmembers enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
}

-keep class com.squareup.okhttp.** { *;}
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

-keep class org.json.* {*;}
-keep class androidx.** {*;}

#kotlin
-keep class org.jetbrains.** { *; }
-keep interface org.jetbrains.** { *; }
-dontwarn org.jetbrains.**
-dontwarn com.ted.floo.**
-keep class kotlin.** { *; }
-keep interface kotlin.** { *; }
-keepclassmembers class kotlin.Metadata {
    public <methods>;
}
-keepclasseswithmembers @kotlin.Metadata class * { *; }
-keepclassmembers class **.WhenMappings {
    <fields>;
}
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
    static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
}
-dontwarn kotlin.**

-keep class kotlinx.** { *; }
-keep interface kotlinx.** { *; }
-dontwarn kotlinx.**

-keep class retrofit2.** { *; }
-keep interface retrofit2.** { *; }
-dontwarn retrofit2.**

-keep class com.google.** { *; }
-keep interface com.google.** { *; }
-dontwarn com.google.**

-keep class com.google.protobuf.* {*;}
-dontwarn com.google.protobuf.**

 

 


版权声明:本文为u011149738原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。