Reputation: 643
I had an error while trying to migrate to FireBase managed push, I tried using class FCMservice as the push app in samples but my app crashes giving this log:
FATAL EXCEPTION: AsyncTask #3
Process: com.galsa.example, PID: 17415
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.galsa.example. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at com.sinch.android.rtc.internal.client.fcm.FcmTask.doInBackground(Unknown Source)
at com.sinch.android.rtc.internal.client.fcm.FcmTask.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
Upvotes: 0
Views: 260
Reputation: 643
first you need to add this line in your dependencies in your root gradle file:
classpath 'com.google.gms:google-services:3.1.0'
then you have to add this line in dependencies in your project gradle file:
implementation 'com.google.firebase:firebase-messaging:11.6.0'
and also add this line at the end of your project gradle file:
apply plugin: 'com.google.gms.google-services'
then you have to follow the steps in this link to generate google-services.json
file and put it in the root folder of your project.
Upvotes: 0
Reputation: 21
IN BREIF: Most probably Firebase service dependency is not configured correctly in gralde files of the app. You should register your application in Firebase Console, download google-services.json file into your app main folder, where Firebase gradle plugin can find it and it will do all the work for you. Try to build and run our sample push app, look at the gradle files for
apply plugin: 'com.google.gms.google-services'
IN DETAILS: You can see in the crash log:
…Default FirebaseApp is not initialized in this process com.galsa.example. Make sure to call FirebaseApp.initializeApp(Context) first.
But in fact, Firebase if added to the project correctly, does everything for you automatically, including initialization call. You can find good explanation here: https://firebase.googleblog.com/2016/12/how-does-firebase-initialize-on-android.html. To add Firebase functionality to your app, one theoretically needs to do a lot of things – define resources, embed manifest with service declarations and permissions, add dependency jars/aars and finally provide some code to supply application context to SDK for initialization. Luckily, there is a Firebase developers provided gradle plugin, that does all of this for you. But, to make it work, it needs google-services.json that you can download from Firebase Console. If you look at build.gradle file for our push sample apps, you’ll find that it finishes with apply plugin: 'com.google.gms.google-services'
command which runs the plugin and it does ‘its magic’. If everything goes well, you should see inside your .apk’s merged manifest something like this:
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:exported="false"
android:authorities="…"
android:initOrder="100" />
In case this part is missing, it’s definitely your app build config issue, again look at our push sample apps. If it is there, make sure that there are no conflicting libraries versions, say if you use google’s play-services they should match like this:
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
Lastly, make sure to use up-to-date version of the libraries. 11.0.1 looks good in our tests.
Best regards, Victor
Upvotes: 2