FirebaseApp named [DEFAULT] does not exist

After switching to Firebase Cloud Messaging. When I open my application, it crashes and throws an error message java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. I already posted my new google-services.json and updated my SDK.

Here is my mainactivity

 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Check Google play service GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance(); int resultCode = googleAPI.isGooglePlayServicesAvailable(this); if (resultCode != ConnectionResult.SUCCESS) { if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) { GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show(); } else { Log.e(LOG_TAG, "This device is not supported."); finish(); } } Log.i(TAG, "InstanceID token: " + FirebaseInstanceId.getInstance().getToken()); } } 
+64
java android firebase
May 20 '16 at 9:00 a.m.
source share
12 answers

Do a double check, you added

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

at the bottom of the app gradle file, and then clean and rebuild the project

+67
May 21 '16 at 11:09
source share

Not sure if this is relevant. But there is another scenario when this can happen.




If your application has a service (with a different process) and you create your own Application class, the service and front-end application will use the same application class ( not the same instance ) to initialize. Now when I use the com.google.firebase:firebase-crash dependency to handle failures, the background service your.app.packagename:background_crash . For some reason, this caused crashes in my application. In particular, because in my application class I made a call like

 FirebaseDatabase.getInstance().setPersistenceEnabled(true); 

I assume that the background service when initializing with our Application class, somehow Firebase does not initialize. To fix this, I did

 if (!FirebaseApp.getApps(this).isEmpty()) FirebaseDatabase.getInstance().setPersistenceEnabled(true); 
+21
Jul 24. '16 at 4:08
source share

I had a similar problem and for me it was a bug / problem with an explicit merge. I found out that FirebaseInitProvider not added to the final manifest file due to tools:node="replace" in the application manifest file. So, try removing this xml tag and FirebaseInitProvider will be entered and Firebase can be initialized correctly.

+12
Jun 27 '16 at 17:55
source share

build.gradle file:

 buildscript { repositories { jcenter() mavenLocal() } dependencies { classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.google.gms:google-services:3.0.0' } } allprojects { repositories { jcenter() mavenLocal() } } 

\ app \ build.gradle file:

 apply plugin: 'com.android.application' android { .. } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) .. compile 'com.google.firebase:firebase-core:9.0.2' compile 'com.google.firebase:firebase-messaging:9.0.2' } apply plugin: 'com.google.gms.google-services' 
+10
Jun 24 '16 at 13:19
source share

@jmodrako's answer solved my problem ... tools:node="replace" to tools:node="merge"

Explained ... on AndroidManifest.xml

FROM

 <application ... tools:node="replace"> 

For

 <application ... tools:node="merge"> 

Combine issues with library themes? Troubleshoot with tools:replace="android:theme"

Credits

+10
Sep 08 '16 at 3:06 on
source share

Move the firebase initialization inside the onCreate of Application class. Also, if you turned on offline storage, FirebaseDatabase.getInstance (). SetPersistenceEnabled (true) should appear before any other initializations.

+2
Jun 29 '16 at 8:37
source share

Android Studio

  • apply the plugin: "com.google.gms.google-services" (build.gradle - module level)
  • Menu ~> Addition ~> CleanProject

It works fine for me.

0
May 25 '16 at 8:50
source share

In your dependency just add:

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) ... compile 'com.google.firebase:firebase-core:9.0.2' compile 'com.google.firebase:firebase-messaging:9.0.2' } 

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

0
Jul 28 '16 at 19:51
source share

Register your application in Firebase and copy google-services.json into your root project.

Apply classpath 'com.google.gms:google-services:3.1.0 to your root build.gradle.

Apply apply plugin: 'com.google.gms.google-services for your project.

0
Jun 16 '17 at 11:16
source share

Change the create action (GoogleServicesJson) to the name of the Google-Services.Json file.

0
Dec 13 '18 at 10:55
source share

In my case, I did not initialize Firebase when the application started, I had to do the following to solve it

 @Service public class FirebaseSetup implements CommandLineRunner { public void run(String... args) throws Exception { initializeFirebase(); } private void initializeFirebase() throws FileNotFoundException, IOException { FileInputStream serviceAccount = new FileInputStream(ResourceUtils.getFile("classpath:ssf1-v1-firebase-adminsdk-zr72u-afcb5bc13b.json")); FirebaseOptions options = new FirebaseOptions.Builder().setCredentials(GoogleCredentials.fromStream(serviceAccount)).build(); FirebaseApp.initializeApp(options); } } 
0
Mar 07 '19 at 6:01
source share

Check all configurations as shown below:

Setting up a 1-firebase: google-services.json project correctly? enter image description here

2- add Firebase SDK enter image description here

3- clean - rebuild your project

hope this helps!

0
Jul 07 '19 at 16:30
source share



All Articles