title: How to solve Firebase API initialization failure (Android + Firebase)
body: <p>I recently needed to use Google GCM in my project. From its <a href="https://developers.google.com/cloud-messaging/registration#automatic-retry-using-exponential-back-off">website</a> it is said:</p>
  
  <blockquote>
    <p>Firebase Cloud Messaging (FCM) is the new version of GCM. It inherits
    the reliable and scalable GCM infrastructure, plus new features! See
    the FAQ to learn more. If you are integrating messaging in a new app,
    start with FCM. GCM users are strongly recommended to upgrade to FCM,
    in order to benefit from new FCM features today and in the future.</p>
  </blockquote>
  
  <p>In order to setup a new Firebase application, I've followed the instructions provided at the <a href="https://firebase.google.com/docs/android/setup#prerequisites">official website</a> and did the following:</p>
  
  <ol>
  <li>Created a new Firebase app in the web console and got my json from there - after providing the correct package of my app;</li>
  <li>At the top level project's gradle file, I've added <code>classpath 'com.google.gms:google-services:3.0.0'</code> in the dependency section;</li>
  <li>At my module's gradle file, I've added: <code>compile 'com.google.firebase:firebase-core:9.0.0'
  compile 'com.google.firebase:firebase-messaging:9.0.0'</code> and in the last line of it, I've added: <code>apply plugin: 'com.google.gms.google-services'</code>;</li>
  </ol>
  
  <p>Full Gradle files are provided below:</p>
  
  <p>Top level gradle file:</p>
  
  <pre><code>buildscript {
      repositories {
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:2.1.0'
          classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7'
          classpath 'com.google.gms:google-services:3.0.0'
      }
  }
  
  allprojects {
      repositories {
          jcenter()
          maven { url "https://jitpack.io" }
      }
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>
  
  <p>Module's gradle file:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  apply plugin: 'com.neenbedankt.android-apt'
  
  android {
      compileSdkVersion 23
      buildToolsVersion "23.0.2"
  
      dexOptions {
          javaMaxHeapSize "4g"
      }
  
      defaultConfig {
          applicationId "br.com.gogame"
          minSdkVersion 21
          targetSdkVersion 23
          versionCode 1
          versionName "1.0"
          multiDexEnabled true
      }
  
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      useLibrary  'org.apache.http.legacy'
  }
  
  dependencies {
      ...
      compile 'com.google.firebase:firebase-core:9.0.0'
      compile 'com.google.firebase:firebase-messaging:9.0.0'
      ...
  }
  
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  
  <p>When I start my app I get this stacktrace:</p>
  
  <pre><code>05-23 14:04:55.109 13368-13368/br.com.gogame I/art: Rejecting re-init on previously-failed class java.lang.Class&lt;com.google.android.gms.internal.zzqq$zzd&gt;
  05-23 14:04:55.109 13368-13368/br.com.gogame I/art: Rejecting re-init on previously-failed class java.lang.Class&lt;com.google.android.gms.internal.zzqq$zzd&gt;
  05-23 14:04:55.110 13368-13368/br.com.gogame I/art: Rejecting re-init on previously-failed class java.lang.Class&lt;com.google.android.gms.internal.zzqq$zzc&gt;
  05-23 14:04:55.110 13368-13368/br.com.gogame I/art: Rejecting re-init on previously-failed class java.lang.Class&lt;com.google.android.gms.internal.zzqq$zzc&gt;
  05-23 14:04:55.126 13368-13368/br.com.gogame E/FirebaseApp: Firebase API initialization failure.
                                                              java.lang.reflect.InvocationTargetException
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at com.google.firebase.FirebaseApp.zza(Unknown Source)
                                                                  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                                                                  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
                                                                  at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
                                                                  at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
                                                                  at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
                                                                  at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
                                                                  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
                                                                  at android.app.ActivityThread.installProvider(ActivityThread.java:5174)
                                                                  at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769)
                                                                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709)
                                                                  at android.app.ActivityThread.-wrap1(ActivityThread.java)
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                  at android.os.Looper.loop(Looper.java:148)
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
                                                               Caused by: java.lang.NoSuchMethodError: No static method zzy(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzx; or its super classes (declaration of 'com.google.android.gms.common.internal.zzx' appears in /data/app/br.com.gogame-2/base.apk:classes26.dex)
                                                                  at com.google.android.gms.measurement.internal.zzt.zzaU(Unknown Source)
                                                                  at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source)
                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                  at com.google.firebase.FirebaseApp.zza(Unknown Source) 
                                                                  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
                                                                  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source) 
                                                                  at com.google.firebase.FirebaseApp.zzbu(Unknown Source) 
                                                                  at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) 
                                                                  at android.content.ContentProvider.attachInfo(ContentProvider.java:1748) 
                                                                  at android.content.ContentProvider.attachInfo(ContentProvider.java:1723) 
                                                                  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) 
                                                                  at android.app.ActivityThread.installProvider(ActivityThread.java:5174) 
                                                                  at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769) 
                                                                  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709) 
                                                                  at android.app.ActivityThread.-wrap1(ActivityThread.java) 
                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415) 
                                                                  at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                  at android.os.Looper.loop(Looper.java:148) 
                                                                  at android.app.ActivityThread.main(ActivityThread.java:5443) 
                                                                  at java.lang.reflect.Method.invoke(Native Method) 
                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) 
                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
  05-23 14:04:55.131 13368-13368/br.com.gogame I/FirebaseInitProvider: FirebaseApp initialization successful
  05-23 14:04:55.133 13368-13368/br.com.gogame E/AndroidRuntime: FATAL EXCEPTION: main
                                                                 Process: br.com.gogame, PID: 13368
                                                                 java.lang.NoSuchMethodError: No static method zzy(Ljava/lang/Object;)Ljava/lang/Object; in class Lcom/google/android/gms/common/internal/zzx; or its super classes (declaration of 'com.google.android.gms.common.internal.zzx' appears in /data/app/br.com.gogame-2/base.apk:classes26.dex)
                                                                     at com.google.android.gms.measurement.internal.zzt.zzaU(Unknown Source)
                                                                     at com.google.android.gms.measurement.AppMeasurementContentProvider.onCreate(Unknown Source)
                                                                     at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
                                                                     at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
                                                                     at android.app.ActivityThread.installProvider(ActivityThread.java:5174)
                                                                     at android.app.ActivityThread.installContentProviders(ActivityThread.java:4769)
                                                                     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4709)
                                                                     at android.app.ActivityThread.-wrap1(ActivityThread.java)
                                                                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
                                                                     at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                     at android.os.Looper.loop(Looper.java:148)
                                                                     at android.app.ActivityThread.main(ActivityThread.java:5443)
                                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  </code></pre>
  
  <p>Any help solving this problem will be very appreciated!
  Regards</p>