react-native: Android java.lang.IllegalAccessError Method void android.support.v4.net.ConnectivityManagerCompat

It appears that the NetInfo Module is trying to access ( com.facebook.react.modules.netinfo.NetInfoModule ) ConnectivityManagerCompat ( java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat ) method of android support lib v4 and that method is private? java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat. I am using RN .18, so I am not sure if this is not an issue in RN .20, but I wanted to post it just incase someone else is running across this issue. Stack Trace đŸŽ±

Also I do have the network permission in the manifest. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

02-25 10:51:50.355 23140-23174/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
                                                   Process: package.name, PID: 23140
                                                   java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                       at android.os.AsyncTask$3.done(AsyncTask.java:307)
                                                       at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                       at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                       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/app/package.name-2/base.apk)
                                                       at com.facebook.react.modules.netinfo.NetInfoModule.<init>(NetInfoModule.java:55)
                                                       at com.facebook.react.shell.MainReactPackage.createNativeModules(MainReactPackage.java:62)
                                                       at com.facebook.react.ReactInstanceManagerImpl.processPackage(ReactInstanceManagerImpl.java:751)
                                                       at com.facebook.react.ReactInstanceManagerImpl.createReactContext(ReactInstanceManagerImpl.java:688)
                                                       at com.facebook.react.ReactInstanceManagerImpl.access$600(ReactInstanceManagerImpl.java:84)
                                                       at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:177)
                                                       at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:162)
                                                       at android.os.AsyncTask$2.call(AsyncTask.java:295)
                                                       at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                       at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                       at java.lang.Thread.run(Thread.java:818) ```

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 96 (26 by maintainers)

Commits related to this issue

Most upvoted comments

com.android.support:appcompat-v7:23.2.1 change to com.android.support:appcompat-v7:23.0.1, fixed it

I’ve solved the problem changing In my project’s build.gradle file what follows maven { // All of React Native (JS, Android binaries) is installed from npm url “$rootDir/
/node_modules/react-native/android” } in maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url “/MyAbsolutePathToTheApplicationRoot/node_modules/react-native/android” }

Then you have to solve some compiling errors related to the OnPause, OnResume
that are changed in onHostPause, onHostResume and that’s it. A pain in the ass anyway!

I am getting the same issue. The only solution is in my Android application revert back the support library to the version the version 23.0.1? My app currently uses the 24.2.1 version of the support library, so reverting to 23.0.1 is not an easy/feasible solution.

I am trying to integrate React Native with my current application. I am following these instructions, but I am getting this error when I try to start the activity with the native code.

 Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
 java.lang.RuntimeException: An error occurred while executing doInBackground()
     at android.os.AsyncTask$3.done(AsyncTask.java:309)
     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
     at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
     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/app/*****.debug-2/base.apk)
     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:295)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
     at java.lang.Thread.run(Thread.java:818) 

Oh, My God!
The problem has been bothering me for a day. I tried all the waysI found my ‘Extra’ need to update!!! Repalce or update this file

image

 everything is ok and I still love react-native 

@jjding1986 you shouldn’t use the react native dependency hosted on Maven Central any more, as the version there won’t be updated any more. Instead, the aar (android lib) is now distributed directly with the react-native npm package, that’s what the node_modules/react-native/android/com/facebook/react/react-native/ folder is for. It contains a local maven repository, which always has the latest react native aar inside. (in your case 0.23.0) So try to change compile 'com.facebook.react:react-native:0.20.1' to compile 'com.facebook.react:react-native:0.23.0' Also, make sure that in your root gradle file (build.gradle inside your projects’ android folder) contains the following lines: https://github.com/facebook/react-native/blob/master/local-cli/generator-android/templates/src/build.gradle#L19-L22

thanks for your patience @astuetz. the latest version I can get from maven central is 0.20.1, so I used

compile 'com.facebook.react:react-native:0.20.1' 

in module(this module has one Activity that uses React Native) 's build.gradle, and my package.json looks like this

"dependencies": {
    "react": "^0.14.8",
    "react-native": "^0.23.0"
  }

and the folder in node_modules/react-native/android/com/facebook/react/react-native/ is 0.23.0.

I also defined

libSupportV4 = 'com.android.support:support-v4:23.2.1'
libRecyclerView = 'com.android.support:recyclerview-v7:23.2.1' 
libSupportAnnotation = 'com.android.support:support-annotations:23.2.1' 

in my project’s build.gradle and use them in other sub modules under the project, and I met this issue.

when I add

subprojects {
    configurations.all {
        resolutionStrategy {
            // https://github.com/facebook/react-native/issues/6152
            force 'com.android.support:support-v4:23.0.1'
        }
    }
}

into my project’s build.gradle, the issue gone. I also created a new simple project using React Native with

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.facebook.react:react-native:0.20.1'

in my app’s build.gradle, and react-native is the only 3rd-party dependency imported in it.

and

"dependencies": {
    "react": "^0.14.8",
    "react-native": "^0.22.2"
  }

in package.json, everything is ok.

I think my issue maybe caused by other 3rd-party libs which reference support-v4.

@sarajmunjal @jjding1986 you have to either use the com.facebook.react:react-native:+ dependency or manually change the dependency to the exact version of React Native you have defined in your package.json like com.facebook.react:react-native:0.22.2

Same here, one thing to help debug is specify the version in the build.gradle file when importing the React Native. Since the latest version are not in Maven central it will throw an error.

@sandyjoins02, stackoverflow would be a better place to get help about proper configuration.

@jjding1986 @chujj Both solutions are definitely not ideal. I just created a new project using React Native 0.22.2 and AppCompat 23.2.0, worked without any problems.

Make sure you’re really up-to-date with your React Native dependency, you can either just check the contents of the following folder: node_modules/react-native/android/com/facebook/react/react-native/ and see if the name of the folder in there matches the version of React Native you’re using (has to be >= 0.22.0-rc) or you just run rm -rf node_modules/ and npm install again

One more thing you could try is clearing your gradle caches. you can find the folder in your home directory: On Windows: %USER_HOME%.gradle/caches On Mac/Unix: $HOME/.gradle/caches/

thanks. btw the version is 0.22.0-rc4, I was able to use by copying it out from the android subdirectory into my local ~/.m2 maven repo