无法从基础应用启动动态模块 activity 并且应用崩溃
Unable to start dynamic module launching activity from the base app and app crashes
我正在为我的 android 应用程序使用应用程序包 - 动态功能模块。我遵循了文档并实施了所有必需的步骤,
(1) Used PlayCore Library - version 1.3.7
(2) Used the SplitCompat Library in my Application class (attachBaseContext)
(3) Used the SplitCompat.install(context) in attachBaseContext() of the new modules launching actvity
(4) Implemented and initiated the SplitInstallManager instance and handled the error codes and status updates.
(5) Double checked the build.gradle and manifest files and everything looks perfect.
我从 android studio 启动了应用程序,将部署选项设置为 "Apk from app bundle"
但是当我点击按钮安装模块时,应用程序崩溃了。
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.something.myapp/com.something.myapp.sample_module.activity.SampleActivity}: java.lang.ClassNotFoundException: Didn't find class "com.something.myapp.sample_module.activity.SampleActivity" on path: DexPathList[[zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/base.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.arm64_v8a.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.en.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.si.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/lib/arm64, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/base.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.en.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.si.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.xxhdpi.apk!/lib/arm64-v8a, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2881)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
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:858)
它说无法实例化activity。此应用程序使用了 MultiDex 功能,但我认为它不会影响应用程序包 - 动态模块。
当我调试应用程序时,它进入 SplitInstallSessionStatus.INSTALLED 状态,然后启动下载模块的 activity。然后就崩溃了。
更新:
这是动态模块中的 AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.something.myapp.sample_module">
<dist:module
dist:instant="false"
dist:onDemand="true"
dist:title="@string/module_sample">
<dist:fusing dist:include="true" />
</dist:module>
<application android:allowBackup="true">
<activity android:name="com.something.myapp.sample_module.activity.SampleActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
这是 SplitInstallService 的另一个日志:
SplitInstallService : startInstall([sample_module],[])
SplitInstallService : Initiate binding to the service.
com.google.android.finsky.splitinstallservice.du.a(10): Connecting InstallListener to SplitInstallService broadcaster...
SplitInstallService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.splitinstallservice.SplitInstallService})
SplitInstallService : linkToDeath
SplitInstallService : Unbind from service.
SplitInstallService : onStartInstall(0)
那么如何解决这个问题呢?
任何建议表示赞赏。
谢谢
它对我来说从未在 Android Studio 中起作用。尽管我在 运行 配置 中使用了 App Bundle 中的 APK。我也尝试使用 bundletool。当我同时使用这两个选项时,我遇到了同样的崩溃。我认为,由于 App Bundle 处于测试阶段,测试工具仍然存在问题。
但它适用于游戏控制台 - 内部测试轨道。因此,我认为目前测试应用程序包的最佳方法是使用游戏控制台中的内部测试轨道而不是 android 工作室。
通常我会先使用 默认 APK 测试应用程序,检查是否存在 运行 时间问题,如果没有问题,然后将 aab 上传到控制台 -内部测试轨道。
完全相同的事情发生在我身上即使上传到内部测试轨道。
具体来说,会话状态始终是 SplitInstallSessionStatus.INSTALLED
,即使该模块并未真正安装。
在我的例子中,导致问题的原因是 build.gradle
上声明的模块名称与下载模块时在运行时传递的模块名称不匹配。例如:
build.gradle
android {
// ...
dynamicFeatures = [ 'myfeature' ]
}
下载时
val request = SplitInstallRequest.newBuilder()
.addModule("my-feature") // <- THE PROBLEM. Should be "myfeature"
.build()
所以,我犯了一个愚蠢的错误。但是,我不确定为什么这没有触发错误而不是说模块已安装。可能是游戏核心的错误...
我正在为我的 android 应用程序使用应用程序包 - 动态功能模块。我遵循了文档并实施了所有必需的步骤,
(1) Used PlayCore Library - version 1.3.7
(2) Used the SplitCompat Library in my Application class (attachBaseContext)
(3) Used the SplitCompat.install(context) in attachBaseContext() of the new modules launching actvity
(4) Implemented and initiated the SplitInstallManager instance and handled the error codes and status updates.
(5) Double checked the build.gradle and manifest files and everything looks perfect.
我从 android studio 启动了应用程序,将部署选项设置为 "Apk from app bundle"
但是当我点击按钮安装模块时,应用程序崩溃了。
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.something.myapp/com.something.myapp.sample_module.activity.SampleActivity}: java.lang.ClassNotFoundException: Didn't find class "com.something.myapp.sample_module.activity.SampleActivity" on path: DexPathList[[zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/base.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.arm64_v8a.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.en.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.si.apk", zip file "/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.xxhdpi.apk"],nativeLibraryDirectories=[/data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/lib/arm64, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/base.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.arm64_v8a.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.en.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.si.apk!/lib/arm64-v8a, /data/app/com.something.myapp-OYWwJYvG4hSEq9ul1Y6rHA==/split_config.xxhdpi.apk!/lib/arm64-v8a, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2881)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
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:858)
它说无法实例化activity。此应用程序使用了 MultiDex 功能,但我认为它不会影响应用程序包 - 动态模块。
当我调试应用程序时,它进入 SplitInstallSessionStatus.INSTALLED 状态,然后启动下载模块的 activity。然后就崩溃了。
更新: 这是动态模块中的 AndroidManifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.something.myapp.sample_module">
<dist:module
dist:instant="false"
dist:onDemand="true"
dist:title="@string/module_sample">
<dist:fusing dist:include="true" />
</dist:module>
<application android:allowBackup="true">
<activity android:name="com.something.myapp.sample_module.activity.SampleActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
</application>
</manifest>
这是 SplitInstallService 的另一个日志:
SplitInstallService : startInstall([sample_module],[])
SplitInstallService : Initiate binding to the service.
com.google.android.finsky.splitinstallservice.du.a(10): Connecting InstallListener to SplitInstallService broadcaster...
SplitInstallService : ServiceConnectionImpl.onServiceConnected(ComponentInfo{com.android.vending/com.google.android.finsky.splitinstallservice.SplitInstallService})
SplitInstallService : linkToDeath
SplitInstallService : Unbind from service.
SplitInstallService : onStartInstall(0)
那么如何解决这个问题呢? 任何建议表示赞赏。
谢谢
它对我来说从未在 Android Studio 中起作用。尽管我在 运行 配置 中使用了 App Bundle 中的 APK。我也尝试使用 bundletool。当我同时使用这两个选项时,我遇到了同样的崩溃。我认为,由于 App Bundle 处于测试阶段,测试工具仍然存在问题。
但它适用于游戏控制台 - 内部测试轨道。因此,我认为目前测试应用程序包的最佳方法是使用游戏控制台中的内部测试轨道而不是 android 工作室。
通常我会先使用 默认 APK 测试应用程序,检查是否存在 运行 时间问题,如果没有问题,然后将 aab 上传到控制台 -内部测试轨道。
完全相同的事情发生在我身上即使上传到内部测试轨道。
具体来说,会话状态始终是 SplitInstallSessionStatus.INSTALLED
,即使该模块并未真正安装。
在我的例子中,导致问题的原因是 build.gradle
上声明的模块名称与下载模块时在运行时传递的模块名称不匹配。例如:
build.gradle
android {
// ...
dynamicFeatures = [ 'myfeature' ]
}
下载时
val request = SplitInstallRequest.newBuilder()
.addModule("my-feature") // <- THE PROBLEM. Should be "myfeature"
.build()
所以,我犯了一个愚蠢的错误。但是,我不确定为什么这没有触发错误而不是说模块已安装。可能是游戏核心的错误...