Mat*_*ias 10 android android-module android-app-bundle
我在发布到 Play 商店时在下载的功能模块中启动活动时遇到问题。它总是在下载的模块活动中的 setContentView() 上崩溃。
java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx/xxxActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7e080000
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7e080000
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:227)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2149)
at android.content.res.Resources.getLayout(Resources.java:1158)
at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
Run Code Online (Sandbox Code Playgroud)
真正奇怪的部分是,如果我发布应用程序的新版本(唯一的变化是 versionCode)来播放商店和更新应用程序,一切正常。
当我卸载应用程序并再次安装时,崩溃又回来了。
我的应用程序继承了 SplitCompatApplication() 并且只是为了确保我已经尝试添加:
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase)
SplitCompat.install(this)
}
Run Code Online (Sandbox Code Playgroud)
到功能模块中的活动并禁用 proguard 以确保在缩小期间没有删除任何内容
我的 SplitInstallStateUpdatedListener
private val listener = SplitInstallStateUpdatedListener { state ->
val multiInstall = state.moduleNames().size > 1
state.moduleNames().forEach { name ->
// Handle changes in state.
when (state.status()) {
SplitInstallSessionStatus.DOWNLOADING -> {
// In order to see this, the application has to be uploaded to the Play Store.
displayLoadingState(state, "Laddar ner $name")
}
SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> {
/*
This may occur when attempting to download a sufficiently large module.
In order to see this, the application has to be uploaded to the Play Store.
Then features can be requested until the confirmation path is triggered.
*/
startIntentSender(state.resolutionIntent()?.intentSender, null, 0, 0, 0)
}
SplitInstallSessionStatus.INSTALLED -> {
if(toInstall.isNotEmpty() && toInstall.contains(name)) {
toInstall.remove(name)
}
if(toInstall.isEmpty()) {
// Updates the app’s context with the code and resources of the
// installed module. (should only be for instant apps but tried it anyway, no change)
SplitInstallHelper.updateAppInfo(applicationContext)
Handler().post {
viewModel.goToOverview()
}
}
}
SplitInstallSessionStatus.INSTALLING -> displayLoadingState(state, "Installerar $name")
SplitInstallSessionStatus.FAILED -> {
toastAndLog("Error: ${state.errorCode()} for module ${state.moduleNames()}")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
此代码根据用户声明下载模块并在基本应用程序中启动活动
下载的模块活动然后从一个 BottomSheetDialogFragment 开始,如下所示:
xxx.setOnClickListener(view -> {
Intent intent = new Intent();
String packageName = Constants.MODULE_BASEPACKAGE + "." + Constants.MODULE_XXXXX;
intent.setClassName(getActivity().getPackageName(),packageName + ".XxxxxActivity" );
ParcelUuid parcelUuid = new ParcelUuid(UUID.randomUUID());
intent.putExtra("uuid", parcelUuid);
startActivity(intent);
dismiss();
});
Run Code Online (Sandbox Code Playgroud)
我完全不知道下一步要尝试什么。似乎在安装更新之前不会更新资源列表并且重新启动应用程序是不够的,或者我只是缺少一些简单的东西?
您始终可以从动态模块内的主项目访问资源,因此您可以将动态模块的资源放在主应用程序中,然后使用主应用程序中的 R.java。
但是,打开这些资源的正确方法是在动态交付的活动中使用 SplitCompat.install(this)
这似乎是 com.android.tools.build:gradle:3.2.1 中的一个错误,当我升级到 3.3.0 时,问题自行解决。
希望它可以帮助其他遇到这个问题的人......
| 归档时间: |
|
| 查看次数: |
3115 次 |
| 最近记录: |