I am randomly getting a crash when trying to load a jsbundle (offline react app)
mReactInstanceManager = ReactInstanceManager.builder().setApplication(mActivity.getApplication()) .setJSBundleFile(appPath) .addPackage(mReactPackage).addPackage(new MyCustomReactPackage()) .setUseDeveloperSupport(false)//For performance use false .setInitialLifecycleState(LifecycleState.RESUMED) .setNativeModuleCallExceptionHandler(new NativeModuleCallExceptionHandler() { @Override public void handleException(Exception e) { e.printStackTrace(); Logger.e(TAG,"Exception while opening app "+ Log.getStackTraceString(e)); } }) .build(); reactRootView.startReactApplication(mReactInstanceManager, launchClassName, initialProps);
Stacktrace:
LOCATION com.facebook.react.JSCConfig$1.a() EXCEPTION java.lang.NoClassDefFoundError MESSAGE com.facebook.react.bridge.WritableNativeMap at com.facebook.react.JSCConfig$1.a()(null:14) at com.facebook.react.ReactInstanceManager.k()(null:359) at com.facebook.react.ReactInstanceManager.j()(null:353) at com.facebook.react.ReactInstanceManager.c()(null:295) at com.facebook.react.ReactRootView.a()(null:221) at com.example.sdk.uidesign.fragments.AppFragment.b()(null:215) at com.example.sdk.uidesign.ActivityV2.a()(null:1265) at com.example.sdk.uidesign.adapter.AppsAdapter.a()(null:102) at com.example.sdk.uidesign.adapter.AppsAdapter.a()(null:37) at com.example.sdk.uidesign.a.e$a$1.onClick()(null:135) at android.view.View.performClick()(View.java:4790) at android.view.View$PerformClick.run()(View.java:19883) at android.os.Handler.handleCallback()(Handler.java:739) at android.os.Handler.dispatchMessage()(Handler.java:95) at android.os.Looper.loop()(Looper.java:135) at android.app.ActivityThread.main()(ActivityThread.java:5268) at java.lang.reflect.Method.invoke()(Method.java:-2) at java.lang.reflect.Method.invoke()(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()(ZygoteInit.java:902) at com.android.internal.os.ZygoteInit.main()(ZygoteInit.java:697)
Any help would be appreciated.
1 Answers
Answers 1
Android 5.1 has an arbitrary limit of 100 dex files
Here what we can see in runtime/dex_file.cc
bool DexFile::OpenFromZip(...) { ... while (i < 100) { std::string name = StringPrintf("classes%zu.dex", i) ... } ... }
So if you have more than 100 dex files you get this NoClassDefFoundError.
It is possible to avoid this error by disabling pre-dexing
One possible workaround is to disable preDexLibraries which reduces the number of classes.dex files included in an apk.
Add
android { dexOptions { preDexLibraries false } }
to the app's build.gradle file
java.lang.NoClassDefFoundError when running app with Android 5.1 with Android Studio 2.2RC
0 comments:
Post a Comment