android – Proguard on multimodule app

前端之家收集整理的这篇文章主要介绍了android – Proguard on multimodule app前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个由以下模块组成的应用程序:

/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.viewmodel.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.
最佳答案
Proguard仅与实际版本相关.因此,不要为每个模块添加minifyEnabled true,而只是将其添加到应用程序本身的发布配置中.

来自库的所有代码(无论是来自模块还是外部依赖)都将使用应用程序的代码进行模糊处理.

如果您有要与库共享的自定义规则,则可以将consumerProguardFiles的“proguard-rules.pro”定义为添加到AAR文件中.

原文链接:https://www.f2er.com/android/430218.html

猜你在找的Android相关文章