Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError com.facebook.react.bridge.WritableNativeMap

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.

like image 272
HimalayanCoder Avatar asked Oct 30 '22 06:10

HimalayanCoder


1 Answers

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

Update :

Seems like the real issue is related to loading the fbjni library using soloader. We finally fixed this problem by preloading the soloader library

import com.facebook.soloader.SoLoader;

@Override public void onCreate() {

...
...
SoLoader.init(getApplicationContext(), /* native exopackage */ false);
//SoLoader.loadLibrary("fbjni"); //uncomment this line if the issue is not resolved
}
like image 70
HimalayanCoder Avatar answered Nov 15 '22 06:11

HimalayanCoder