title: FirebaseException: An internal error has occurred. [ API key expired. Please renew the API key. ]
body: <p>I am developing an Android app and trying to implement a Google sign-in functionality. The authentication info that it's supposed to produce, is stored in my Firebase database. It seemed to have worked until recently.
  I have been trying to resolve this frustrating exception in many ways:</p>
  <ul>
  <li>I regenerated an API key on GCP, redownloaded google-services.json and rebuilt the project.</li>
  <li>I noticed that the API key specified in the values.xml file (this file is stored in app\build\generated\res\google-services\debug\values) is outdated. Therefore, I tried to modify the fields &quot;google_api_key&quot; and &quot;google_crash_reporting_api_key&quot;, as well as delete the file itself. The outdated data appears as soon as I rebuild the project.</li>
  <li>I made sure that the SHA-1 is specified in the Firebase console</li>
  <li>I set the API key's restrictions using GCP</li>
  </ul>
  <p>Google sign-in code:</p>
  <pre><code>   private void loginUserWithGoogle() {
      GoogleSignInOptions gsio = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
              .requestIdToken(getOwnerActivity().getString(R.string.default_web_client_id))
              .requestEmail()
              .build();
      GoogleSignInClient gsic = GoogleSignIn.getClient(getContext(), gsio);
      Intent sii = gsic.getSignInIntent();
      getOwnerActivity().startActivityForResult(sii, GOOGLE_SIGN_IN_REQUEST_CODE);
  }
  
  public void credentialsFromGoogleIntent(@Nullable Intent data) {
      Task&lt;GoogleSignInAccount&gt; accountTask =
              GoogleSignIn.getSignedInAccountFromIntent(data);
      accountTask.addOnCompleteListener(receiveAuthInfo -&gt; {
          if (receiveAuthInfo.isSuccessful()) {
              GoogleSignInAccount account = accountTask.getResult();
              AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
              auth.signInWithCredential(credential).
                      addOnCompleteListener(completeSignIn -&gt; {
                          if (!completeSignIn.isSuccessful()) {
                              Log.w(&quot;LoginWindow&quot;, &quot;signInWithCedential:Failure&quot;, completeSignIn.getException());
                              return;
                          }
                          CollectionReference reference = db.collection(USER_COLLECTION);
                          FirebaseUser user = auth.getCurrentUser();
                          Query query = reference.whereEqualTo(&quot;uuid&quot;, user.getDisplayName());
                          query.get().addOnCompleteListener(task -&gt; {
                              if (task.getResult().size() &lt;= 0) {
                                  UserProfileChangeRequest.Builder build = new UserProfileChangeRequest.Builder();
                                  String userId = UUID.randomUUID().toString();
                                  build.setDisplayName(userId);
                                  Task&lt;Void&gt; task1 = user.updateProfile(build.build());
                                  Map&lt;String, Object&gt; userData = new HashMap&lt;&gt;();
                                  userData.put(&quot;uuid&quot;, userId);
                                  userData.put(&quot;password&quot;, &quot;irrelevant&quot;);
                                  Task&lt;DocumentReference&gt; task2 = reference.add(userData);
                                  Tasks.whenAll(task1, task2).continueWith(taskContinue -&gt; {
                                      Intent intent = new Intent(getOwnerActivity(),
                                              MainActivity.class);
                                      getOwnerActivity().startActivity(intent);
                                      return null;
                                  });
                              } else {
                                  Intent intent = new Intent(getOwnerActivity(),
                                          MainActivity.class);
                                  getOwnerActivity().startActivity(intent);
                              }
                          });
                      });
          } else
              Log.w(&quot;LoginWindow&quot;, receiveAuthInfo.getException().toString());
      });
  }
  </code></pre>