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

NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzw #463

Closed
TacticalSlothmaster opened this issue Aug 2, 2018 · 8 comments

Comments

@TacticalSlothmaster
Copy link

TacticalSlothmaster commented Aug 2, 2018

Hi,

I updated my dependencies in my app/build.gradle. Now I get the following red-screen error when I start my app (everything else is building correctly):

Java exception in 'NativeModules'

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzw;
com.learnium.RNDeviceInfo.RNDeviceModule.getConstants
    RNDeviceModule.java:260
com.facebook.react.bridge.JavaModuleWrapper.getConstants
    JavaModuleWrapper.java:140
android.os.Handler.handleCallback
    Handler.java:751
android.os.Handler.dispatchMessage
    Handler.java:95
com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage
    MessageQueueThreadHandler.java:31
<unknown>
    deviceinfo.js:6:33
loadModuleImplementation
    require.js:213:12
guardedLoadModule
    require.js:147:36
_require
    require.js:131:20
<unknown>
    HotelsScreen.js:19
loadModuleImplementation
    require.js:213:12
guardedLoadModule
    require.js:147:36
_require
    require.js:131:20
<unknown>
    StartScreen.js:5
loadModuleImplementation
    require.js:213:12
guardedLoadModule
    require.js:147:36
_require
    require.js:131:20
<unknown>
    AppNavigator.js:13
loadModuleImplementation
    require.js:213:12
guardedLoadModule
    require.js:147:36
_require
    require.js:131:20
<unknown>
    Root.js:4
loadModuleImplementation
    require.js:213:12
guardedLoadModule
    require.js:147:36
_require
    require.js:131:20
<unknown>
    index.android.js:3
loadModuleImplementation
    require.js:213:12
guardedLoadModule
    require.js:140:45
_require
    require.js:131:20
global code
    

This only happens on android. I tried to add

compile ("com.google.android.gms:play-services-gcm:16.1.0") {
            force = true;
        }

in my dependencies, but with no luck.

my android settings:

compileSdkVersion 27
buildToolsVersion "27.0.1"
...
minSdkVersion 16
targetSdkVersion 27
Device: Samsung Galaxy S6

also, I tried to do the following suggestions:
https://stackoverflow.com/questions/51036749/react-native-device-info-crash-the-app-on-android
but that didn't work either.

@x0fma
Copy link

x0fma commented Aug 6, 2018

Hey I had the same problem, I've resolved it by adding googlePlayServicesVersion=X.X.X in the gradle.properties file in the android folder. Tell me if it works for you ^^

@dwidc
Copy link

dwidc commented Aug 15, 2018

I also got the same problem recently. After hours of trials and errors (and hair pulling), turned out it's simply because of version mismatch between 'play-services-gcm' and 'firebase-messaging'.

I have "com.google.android.gms:play-services-gcm:10.2.6" set on app/build.gradle dependencies.
But I never set or include 'firebase-messaging', it's probably included implicitly by one of library.

To force versions used by library, you can set it on app/build.gradle:

configurations.all {
    resolutionStrategy {  
        // ...
        force 'com.google.android.gms:play-services-gcm:10.2.6'
        force 'com.google.firebase:firebase-messaging:10.2.6'
    }
}

or

dependencies {
    // ...
    compile ('com.google.android.gms:play-services-gcm:10.2.6') {
        force = true;
    }
    compile ('com.google.firebase:firebase-messaging:10.2.6') {
        force = true;
    }
}

either one will give the same result, I prefer the first one because it's easy on eyes.

That's it, it fixes the dreaded red screen NoClassDefFoundError for me.


You might want to verify versions used by library dependencies.

To see actual versions used by dependencies, check your '\android\app\build\intermediates\exploded-aar\' folder.

For example in my pc I have:
\exploded-aar\com.google.android.gms\play-services-gcm\10.2.6\ and
\exploded-aar\com.google.firebase\firebase-messaging\10.2.6\ folder,
which is good because both versions are the same.

Make sure libraries inside \com.google.android.gms\ and \com.google.firebase\ all use the same version.


If all above still fails, as last resort you can try disable InstanceID check on RNDeviceModule.java.

https://github.com/rebeccahughes/react-native-device-info/blob/02d63b9aabf7f553abe77bb72bc024f35ef1db68/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java#L270-L276

You can find it on your local \node_modules\react-native-device-info\android\src\main\java\com\learnium\RNDeviceInfo\RNDeviceModule.java

That InstanceID.getInstance().getId() line is where you get the red screen runtime error of NoClassDefFoundError.

I try commenting it out at first, and it works preventing NoClassDefFoundError.
But it's a quick hack, it doesn't solve the main problem. Only use it if you're in a hurry. 😉

Hope this helps.

@sfratini
Copy link

Can confirm that setting the googlePlayServicesVersion flag solved this for me too.

@mikehardy
Copy link
Collaborator

@machour closable - another failure to install correctly, but the library definitely works according to instructions (I just installed it...) - people need to define their specific versions in android/build.gradle then the modules will use the right version

@machour machour closed this as completed Mar 10, 2019
@waheedakhtar694
Copy link

any solution about my problem android app got crashed when i start chrome debugger. here is a log that i am getting in android-studio.

    Process: com.create.wefiq, PID: 20623
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzx;
        at com.google.android.gms.iid.zzaf.<init>(Unknown Source)
        at com.google.android.gms.iid.zzaf.<init>(Unknown Source)
        at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
        at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
        at com.learnium.RNDeviceInfo.RNDeviceModule.getConstants(RNDeviceModule.java:272)
        at com.facebook.react.bridge.JavaModuleWrapper.getConstants(JavaModuleWrapper.java:136)
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29)
        at android.os.Looper.loop(Looper.java:168)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.util.zzx" on path: DexPathList[[zip file "/data/app/com.create.wefiq-1/base.apk", zip file "/data/app/com.create.wefiq-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.create.wefiq-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.create.wefiq-1/lib/arm, /data/app/com.create.wefiq-1/base.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_dependencies_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_0_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_1_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_2_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_3_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_4_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_5_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_6_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_7_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_8_apk.apk!/lib/armeabi-v7a, /data/app/com.create.wefiq-1/split_lib_slice_9_apk.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
        at com.google.android.gms.iid.zzaf.<init>(Unknown Source) 
        at com.google.android.gms.iid.zzaf.<init>(Unknown Source) 
        at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source) 
        at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source) 
        at com.learnium.RNDeviceInfo.RNDeviceModule.getConstants(RNDeviceModule.java:272) 
        at com.facebook.react.bridge.JavaModuleWrapper.getConstants(JavaModuleWrapper.java:136) 
        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) 
        at android.os.Handler.handleCallback(Handler.java:739) 
        at android.os.Handler.dispatchMessage(Handler.java:95) 
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:29) 
        at android.os.Looper.loop(Looper.java:168) 
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:232) 
        at java.lang.Thread.run(Thread.java:818) 
    	Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.common.util.zzx
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        		... 14 more
     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
11-21 18:31:12.649 1002-1651/? E/ActivityManager: App crashed! Process:```

@waheedakhtar694
Copy link

thanks @mikehardy from here
evollu/react-native-fcm#998
Sijad's solution works for me.

@mikehardy
Copy link
Collaborator

Works only in the sense your compile works. That library is really, really old. It's an android library released before Android 9 was released. Android 10 is out now. I hesitate to think how it will work in practice.

You will want a modern library I think.

https://github.com/react-native-community/react-native-device-info/blob/master/refresh-example.sh#L39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants