2

we are trying to integrate react-native into our existing android application: The SDK requirements of our build.gradle are: minSdkVersion 16 targetSdkVersion 23

We use an Intent to call the initial React index.js:

Intent inte = new Intent(this, ReactNativeStarter.class);
startActivity(inte);

The rest of the code is from the react integrating tutorial.

When we try to call our react component we get the following error:

Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.<init>()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule' 
     (declaration of 'com.facebook.react.modules.netinfo.NetInfoModule' appears in /data/data/at.??????/files/instant-run/dex/slice-com.facebook.react-react-native-0.20.1_3762d580ab3ced1fa2f7503493d38e666994b9fa-classes.dex)
        at com.facebook.react.modules.netinfo.NetInfoModule.<init>(NetInfoModule.java:55)

Can you help?

Full error log:

12-19 10:07:22.157 30271-32680/at.???? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
    Process: at.?????, PID:
    java.lang.RuntimeException: An error occured while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:300)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
        at java.util.concurrent.FutureTask.run(FutureTask.java:242)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.<init>()' is inaccessible to class 'com.facebook.react.modules.netinfo.NetInfoModule' 
     (declaration of 'com.facebook.react.modules.netinfo.NetInfoModule' appears in /data/data/at.??????/files/instant-run/dex/slice-com.facebook.react-react-native-0.20.1_3762d580ab3ced1fa2f7503493d38e666994b9fa-classes.dex)
        at com.facebook.react.modules.netinfo.NetInfoModule.<init>(NetInfoModule.java:55)
        at com.facebook.react.shell.MainReactPackage.createNativeModules(MainReactPackage.java:67)
        at com.facebook.react.ReactInstanceManagerImpl.processPackage(ReactInstanceManagerImpl.java:793)
        at com.facebook.react.ReactInstanceManagerImpl.createReactContext(ReactInstanceManagerImpl.java:730)
        at com.facebook.react.ReactInstanceManagerImpl.access$600(ReactInstanceManagerImpl.java:91)
        at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:184)
        at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:169)
        at android.os.AsyncTask$2.call(AsyncTask.java:288)
        at java.util.concurrent.FutureTask.run(FutureTask.java:237)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
        at java.lang.Thread.run(Thread.java:818) 
2
  • Try to replace React-Native dependency with latest version compile "com.facebook.react:react-native:0.39" // From node_modules Commented Dec 23, 2016 at 12:05
  • did you solve this error? Commented Feb 23, 2017 at 12:40

2 Answers 2

0

I suspect this is caused by gradle picking up the wrong version of react-native because of a wrong path in maven allprojects config (at least it was for us) see PR here: https://github.com/facebook/react-native/pull/14743

Sign up to request clarification or add additional context in comments.

Comments

0

I was integrating an existing Android app (written on kotlin) with React Native.

The activity (.kt) I was writing to run the ReactRootView had the following onCreate() method:

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mReactRootView = ReactRootView(this)
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(application)
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index")
                .addPackage(MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState((LifecycleState.RESUMED))
                .build()

        // The string here (e.g. "MyReactNativeApp") has to match
        // the string in AppRegistry.registerComponent() in index.js
        mReactRootView!!.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null)
        setContentView(mReactRootView)

        if (Build.VERSION.SDK_INT >= M) {
            if (!canDrawOverlays(this)) {
                val intent = Intent(ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:$packageName"))
                startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE)
            }
        }
    }

The problem was exactly on the line

mReactRootView!!.startReactApplication(mReactInstanceManager, "MyReactNativeApp", null).

I had to change the "module" name from 'MyReactNativeApp' to 'App', which is the name of my main component registered on React.

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

Sooo... the right onCreate() function is

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mReactRootView = ReactRootView(this)
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(application)
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index")
                .addPackage(MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState((LifecycleState.RESUMED))
                .build()

        // The string here (e.g. "MyReactNativeApp") has to match
        // the string in AppRegistry.registerComponent() in index.js
        mReactRootView!!.startReactApplication(mReactInstanceManager, "App", null)
        setContentView(mReactRootView)

        if (Build.VERSION.SDK_INT >= M) {
            if (!canDrawOverlays(this)) {
                val intent = Intent(ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:$packageName"))
                startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE)
            }
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.