替換系統(tǒng)默認加載器動態(tài)加載dex的startActivitySecondMethod()方法運行報錯
在真機系統(tǒng)版本為8.1.0上運行報錯
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kanxue.course01, PID: 18409
java.lang.RuntimeException: Unable to resume activity {com.kanxue.course01/com.kanxue.course01.MainActivity}: java.lang.ClassCastException: androidx.appcompat.widget.ActionBarOverlayLayout cannot be cast to androidx.appcompat.widget.ActionBarOverlayLayout
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3581)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)
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.ClassCastException: androidx.appcompat.widget.ActionBarOverlayLayout cannot be cast to androidx.appcompat.widget.ActionBarOverlayLayout
at androidx.appcompat.app.WindowDecorActionBar.init(WindowDecorActionBar.java:195)
at androidx.appcompat.app.WindowDecorActionBar.<init>(WindowDecorActionBar.java:173)
at androidx.appcompat.app.AppCompatDelegateImpl.initWindowDecorActionBar(AppCompatDelegateImpl.java:403)
at androidx.appcompat.app.AppCompatDelegateImpl.getSupportActionBar(AppCompatDelegateImpl.java:383)
at androidx.appcompat.app.AppCompatDelegateImpl.onPostResume(AppCompatDelegateImpl.java:535)
at androidx.appcompat.app.AppCompatActivity.onPostResume(AppCompatActivity.java:196)
at android.app.Activity.performResume(Activity.java:7131)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3556)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3621)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2862)
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)
I/Process: Sending signal. PID: 18409 SIG: 9
換到模擬器上執(zhí)行亦未成功,報錯:
E/System: Unable to load dex file: /sdcard/4.dex
E/System: java.io.IOException: No original dex files found for dex location /sdcard/4.dex
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:365)
at dalvik.system.DexFile.<init>(DexFile.java:107)
at dalvik.system.DexFile.<init>(DexFile.java:80)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:444)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:393)
at dalvik.system.DexPathList.<init>(DexPathList.java:164)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:84)
at dalvik.system.DexClassLoader.<init>(DexClassLoader.java:55)
at com.kanxue.course01.MainActivity.startActivitySecondMethod(MainActivity.java:103)
at com.kanxue.course01.MainActivity.onCreate(MainActivity.java:47)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
將dex文件放到/data/local/tmp/下報錯:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kanxue.course01, PID: 9949
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.kanxue.course01/com.kanxue.test02.TestActivity}: java.lang.ClassNotFoundException: Didn't find class "com.kanxue.test02.TestActivity" on path: DexPathList[[zip file "/data/app/com.kanxue.course01-xc42LnD49V-g2imqDjoV2Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.kanxue.course01-xc42LnD49V-g2imqDjoV2Q==/lib/x86, /data/app/com.kanxue.course01-xc42LnD49V-g2imqDjoV2Q==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.kanxue.test02.TestActivity" on path: DexPathList[[zip file "/data/app/com.kanxue.course01-xc42LnD49V-g2imqDjoV2Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.kanxue.course01-xc42LnD49V-g2imqDjoV2Q==/lib/x86, /data/app/com.kanxue.course01-xc42LnD49V-g2imqDjoV2Q==/base.apk!/lib/x86, /system/lib, /system/product/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:41)
at android.app.Instrumentation.newActivity(Instrumentation.java:1243)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3182)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
目前仍未解決