title: "Firebase API initialization failure." when extending Application class and using Firebase in Android
body: <p>I am integrating Firebase Cloud Messaging Service in my Android app. Currently my app extends the Application class (named as MainApplication) and is declared in manifest application tag.</p>
  
  <p>I have followed all the instructions to enable Firebase Cloud Messaging. When I run the app I receive below stack-trace</p>
  
  <pre><code>04-03 17:05:16.099 20911-20911/&lt;package_name&gt; E/FA: Failed to load metadata: Package name not found: android.content.pm.PackageManager$NameNotFoundException: : com.google.android.gms.internal.zzadf.getApplicationInfo(Unknown Source)
  04-03 17:05:16.099 20911-20911/&lt;package_name&gt; E/FA: Scheduler not set. Not logging error/warn
  04-03 17:05:16.099 20911-20911/&lt;package_name&gt; E/FA: Failed to load metadata: Package name not found: android.content.pm.PackageManager$NameNotFoundException: : com.google.android.gms.internal.zzadf.getApplicationInfo(Unknown Source)
  04-03 17:05:16.099 20911-20911/&lt;package_name&gt; E/FA: Scheduler not set. Not logging error/warn
  04-03 17:05:16.100 20911-20911/&lt;package_name&gt; V/FA: Collection enabled
  04-03 17:05:16.100 20911-20911/&lt;package_name&gt; V/FA: App package, google app id: 1:744836320047:android:a611bb33ea5170ee
  04-03 17:05:16.100 20911-20911/&lt;package_name&gt; I/FA: To enable faster debug mode event logging run:
                                                            adb shell setprop debug.firebase.analytics.app 
  04-03 17:05:16.100 20911-20911/&lt;package_name&gt; D/FA: Debug-level message logging enabled
  04-03 17:05:16.103 20911-20911/&lt;package_name&gt; 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.initializeApp(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:5262)
                                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4847)
                                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4787)
                                                                       at android.app.ActivityThread.access$1600(ActivityThread.java:154)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:234)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5526)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                    Caused by: java.lang.SecurityException: Permission Denial: getIntentSender() from pid=20911, uid=10252, (need uid=-1) is not allowed to send as package 
                                                                       at android.os.Parcel.readException(Parcel.java:1627)
                                                                       at android.os.Parcel.readException(Parcel.java:1579)
                                                                       at android.app.ActivityManagerProxy.getIntentSender(ActivityManagerNative.java:4032)
                                                                       at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:531)
                                                                       at android.app.PendingIntent.getBroadcast(PendingIntent.java:515)
                                                                       at com.google.android.gms.internal.zzaup.zzpE(Unknown Source)
                                                                       at com.google.android.gms.internal.zzaup.zzmS(Unknown Source)
                                                                       at com.google.android.gms.internal.zzauh.initialize(Unknown Source)
                                                                       at com.google.android.gms.internal.zzaue.&lt;init&gt;(Unknown Source)
                                                                       at com.google.android.gms.internal.zzaui.zzMP(Unknown Source)
                                                                       at com.google.android.gms.internal.zzaue.zzbM(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.initializeApp(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:5262) 
                                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4847) 
                                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4787) 
                                                                       at android.app.ActivityThread.access$1600(ActivityThread.java:154) 
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1452) 
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                       at android.os.Looper.loop(Looper.java:234) 
                                                                       at android.app.ActivityThread.main(ActivityThread.java:5526) 
                                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  04-03 17:05:16.105 20911-20911/&lt;package_name&gt; I/FirebaseInitProvider: FirebaseApp initialization successful
  </code></pre>
  
  <p>Even the token is not generated. But when I remove the application name attribute from application tag in manifest i.e. not specifying my application class in manifest. The above error goes away and I get the token.</p>
  
  <p>I have tried calling </p>
  
  <pre><code>FirebaseApp.initializeApp(this);
  </code></pre>
  
  <p>in onCreate of my application class, but still getting this error.
  Currently I am using below Firebase version but have tried with earlier version also, but still receiving the error stack.</p>
  
  <pre><code>compile 'com.google.firebase:firebase-messaging:10.2.1'
  </code></pre>
  
  <p>It does not make sense to remove the extended Application class in order to use Firebase. Not sure what is needed to be done.</p>
  
  <p>Thanks</p>