Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android java.lang.IllegalAccessError Method void android.support.v4.net.ConnectivityManagerCompat #6152

Closed
tuneZola opened this issue Feb 25, 2016 · 96 comments
Labels
Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot.

Comments

@tuneZola
Copy link

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) ```
@Traviskn
Copy link

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

@ronanhardiman
Copy link

I am also hitting this error

@pdiaz
Copy link

pdiaz commented Feb 29, 2016

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

@Traviskn
Copy link

@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

@tuneZola
Copy link
Author

@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.

@jinzhaoyu
Copy link

I has same problem when i upgrade android support package to 23.2

@gabygandrade
Copy link

+1 Tried with android support package v23.1 & v23.2

@satya164
Copy link
Contributor

satya164 commented Mar 2, 2016

cc @bestander

@Anthonyzou
Copy link

The issue is that the ConnectivityManagerCompat constructor is now private in version 23.2

@bestander
Copy link
Contributor

Oh snap, I'll look into that tomorrow

@ceichinger
Copy link

+1 same issue here

1 similar comment
@cedoucette
Copy link

+1 same issue here

@Traviskn
Copy link

Traviskn commented Mar 3, 2016

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)

@tuneZola
Copy link
Author

tuneZola commented Mar 3, 2016

@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.

@Anthonyzou
Copy link

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).

@Anthonyzou
Copy link

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

@tuneZola
Copy link
Author

tuneZola commented Mar 3, 2016

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.

@bestander
Copy link
Contributor

@Anthonyzou we don't instantiate ConnectivityManagerCompat, so constructor visibility should not make a difference.
But anyway, I am debugging this

@bestander
Copy link
Contributor

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.

@ben-manes
Copy link
Contributor

@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'
    }
  }
}

@ghost
Copy link

ghost commented Mar 7, 2016

Should be fixed with 3640080

@satya164
Copy link
Contributor

satya164 commented Mar 7, 2016

Closing based on @astuetz's comment. Let's reopen of its still not working

@Traviskn
Copy link

Traviskn commented Mar 8, 2016

@astuetz @satya164 This is great news! Do you know what version of react native that fix will be available in?

@ghost
Copy link

ghost commented Mar 10, 2016

@Traviskn It's fixed in 0.22.0-rc already :)

@ghost
Copy link

ghost commented Mar 10, 2016

@knowbody I think the fix for this Android-specific bug should be included in the 0.22.0-rc release notes as well. (Although the commit message doesn't really sound like a major bugfix)

@knowbody
Copy link
Contributor

@astuetz done

@LiamInJapan
Copy link
Contributor

LiamInJapan commented Nov 16, 2016

This gives me a lot of compilation errors:

Error:(11, 26) error: cannot find symbol class LifecycleState
Error:(33, 34) error: cannot find symbol method onPause()
Error:(42, 34) error: cannot find symbol method onResume(ReactActivity,ReactActivity)
Error:(51, 34) error: cannot find symbol method onDestroy()
Error:(95, 43) error: cannot find symbol variable LifecycleState
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

Trying:

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

followed by

rm -rf node_modules/ && npm install

Then a project refresh, then a build. I get the same errors.

Essentially, the process lined out in this doc is broken I believe... Unless maybe I need to update react version number too? (Which comes back to what I was saying earlier about a table of compatible version numbers)

@ishan-dhingra
Copy link

@LiamInJapan New package name for LifecycleState class: com.facebook.react.common.LifecycleState

@LiamInJapan
Copy link
Contributor

Thanks @ishan-dhingra

I still have these:

Error:(33, 34) error: cannot find symbol method onPause()
Error:(42, 34) error: cannot find symbol method onResume(ReactActivity,ReactActivity)
Error:(51, 34) error: cannot find symbol method onDestroy()
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.

@ishan-dhingra
Copy link

@LiamInJapan This seems to be a Compile time Java error, check if you are extending class and overriding function properly.

@LiamInJapan
Copy link
Contributor

Ok, I'll check (although this is what is in the documents... Actually come
to think of it I think I know what it is)

On Wed, Nov 16, 2016 at 6:26 PM, Ishan Dhingra notifications@github.com
wrote:

@LiamInJapan https://github.com/LiamInJapan This seems to be a Compile
time Java error, check if you are extending class and overriding function
properly.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#6152 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABlM9y5Jjw-25LxmDODzomMkRKwTSAfXks5q-sxTgaJpZM4HjE37
.

Liam Conroy
Freelance Software Engineer
Portfolio http://liaminjapan.github.io
Twitter https://twitter.com/LiamInJapan
LinkedIn https://jp.linkedin.com/in/liamconroy2008
AngelList https://angel.co/liam-conroy

@LiamInJapan
Copy link
Contributor

So replacing with onHostPause, onHostResume e.t.c. gets it compiling, though there is a strikethrough on these function names (deprecated?).

Then I get a "Seem's you're trying to access 'ReactNative.Component' from the 'react-native' package "throwOnWrongReactAPI" exception...

Again these are using samples from the documentation... I am following the instructions now

@LiamInJapan
Copy link
Contributor

Ok I am finally at Hello World, though I think this is the longest "Hello World" I've ever experienced.

I still have the depreciated issue mind regarding the onHostXXXX functions (onDestroy e.t.c. don't work) which makes me think I still have a versioning issue:

"dependencies": {
    "react": "^15.3.2",
    "react-native": "^0.37.0"
  }
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.facebook.react:react-native:0.37.0'

Any advice appreciated!

@HannanShaik
Copy link

I am facing the same issue. Can someone help?

@StefanoCremona
Copy link

StefanoCremona commented Nov 22, 2016

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!

@HannanShaik
Copy link

@StefanoCremona I was able to get rid of the error with this, however when I run the app I get

java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Could not connect to development server.

I did this adb reverse tcp:8081 tcp:8081, even then it's not working. Did you come across this?

@zenghui01
Copy link

84m gp 2jp 93x 8v j 01
4ppwom_55zrsl2 zf241peu
no a39cfq6tu 1 3 8 h72m
l rot rolzttbaj 3bc0

@Jusenr
Copy link

Jusenr commented Feb 9, 2017

"dependencies": { "react": "^0.14.7", "react-native": "^0.26.2" }

02-09 19:44:03.409 12389-12475/com.kenny.embedded E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.kenny.embedded, PID: 12389 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:321) 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:246) 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:833) Caused by: java.lang.UnsatisfiedLinkError: could find DSO to load: libreactnativejni.so at com.facebook.soloader.SoLoader.loadLibraryBySoName(SoLoader.java:213) at com.facebook.soloader.SoLoader.loadLibrary(SoLoader.java:178) at com.facebook.react.bridge.JSCJavaScriptExecutor.<clinit>(JSCJavaScriptExecutor.java:25) at com.facebook.react.bridge.JSCJavaScriptExecutor$Factory.create(JSCJavaScriptExecutor.java:20) at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:183) at com.facebook.react.ReactInstanceManagerImpl$ReactContextInitAsyncTask.doInBackground(ReactInstanceManagerImpl.java:169) at android.os.AsyncTask$2.call(AsyncTask.java:307) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)  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:833) 

Excuse me? Thank you !

@sharjeel-ahmed
Copy link

I solved this problem by using the complete maven path in the app's build.gradle.

I had put this maven path in the Projects build.gradle before by mistake. Putting it into app's build.gradle worked.

@Jakevin
Copy link

Jakevin commented Feb 10, 2017

I am also hitting this error

app gradle

 compileSdkVersion = 25
 buildToolsVersion = "24.0.3"
 compile 'com.android.support:appcompat-v7:23.0.1'
 complie 'com.android.support:support-v4:23.0.1'
 compile "com.facebook.react:react-native:+" // From node_modules.

package.json

"dependencies": {
    "react": "^15.4.2",
    "react-native": "^0.41.0"
  }

@zenghui01
Copy link

keep the supportV7 version with the compileSdkVersion version

@alexblack
Copy link

alexblack commented Feb 18, 2017

I'm hitting this with React Native 0.41.2, I don't have a appcompat-v4 dependency in my build.gradle file, I do have:

compile 'com.android.support:appcompat-v7:23.3.0'

ah, but one of my dependencies uses:

compile 'com.android.support:support-v4:22.2.1'

@haemi
Copy link

haemi commented Feb 21, 2017

@NoTraceOfSnow I can't implement ReactApplication as it is not found - using compile "com.facebook.react:react-native:+" // From node_modules.

Am I missing something?

"dependencies": {
    "react": "^15.4.2",
    "react-native": "^0.41.2"
}

compileSdkVersion 25
buildToolsVersion "24.0.3"

compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'

@zenghui01
Copy link

@haemi your project has download this about the reactnative file? i have a good idea ,you can init a Official project ,View all files and you can find difference in the project,copy the difference file to you self project.if you can improt reactnative in you project you can link me , i will try my beast .my QQ email 2371479117@qq.com and you project has this picture files
1487663126 1

@haemi
Copy link

haemi commented Feb 21, 2017

@NoTraceOfSnow thanks for your quick response! I can import React into my project, I also have the node_modules folder with it's subfolders. But when I want to show my ReactNative-Activity, I get the error from above (java.lang.IllegalAccessError: Method 'void android.support.v4.net.ConnectivityManagerCompat.<init>()').

Then I wanted to try what you wrote here (#6152 (comment)), but I can't do the implements ReactApplication...

@zenghui01
Copy link

@haemi eee.... do you start your server? and i think you lost some file .
fng1eayuw2s9x 9ds 7 6 gthis is the office project ,i think you can see the office project file one by one.wish you success

@haemi
Copy link

haemi commented Feb 21, 2017

is this in build.gradle correct?

allprojects {
    repositories {
        ...
        maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
    ...
}

shouldn't it be ReactAndroid at the end? I do not have a react-native/android directory...

@zenghui01
Copy link

so sorry i am sleep last night ,yes,you should it be . i will tell you how to lead reactnative into your project.
first
second
you should find the data.txt with you appgridle diffrence and copy in you project
data.txt
and you must keep version like this picture
third
foru
Wish you success

@paolomaffei
Copy link

I suspect this is caused by gradle picking up the wrong version of react-native,
see PR here: #14743

@hramos hramos added Help Wanted :octocat: Issues ideal for external contributors. and removed Help Wanted :octocat: Issues ideal for external contributors. labels Mar 8, 2018
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Help Wanted :octocat: Issues ideal for external contributors. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests