Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google GCM android crashes ( java.lang.NoClassDefFoundError: com.google.android.gms.R$string )

I am developing an app using the Google GCM service and it seems to be crashing on all pre-lollipop devices at Launch.. I Have followed google tutorial... and its working on lollipop and marshmallow

here are my project level dependencies

dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.google.gms:google-services:1.5.0'
}

I have this in my app level gradle file

compile 'com.google.android.gms:play-services:8.4.0'

and this

apply plugin: 'com.google.gms.google-services'

I have also setup android manifest.. and service classes accordingly and receiving GCM on marshmallow device.

I am having this error.

E/AndroidRuntime: FATAL EXCEPTION: main
      Process: itcurves.driver, PID: 12788
      java.lang.NoClassDefFoundError: com.google.android.gms.R$string
      at com.google.android.gms.measurement.zza.<init>(Unknown Source)
      at com.google.android.gms.measurement.zza.zzaR(Unknown Source)
      at com.google.android.gms.measurement.internal.zzn.zziJ(Unknown Source)
      at com.google.android.gms.measurement.internal.zzz.zza(Unknown Source)
      at com.google.android.gms.measurement.internal.zzw.<init>(Unknown Source)
      at com.google.android.gms.measurement.internal.zzaa.zzDj(Unknown Source)
      at com.google.android.gms.measurement.internal.zzw.zzaT(Unknown Source)
      at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
      at android.content.ContentProvider.attachInfo(ContentProvider.java:1591)
      at android.content.ContentProvider.attachInfo(ContentProvider.java:1562)
      at android.app.ActivityThread.installProvider(ActivityThread.java:4889)
      at android.app.ActivityThread.installContentProviders(ActivityThread.java:4476)
      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4413)
      at android.app.ActivityThread.access$1500(ActivityThread.java:142)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1263)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:136)
      at android.app.ActivityThread.main(ActivityThread.java:5120)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
      at dalvik.system.NativeStart.main(Native Method)
like image 870
Athar Rajpoot Avatar asked Feb 11 '16 08:02

Athar Rajpoot


1 Answers

I had same problem.You are probably facing it on devices prior 5.0 version.The reason why this happen is that version prior to android 5.0 use Dalvik and by default, Dalvik limits apps to a single classes.dex bytecode file per APK.The solution is to use multidex support.

Include in your build.gradle dependencies this:

compile 'com.android.support:multidex:1.0.0'


public class MyApp extends MultiDexApplication { 

  @Override
  public void onCreate() {
     super.onCreate(); 
  } 

}

than in your Manifest add MultiDexApplication class

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name=".MyApp">
        ...
    </application>
</manifest>

Note: If you already have your application class just extend it with MultiDexApplication class

like image 70
Haris Kovačević Avatar answered Nov 07 '22 04:11

Haris Kovačević