Chirag Parmar
Chirag Parmar

Reputation: 1064

FirebaseCloudMessaging : FirebaseInstanceId background sync failed - SERVICE_NOT_AVAILABLE

I have use Firebase Cloud Messaging(FCM) API for the push notification in Android. When I implemented that time perfect work but now it's can not find the Service of google play.

the error is:

FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE,

Please help me how to resolve. I Have use below dependency in gradle file.

dependencies {
    compile files('libs/ksoap2-android-assembly-3.4.0-jar.jar')
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile files('libs/gson-2.2.4.jar')
    compile files('libs/activation.jar')
    compile files('libs/mail.jar')
    compile files('libs/additionnal.jar')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.facebook.android:facebook-android-sdk:4.14.0'
    compile 'com.google.firebase:firebase-messaging:9.0.2'

    compile('com.google.android.gms:play-services:9.0.2') {
        exclude group: "play-services-wallet"
        exclude module: "play-services-wallet"
        exclude group: "play-services-ads"
        exclude module: "play-services-ads"
    }

}

Thanks for taking the time to read this.

Upvotes: 37

Views: 54054

Answers (13)

Alisha Shaw
Alisha Shaw

Reputation: 1

You need to update your play services and make sure your internet connectivity is good.

Upvotes: 0

Mojtaba Haddadi
Mojtaba Haddadi

Reputation: 1376

In my case

I have been Added google-services.json file in Project root, I moved it to app folder and problem has been fixed.

MyProjectRootDir/google-services.json

move to --> 

MyProjectRootDir/app/google-services.json

Upvotes: -1

Gi Tavares
Gi Tavares

Reputation: 377

I just had this problem. In my case, only worked when I stopped the emulator, closed it, and opened again. I didn't make any other changes.

Upvotes: 5

Praveen Kashyap
Praveen Kashyap

Reputation: 41

Me too had the same issue, resolved by just Clean Project option under build. Hope it might help anyone here.

Upvotes: 1

Suraj Vaishnav
Suraj Vaishnav

Reputation: 8315

Connect your mobile with different wifi connection with different service provider. It seems weird but you can try it!

Upvotes: 2

AWE
AWE

Reputation: 74

I had to disbale my VPN - hope this helps someone !

Upvotes: 5

Max Mark
Max Mark

Reputation: 81

In my case - I rebooted my PC and it worked.

Im not an expert, so I might have covered one of the mentioned tipps by my approach

Upvotes: 2

marcolav
marcolav

Reputation: 485

In my case, I just removed instant run from Android Studio preferences

Upvotes: 1

IvanF.
IvanF.

Reputation: 543

Easiest solution is to delete the bin and obj folders under the .Droid directory.
In this way you have a clean start every time.

Upvotes: 2

Sushant Gosavi
Sushant Gosavi

Reputation: 3835

You can check

  1. Check your internet connection with no proxy and open internet connect
  2. Replace your google-service.json with new one you can get this in firebaseconsol
  3. Please check your device has google play service in it and it working or not , firebase not work without google play service

Check -FireBaseInstanceId service does not get registered

Upvotes: 15

Sujatha
Sujatha

Reputation: 221

  1. Verify internet connectivity
  2. Verify if the Android SDK tools(Tools -> Android -> SDK manager -> SDK tools tab) has 'Google Play services' latest version and if not install the package. Then if you are using emulator, please stop the emulator and start it again.It works

Upvotes: 22

Martin Zeitler
Martin Zeitler

Reputation: 76789

the service needs to be bound in the Manifest.xml

    <!-- Firebase InstanceId Service -->
    <service
        android:name="eu.acme.service.FireBaseInstanceIdService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>

then one can access one single exposed method (the other names are obfuscated = not reliable):

package eu.acme.service;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class FireBaseInstanceIdService extends FirebaseInstanceIdService {

    @Override
    @android.support.annotation.WorkerThread
    public void onTokenRefresh() {

        /* obtain the current InstanceId token: */
        String token = FirebaseInstanceId.getInstance().getToken();
    }
}

one could only work around it, by not provoking it, eg. by not adding any AuthState Listener while knowing that there is no active network present, as explained here - as it seems, one otherwise cannot catch the exception thrown from within the library - which can be ignored, since it merely just complains, that there is no network connectivity.

com.google.android.gms.iid and com.google.firebase.iid are about the same.

Upvotes: 5

Yogesh Rathi
Yogesh Rathi

Reputation: 6509

After long struggle i found the answer, if google play service is not running then FirebaseInstanceId background sync failed - SERVICE_NOT_AVAILABLE log print, so you can check your google play service is running properly or not ?

May be this information is helpful to you !

Upvotes: 7

Related Questions