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 :8ball:
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) ```
I am also hitting this error when I try to run my app on android. The app crashes right after fetching the js bundle. Running on iOS has no problems.
Even checking out older versions of my app that are deployed and working in production still does not fix the issue, I simply cannot run android! Strangely, one of my co-workers has no problems running android. Also, if I react-native init a brand new project it also has no problems running on android. I'm completely mystified as to what could be going on.
I've included logcat output if that helps. It appears to be hitting the same error as described by @tuneZola :
02-27 23:08:42.546 1721 1747 E AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
02-27 23:08:42.546 1721 1747 E AndroidRuntime: Process: com.chillinmobile, PID: 1721
02-27 23:08:42.546 1721 1747 E AndroidRuntime: java.lang.RuntimeException: An error occurred while executing doInBackground()
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at android.os.AsyncTask$3.done(AsyncTask.java:309)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.lang.Thread.run(Thread.java:818)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: 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/com.chillinmobile-1/base.apk)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.modules.netinfo.NetInfoModule.<init>(NetInfoModule.java:55)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.shell.MainReactPackage.createNativeModules(MainReactPackage.java:67)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.ReactInstanceManagerImpl.processPackage(ReactInstanceManagerImpl.java:793)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.ReactInstanceManagerImpl.createReactContext(ReactInstanceManagerImpl.java:730)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.ReactInstanceManagerImpl.access$600(ReactInstanceManagerImpl.java:91)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:184)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:169)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at android.os.AsyncTask$2.call(AsyncTask.java:295)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-27 23:08:42.546 1721 1747 E AndroidRuntime: ... 4 more
I am also hitting this error
I found this issue only after I updated com.android.support:appcompat-v7 from 23.1.1 to 23.2.0 in app/build.gradle
@pdiaz Interesting! I had com.android.support:appcompat-v7:23.0.1 listed in my app/build.gradle dependencies. I tried updating that to 23.1.1 to see if that would help resolve my issue, but unfortunately I am still getting the crash caused by the IllegalAccessError
@pdiaz I noticed that also with the support version update, but I didn't want to have a specific build version dependency. Most people have something like this in there dependency list "com.android.support:support-v4:23.+". Also, this is an issue that will start to show up for more people once they upgrade or use RN for the first time. Changing to a specific build version is just a temporary solution.
I has same problem when i upgrade android support package to 23.2
+1 Tried with android support package v23.1 & v23.2
cc @bestander
The issue is that the ConnectivityManagerCompat constructor is now private in version 23.2
Oh snap, I'll look into that tomorrow
+1 same issue here
+1 same issue here
Has anyone been able to fix the issue by changing their version of the android support package? I cannot get around the issue no matter which version I use (23.0.1, 23.1, 23.2)
@Traviskn No, I was not able to fix it either by specifying those earlier version. I did a gradle clean, but it still seems to import the new version. I think its because I have other dependencies like the FB SDK that always imports the latest.
If you are using the react-native-dialogue module the material-dialogue dependency will not compile without support v23.2. (all their tags point to the latest commit).
to property downgrade your support version download this https://dl-ssl.google.com/android/repository/support_r23.0.1.zip and extract it into $ANDROID_HOME/extras/android/support
One temporary fix you can do is exclude the package from your other dependencies in your app/gradle.build. This is an example of ours.
dependencies {
// INCLUDE THE SUPPORT VERSION YOU WANT TO USE
compile "com.android.support:support-v4:23.0.1"
// EXCLUDE IT FROM THE REST
compile fileTree(dir: "libs", include: ["*.jar"])
compile ( project(':RNWebView') ) { exclude module: 'support-v4' }
compile ( project(':Orientation') ) { exclude module: 'support-v4' }
compile ( project(':react-native-google-analytics-bridge') ) { exclude module: 'support-v4' }
compile "com.facebook.react:react-native:0.18.+"
compile ( "com.facebook.android:facebook-android-sdk:4.+" ) {
exclude module: 'bolts-tasks'
exclude module: 'bolts-applinks'
exclude module: 'support-v4'
}
}
You should be able to go to your android folder and run
./gradlew app:dependencies
and all of the support packages should be listed as version 23.0.1. You might have to be a clean before that.
@Anthonyzou we don't instantiate ConnectivityManagerCompat, so constructor visibility should not make a difference. But anyway, I am debugging this
Looks like it is a breaking change in android support library. We don't have capacity to fix this right now, a Pull Request with a fix that would work both for 23.1 and 23.2 would be very much appreciated. Otherwise please post / vote on it at https://productpains.com/product/react-native. This way the most important issues for the community get surfaced.
@tuneZola Using a resolutionStrategy is a cleaner approach to force the version across all sub-projects.
subprojects {
configurations.all {
resolutionStrategy {
// https://github.com/facebook/react-native/issues/6152
force 'com.android.support:support-v4:23.0.1'
}
}
}