我有一个由以下模块组成的应用程序:
/app
/common
/customviews
/model
现在我想混淆我的代码用于生产,所以我在所有模块的所有build.gradle
文件上添加以下行。
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
此文件包含以下规则:
-dontnote android.net.http.*
-dontnote org.apache.commons.codec.**
-dontnote org.apache.http.**
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn org.conscrypt.**
-dontwarn retrofit2.Platform$Java8
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
该应用程序编译正常,但运行时我得到以下异常:
b.g.b.a.ac: Incorrect resolution sequence for Java constructor public constructor a() defined in com.myexample.myapp.model.a.e.a[b@eb11a88] (b.g.b.a.a.d.a.f.a.j: class com.myexample.myapp.model.a.e.a)
at b.g.b.a.ai.a(Unknown Source)
at b.g.b.a.o.<init>(Unknown Source)
at b.g.b.a.l$a$e.b(Unknown Source)
at b.g.b.a.l$a$e.a(Unknown Source)
at b.g.b.a.ae$a.a(Unknown Source)
at b.g.b.a.ae$c.a(Unknown Source)
at b.g.b.a.l$a.e(Unknown Source)
at b.g.b.a.l.h(Unknown Source)
at b.g.a.c.a(Unknown Source)
at com.b.a.r.a(Unknown Source)
at com.b.a.v.a(Unknown Source)
at com.b.a.d$1.a(Unknown Source)
at com.b.a.d$1.a(Unknown Source)
at com.b.a.v.a(Unknown Source)
at e.b.a.a.a(Unknown Source)
at e.n.a(Unknown Source)
at e.n.b(Unknown Source)
at e.o$a.c(Unknown Source)
at e.o$a.a(Unknown Source)
at e.n.a(Unknown Source)
at e.n$1.invoke(Unknown Source)
at java.lang.reflect.Proxy.invoke(Proxy.java:813)
at $Proxy1.a(Unknown Source)
at com.myexample.myapp.model.b.a.d.a(Unknown Source)
at com.myexample.myapp.ui.splash.SplashViewModel.f(Unknown Source)
at com.myexample.myapp.ui.splash.SplashActivity.k(Unknown Source)
at com.myexample.myapp.ui.splash.SplashActivity.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
我顺便使用Kotlin。
编辑:新例外:
6-13 10:17:37.884 24129-24129/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.android, PID: 24129
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.android/com.myapp.android.ui.splash.SplashActivity}: java.lang.IllegalArgumentException: Unable to create converter for class com.myapp.android.model.api.userprofile.UserProfile
for method d.a
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: Unable to create converter for class com.myapp.android.model.api.userprofile.UserProfile
for method d.a
at retrofit2.n$a.a(ServiceMethod.java:755)
at retrofit2.n$a.c(ServiceMethod.java:741)
at retrofit2.n$a.a(ServiceMethod.java:172)
at retrofit2.m.a(Retrofit.java:170)
at retrofit2.m$1.invoke(Retrofit.java:147)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
at $Proxy1.a(Unknown Source)
at com.myapp.android.model.repository.impl.c.a(UserRepositoryImpl.kt:23)
at com.myapp.android.ui.splash.SplashViewModel.f(SplashViewModel.kt:20)
at com.myapp.android.ui.splash.SplashActivity.m(SplashActivity.kt:58)
at com.myapp.android.ui.splash.SplashActivity.onCreate(SplashActivity.kt:31)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
... 9 more
Caused by: java.lang.IllegalStateException: Resource not found in classpath: kotlin/collections/collections.kotlin_builtins
at kotlin.reflect.jvm.internal.impl.builtins.BuiltInsPackageFragmentProviderKt.a(builtInsPackageFragmentProvider.kt:39)
at kotlin.reflect.jvm.internal.impl.builtins.KotlinBuiltIns.c(KotlinBuiltIns.java:138)
at kotlin.reflect.jvm.internal.impl.platform.JvmBuiltIns.<init>(JvmBuiltIns.kt:56)
at kotlin.reflect.jvm.internal.impl.platform.JvmBuiltIns.<init>(JvmBuiltIns.kt:31)
at kotlin.reflect.jvm.internal.impl.load.kotlin.reflect.RuntimeModuleData$Companion.a(RuntimeModuleData.kt:47)
at kotlin.reflect.jvm.internal.ModuleByClassLoaderKt.a(moduleByClassLoader.kt:58)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl$Data$moduleData$2.b(KDeclarationContainerImpl.kt:37)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl$Data$moduleData$2.a(KDeclarationContainerImpl.kt:34)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.a(ReflectProperties.java:93)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.a(ReflectProperties.java:32)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl$Data.m(Unknown Source:7)
at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.b(KClassImpl.kt:42)
at kotlin.reflect.jvm.internal.KClassImpl$Data$descriptor$2.a(KClassImpl.kt:39)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.a(ReflectProperties.java:93)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.a(ReflectProperties.java:32)
at kotlin.reflect.jvm.internal.KClassImpl$Data.a(Unknown Source:7)
at kotlin.reflect.jvm.internal.KClassImpl.f(KClassImpl.kt:159)
at kotlin.reflect.jvm.internal.KClassImpl.b(KClassImpl.kt:173)
at kotlin.reflect.jvm.internal.KClassImpl$Data$constructors$2.b(KClassImpl.kt:86)
at kotlin.reflect.jvm.internal.KClassImpl$Data$constructors$2.a(KClassImpl.kt:39)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.a(ReflectProperties.java:93)
06-13 10:17:37.885 24129-24129/? E/AndroidRuntime: at kotlin.reflect.jvm.internal.ReflectProperties$Val.a(ReflectProperties.java:32)
at kotlin.reflect.jvm.internal.KClassImpl$Data.e(Unknown Source:7)
at kotlin.reflect.jvm.internal.KClassImpl.i(KClassImpl.kt:192)
at kotlin.reflect.full.KClasses.a(KClasses.kt:40)
at com.squareup.moshi.k.a(KotlinJsonAdapter.kt:160)
at com.squareup.moshi.n.a(Moshi.java:100)
at retrofit2.a.a.a.a(MoshiConverterFactory.java:91)
at retrofit2.m.a(Retrofit.java:330)
at retrofit2.m.b(Retrofit.java:313)
at retrofit2.n$a.c(ServiceMethod.java:739)
... 22 more
答案 0 :(得分:5)
Proguard 仅与实际版本相关。因此,不要为每个模块添加minifyEnabled true
,只需将其添加到应用程序本身的发布配置中。
来自库的所有代码(无论是来自模块还是外部依赖项)都将使用应用程序的代码进行模糊处理。
如果您要与图书馆共享自定义规则,则可以定义要添加到consumerProguardFiles 'proguard-rules.pro'
文件的AAR
。
答案 1 :(得分:0)
如果要将Proguard文件添加到库模块,则应在库的构建的defaultConfig块中将其添加到consumerProguardFiles
而不是proguardFiles
的正确属性中。 gradle文件。 E.g。
android {
defaultConfig {
minifyEnabled true
consumerProguardFiles 'proguard-rules.pro'
}
...
}
proguardFiles
适用于应用程序模块,而不适用于库模块。
答案 2 :(得分:0)
您获得的初始错误类似于KotlinReflectionInternalError when attempting to create an adapter for a data class中描述的错误,可以通过在ProGuard规则中添加以下内容来解决:
-keepclassmembers class kotlin.Metadata {
public <methods>;
}
对于第二个错误,请将此规则添加到ProGuard:
-keep class kotlin.reflect.jvm.internal.** { *; }