37

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Chirag Parmar
  • 1,064
  • 2
  • 13
  • 29
  • Where is your code? Did you configure project on Firebase server properly? – Talha Jul 26 '16 at 07:12
  • yes i was import my project from google console to firebase console and also generated json file and add my project. – Chirag Parmar Jul 26 '16 at 07:15
  • At which line code gives error? Please post your java code and logcat. – Talha Jul 26 '16 at 07:16
  • In background Service fails in FCM library so i only get this error. FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, – Chirag Parmar Jul 26 '16 at 07:31
  • Is network connection ok? – Talha Jul 26 '16 at 07:36
  • 1
    Could you add your AndroidManifest to the question? Also your use of com.google.android.gms:play-services can cause issues since you will be using both firebase-messaging and play-services-gcm. FCM and GCM should not be used in the same project. – Arthur Thompson Jul 27 '16 at 23:51

13 Answers13

22
  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
Sujatha
  • 221
  • 2
  • 2
15

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

Sushant Gosavi
  • 3,647
  • 3
  • 35
  • 55
7

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 !

Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81
5

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.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Which are the things that can cause this? I'm not sure about what is exactly what cause this. I do have network and still throws this exception. I need to keep restarting the device till it works. – Felipe Castilhos Aug 16 '18 at 16:54
  • https://stackoverflow.com/questions/51123197/firebaseinstanceidservice-is-deprecated – Martin Zeitler Aug 16 '18 at 18:03
5

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

AWE
  • 64
  • 4
  • 14
5

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.

Gi Tavares
  • 367
  • 6
  • 15
2

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

IvanF.
  • 513
  • 10
  • 18
2

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

Max Mark
  • 71
  • 2
  • 9
2

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

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
1

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

marcolav
  • 405
  • 1
  • 6
  • 17
1

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

0

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

-1

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
Mojtaba Haddadi
  • 1,346
  • 16
  • 26