title: FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE
body: <p>I'm making an app which can write to firebase database on button click.
  The app is working on emulator but it's not working on my physical device.
  The app was working fine last week but today started giving error.
  Here's the main activity code:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      private Firebase fled1;
      Button on;
      Button off;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          on=  findViewById(R.id.on);
          off=  findViewById(R.id.off);
  
          on.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
              DatabaseReference fled1 = FirebaseDatabase.getInstance().getReferenceFromUrl("https://testproject-tb.firebaseio.com/");
              DatabaseReference fled1Child = fled1.child("Button1");     
              fled1Child.setValue("1");
              }
          });
  
          off.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
              DatabaseReference fled1 = FirebaseDatabase.getInstance().getReferenceFromUrl("https://testproject-tb.firebaseio.com/");
              DatabaseReference fled1Child = fled1.child("Button1"); 
              fled1Child.setValue("0");
              }
          });
      }
  </code></pre>
  
  <p>Here's my manifest file I have added all the permissions required:  </p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.lalitahuja.iotbutton"&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:roundIcon="@mipmap/ic_launcher_round"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name="com.example.lalitahuja.iotbutton.MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Here's the build Gradle file:</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "com.example.lalitahuja.iotbutton"
          minSdkVersion 15
          targetSdkVersion 28
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      //noinspection GradleCompatible
      implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support.constraint:constraint-layout:1.1.3'
      testImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.2'
      androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
      implementation 'com.google.firebase:firebase-core:16.0.8'
      implementation 'com.google.firebase:firebase-database:16.1.0'
      implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
      implementation 'com.google.firebase:firebase-auth:16.2.0'
      implementation 'com.firebase:firebase-client-android:2.5.2'
  }
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  
  <p>The error I'm getting:</p>
  
  <p>E/FirebaseInstanceId: Token retrieval failed: SERVICE_NOT_AVAILABLE</p>
  
  <p>Edit: I tried the solutions existing on internet but none of them is working.</p>