gpt4 book ai didi

android - Proguard 导致 Android 导航组件出现运行时异常

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:45:29 25 4
gpt4 key购买 nike

在将 NavigationComponent (android.arch.navigation:navigation-fragment-ktx:1.0.0-alpha01) 集成到我的带有目标的项目中并编译 sdk 后,我在使用混淆器时遇到了这个崩溃共 27 个

    2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mypackage.myapp.x, PID: 24573
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage.myapp.x/com.mypackage.myapp.MainActivity}: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: android.view.InflateException: Binary XML file line #16: Binary XML file line #16: Error inflating class fragment
Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
Caused by: java.lang.RuntimeException: Exception inflating com.mypackage.myapp.x:navigation/nav_graph line 7
at androidx.navigation.j.a(Unknown Source:124)
at androidx.navigation.d.a(Unknown Source:4)
at androidx.navigation.fragment.NavHostFragment.a(Unknown Source:88)
at android.support.v4.app.Fragment.l(Unknown Source:15)
at android.support.v4.app.m.a(Unknown Source:369)
at android.support.v4.app.m.b(Unknown Source:7)
at android.support.v4.app.m.a(Unknown Source:74)
at android.support.v4.app.m.onCreateView(Unknown Source:216)
at android.support.v4.app.j.a(Unknown Source:4)
at android.support.v4.app.h.a(Unknown Source:2)
at android.support.v4.app.d.onCreateView(Unknown Source:0)
at android.support.v4.app.h.onCreateView(Unknown Source:0)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at android.support.v7.app.AppCompatDelegateImplV9.b(Unknown Source:23)
at android.support.v7.app.d.setContentView(Unknown Source:4)
at com.mypackage.myapp.MainActivity.onCreate(Unknown Source:12)
at android.app.Activity.performCreate(Activity.java:7130)
at android.app.Activity.performCreate(Activity.java:7121)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1262)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6649)
at java.lang.reflect.Method.invoke(Native Method)
2018-05-16 12:13:14.044 24573-24573/com.mypackage.myapp.x E/AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: com.mypackage.myapp.fragments.MainFragment
at androidx.navigation.fragment.b$a.a(Unknown Source:58)
at androidx.navigation.fragment.b$a.a(Unknown Source:19)
at androidx.navigation.j.a(Unknown Source:16)
at androidx.navigation.j.a(Unknown Source:133)
at androidx.navigation.j.a(Unknown Source:31)
... 38 more
Caused by: java.lang.ClassNotFoundException: com.mypackage.myapp.fragments.MainFragment
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:453)
at androidx.navigation.fragment.b$a.a(Unknown Source:45)
... 42 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mypackage.myapp.fragments.MainFragment" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.mypackage.myapp.x-ysts055HQTtJTv5J2uej3g==/base.apk"],nativeLibraryDirectories=[/data/app/com.mypackage.myapp.x-ysts055HQTtJTv5J2uej3g==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
... 45 more

可能是因为 AAPT 还没有为导航组件生成保留规则?

最佳答案

我知道 Proguard 和 R8 应该保留库类的所有子类,但在这种情况下, fragment 类似乎丢失了。这个保留规则解决了我的问题,但从技术上讲,我们根本不需要这个规则!

-keep class * extends android.support.v4.app.Fragment{}

如果您使用的是 AndroidX,则使用此规则:-keep class * extends androidx.fragment.app.Fragment{}

如果您在导航 XML 中使用 argType,您还需要为引用的类制定规则,例如:-keep class com.example.model.MyModel。或者更好的是,按照 official documentation 的建议,将可打包和可序列化的类排除在重命名之外。 .
-keepnames 类 * 扩展 android.os.Parcelable
-keepnames 类 * 扩展 java.io.Serializable

关于android - Proguard 导致 Android 导航组件出现运行时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50378810/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com