对此我感到迷茫……我有一个以前正在编译和运行的应用程序,现在找不到自己的自定义Application类。我在APK中查看了每个dex文件,却看不到它。我很少再更新应用程序代码了,所以这不像最近的代码/ gradle更改会导致这种情况。下面是logcat的堆栈跟踪:
07-13 23:35:47.273 19148 19148 E AndroidRuntime: FATAL EXCEPTION: main
07-13 23:35:47.273 19148 19148 E AndroidRuntime: Process: <app_package_name>, PID: 19148
07-13 23:35:47.273 19148 19148 E AndroidRuntime: java.lang.RuntimeException: Unable to instantiate application <app_package_name>.<MyCustomApplicationClass>: java.lang.ClassNotFoundException: Didn't find class "<app_package_name>.<MyCustomApplicationClass>" on path: DexPathList[[zip file "/data/app/<app_package_name>-...==/base.apk"],nativeLibraryDirectories=[/data/app/<app_package_name>-...==/lib/x86, /system/lib, /system/vendor/lib]]
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:948)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5759)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.ActivityThread.-wrap1(Unknown Source:0)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1659)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:105)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6535)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "<app_package_name>.<MyCustomApplicationClass>" on path: DexPathList[[zip file "/data/app/<app_package_name>-...==/base.apk"],nativeLibraryDirectories=[/data/app/<app_package_name>-...==/lib/x86, /system/lib, /system/vendor/lib]]
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.Instrumentation.newApplication(Instrumentation.java:1086)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: at android.app.LoadedApk.makeApplication(LoadedApk.java:942)
07-13 23:35:47.273 19148 19148 E AndroidRuntime: ... 9 more
07-13 23:35:47.297 1630 2640 W ActivityManager: Force finishing activity <app_package_name>/<core_module_package>.HomeActivity
07-13 23:35:47.481 1630 1715 W AppOps : Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0
07-13 23:35:47.794 1630 1657 W Looper : Dispatch took 373ms on android.ui, h=Handler (android.view.Choreographer$FrameHandler) {3a74f28} cb=android.view.Choreographer$FrameDisplayEventReceiver@94b1441 msg=0
07-13 23:35:47.803 1630 1656 W ActivityManager: Activity pause timeout for ActivityRecord{6da3ef1 u0 <app_package_name>/<core_module_package>.HomeActivity t18 f}
07-13 23:35:48.134 1630 1657 W Looper : Dispatch took 181ms on android.ui, h=Handler (com.android.server.am.ActivityManagerService$UiHandler) {43c2d01} cb=null msg=30
07-13 23:35:48.414 2544 19186 E ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
07-13 23:35:48.446 1630 1715 W WindowManager: Failed looking up window
07-13 23:35:48.446 1630 1715 W WindowManager: java.lang.IllegalArgumentException: Requested window android.view.ViewRootImpl$W@1173f3f does not exist
07-13 23:35:48.446 1630 1715 W WindowManager: at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:5609)
07-13 23:35:48.446 1630 1715 W WindowManager: at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:5602)
07-13 23:35:48.446 1630 1715 W WindowManager: at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:1644)
07-13 23:35:48.446 1630 1715 W WindowManager: at com.android.server.wm.Session.remove(Session.java:209)
07-13 23:35:48.446 1630 1715 W WindowManager: at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3488)
07-13 23:35:48.446 1630 1715 W WindowManager: at android.view.ViewRootImpl.doDie(ViewRootImpl.java:6306)
07-13 23:35:48.446 1630 1715 W WindowManager: at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3882)
07-13 23:35:48.446 1630 1715 W WindowManager: at android.os.Handler.dispatchMessage(Handler.java:105)
07-13 23:35:48.446 1630 1715 W WindowManager: at android.os.Looper.loop(Looper.java:164)
07-13 23:35:48.446 1630 1715 W WindowManager: at android.os.HandlerThread.run(HandlerThread.java:65)
07-13 23:35:48.446 1630 1715 W WindowManager: at com.android.server.ServiceThread.run(ServiceThread.java:46)
07-13 23:35:48.718 1630 1777 E TaskPersister: File error accessing recents directory (directory doesn't exist?).
07-13 23:35:53.485 2544 19186 E ActivityThread: Failed to find provider info for com.google.android.apps.gsa.testing.ui.audio.recorded
07-13 23:35:58.452 1630 1656 W ActivityManager: Activity destroy timeout for ActivityRecord{6da3ef1 u0 <app_package_name>/<core_module_package>.HomeActivity t18 f}
该应用被安排为几个gradle模块。大多数应用程序代码都有一个核心模块。然后是free
和pro
模块,用于自定义用户看到的功能。每个类都有自己的自定义Application
类,该类在核心模块中扩展了自定义Application
类。崩溃之后,我在Android Studio(目前为最新的3.5 Beta)中启动了APK分析器,在任何dex文件中都没有看到自定义Application
类的迹象。
我已经尝试在-keep
包中的所有内容中添加一些Proguard行。我也尝试过-dontobfuscate
。
是的,自定义Application
类在每个模块的AndroidManifest.xml中列出,并且拼写正确,依此类推。我已经尝试了具有相同结果的类的绝对路径和相对路径。我尝试禁用R8,但这也无济于事。
该应用的API级别设置为23至28,使用的是AndroidX等。
有什么主意我想念的是什么吗?
编辑:
以下是清单的相关内容:
这是“ pro”模块的AndroidManifest.xml的相关部分:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="<package>">
<application android:label="@string/app_name"
android:icon="@drawable/ic_launcher"
android:name=".<CustomName>Application"
tools:replace="android:name">
这是核心模块的AndroidManifest.xml的相关部分:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="<base_package>">
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name="<base_package>.<CustomBase>Application"
android:usesCleartextTraffic="true"
android:targetSandboxVersion="1">
核心模块中的自定义Application类扩展了MultiDexApplication
。