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)
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 version23.0.1
? My app currently uses the24.2.1
version of the support library, so reverting to23.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.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
@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 changecompile 'com.facebook.react:react-native:0.20.1'
tocompile '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-L22thanks for your patience @astuetz. the latest version I can get from maven central is 0.20.1, so I used
in module(this module has one Activity that uses React Native) 's build.gradle, and my package.json looks like this
and the folder in node_modules/react-native/android/com/facebook/react/react-native/ is 0.23.0.
I also defined
in my projectâs build.gradle and use them in other sub modules under the project, and I met this issue.
when I add
into my projectâs build.gradle, the issue gone. I also created a new simple project using React Native with
in my appâs build.gradle, and react-native is the only 3rd-party dependency imported in it.
and
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 likecom.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 runrm -rf node_modules/
andnpm install
againOne 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 theandroid
subdirectory into my local~/.m2
maven repo