app-bundle-samples
app-bundle-samples copied to clipboard
Resource Not Found Relaunch Application on-Demand Dynamic Feature Module
When I download the on demand dynamic feature module it works fine as soon as I restart application I get the crash "Resource not found" . Heres the code that i copied from google dynamic features sample repo
private fun onSuccessfulLoad(moduleName: String, launch: Boolean) {
if (launch) {
when (moduleName) {
pagesfeatures -> launchActivity(mainActivity)
}
}
}
I have already overridden the code in BaseActivity and App class
open class BaseActivity: AppCompatActivity() {
override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase)
SplitCompat.install(this)
}
}
public class App extends Application {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
SplitCompat.install(base);
}
}
But its crashing when i revisit the application
The Exception thats occurring in my logs Crashlytics
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.qp.readquranoffline.holybookreading/com.mycode.pagesfeature.activities.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7e010000 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3621) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 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:2190) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:268) at android.app.ActivityThread.main(ActivityThread.java:8004) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:627) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
Caused by android.content.res.Resources$NotFoundException: Resource ID #0x7e010000 at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:248) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2400) at android.content.res.Resources.getAnimation(Resources.java:1277) at android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:138) at com.mycode.quranpagesfeature.activities.MainActivity.onCreate(MainActivity.kt:158) at android.app.Activity.performCreate(Activity.java:8058) at android.app.Activity.performCreate(Activity.java:8042) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1315) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3594) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3866) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 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:2190) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:268) at android.app.ActivityThread.main(ActivityThread.java:8004) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:627) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
The same problem happened to our app. But still no solution.
There are some clues:
- After call SplitCompat.install(context) at Application.attachBaseContext, the applicationContext.resource.asserts do have contain the dynamic module apk (on-demand)
- Then the WebView apk loaded, it refreshed the ResourcesImpl instance. At then, applicationContext.resource.asserts don't contain the dynamic module apk (on-demand)
- We guess that the installed dynamic module apk (on-demand) must be injected manually by calling SplitCompat.install every time the ResourcesImpl created, So after Step 2, the new ResoucesImpl instance don't contain the dynamic module apk (on-demand)
Don't know why Android team is no more interested in stability of such features... They always move to new stuff and leaving unresolved the old stuff
I have the same problem in my app, the resources of the third-party aar in the dynamic feature module cannot be found.
Our Solution: We monitor the property assert of resources(Application), and call SplitCompat.install() every time the assert changed in method getResources (Application)