title: Android app crashes on firebase phone authentication
body: <p>I am using firebase for phone number authentication.When I used my phone number, it automatically verifies it.But when I use another phone number I get <strong>classCastException</strong>.It says <em>"getGoogleApiForMethod() returned Gms"</em>.There is a similar problem in stackoverflow <a href="https://stackoverflow.com/questions/47973887/firebase-error-w-bichannelgoogleapi-firebaseauth-getgoogleapiformethod-r">Link</a>.The answer was to downgrade firebase or google play services in phone or emulator.I have included gradle as well below.Please check it  </p>
  
  <p>Exception:</p>
  
  <pre><code>W/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzal@c2c24f7
  05-11 15:00:05.597 29282-29282/ W/System.err: java.lang.ClassCastException: Otp.OtpCodeFrag cannot be cast to java.util.concurrent.Executor
  05-11 15:00:05.607 29282-29282/ W/System.err:     at Otp.OtpCodeFrag.signInWithPhoneAuthCredential(OtpCodeFrag.java:402)
          at Otp.OtpCodeFrag.access$200(OtpCodeFrag.java:39)
          Otp.OtpCodeFrag$2.onClick(OtpCodeFrag.java:222)
          at android.view.View.performClick(View.java:5716)
          at android.widget.TextView.performClick(TextView.java:10926)
          at android.view.View$PerformClick.run(View.java:22596)
          at android.os.Handler.handleCallback(Handler.java:739)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:148)
          at android.app.ActivityThread.main(ActivityThread.java:7325)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
  </code></pre>
  
  <p>OTPFrag.java:</p>
  
  <pre><code>        onVerificationStateChangedCallbacks=new PhoneAuthProvider.OnVerificationStateChangedCallbacks()
                      {
                          @Override
                          public void onVerificationCompleted(PhoneAuthCredential phoneAuthCredential)
                          {
                              phoneauthCredential = phoneAuthCredential;
                              automatic_verification = true;
  
                              Toast.makeText(getContext(), "Verification Completed", Toast.LENGTH_SHORT).show();
  
                          }
                          @Override
                          public void onVerificationFailed(FirebaseException e) {
                              Toast.makeText(getContext(),"Verification Failed",Toast.LENGTH_SHORT).show();
                              e.printStackTrace();
                          }
  
                          @Override
                          public void onCodeSent(String s, PhoneAuthProvider.ForceResendingToken forceResendingToken)
                          {
                              super.onCodeSent(s, forceResendingToken);
                              Toast.makeText(getContext(),"CodeSent",Toast.LENGTH_SHORT).show();
                              verificationid=s;
                              codesent=true;
                              token=forceResendingToken.toString();
                              Log.e("Token",token);
                              Log.e("ID",s);
          //                           smscode=phoneauthCredential.getSmsCode();
                          }
                          };
  
                      PhoneAuthProvider.getInstance().verifyPhoneNumber(
                          phonenumber,        // Phone number to verify
                          4,                 // Timeout duration
                          TimeUnit.SECONDS,   // Unit of timeout
                          getActivity(),               // Activity (for callback binding)
                          onVerificationStateChangedCallbacks);
  
      otpCodeLytBinding.verifyOtp.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view)
              {
  
                  code1=otpCodeLytBinding.cd1.getText().toString();
                  code2=otpCodeLytBinding.cd2.getText().toString();
                  code3=otpCodeLytBinding.cd3.getText().toString();
                  code4=otpCodeLytBinding.cd4.getText().toString();
                  code5=otpCodeLytBinding.cd5.getText().toString();
                  code6=otpCodeLytBinding.cd6.getText().toString();
                     if (code1!=null&amp;&amp;!code1.equals("")&amp;&amp;code2!=null&amp;&amp;
                     !code2.equals("")&amp;&amp;code3!=null&amp;&amp;!code3.equals("")
                     &amp;&amp;code4!=null&amp;&amp;!code4.equals("")&amp;&amp;code5!=null
                     &amp;&amp;!code5.equals("")&amp;&amp;code6!=null&amp;&amp;!code6.equals(""))
                 {
                     completecode=code1+code2+code3+code4+code5+code6;
                     Log.e("cm",completecode);
                     try {
                         if (verificationid!=null&amp;&amp;completecode!=null){
  
                             PhoneAuthCredential credential = PhoneAuthProvider.
                                 getCredential(verificationid, completecode);
                             signInWithPhoneAuthCredential(credential);
                         }
                         else {
                             Toast.makeText(getContext(),"Something null",Toast.LENGTH_SHORT).show();
                         }
                     }
                     catch (Exception e)
                     {
                         e.printStackTrace();
                     }
  
                 }
                 else {
                         Toast.makeText(getContext(),"Please enter otp",Toast.LENGTH_SHORT).show();
                     }
              }
          });
       private void signInWithPhoneAuthCredential(PhoneAuthCredential credential)
          {
              Log.e("SigningIn","Started");
              mAuth.signInWithCredential(credential)
                      .addOnCompleteListener((Executor) this, new OnCompleteListener&lt;AuthResult&gt;() {
                          @Override
                          public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                              if (task.isSuccessful()) {
                                  // Sign in success, update UI with the signed-in user's information
      //                            Log.d(TAG, "signInWithCredential:success");
      //
      //                            FirebaseUser user = task.getResult().getUser();
                                                            }
   else {
                                  // Sign in failed, display a message and update the UI
                                  Log.w(TAG, "signInWithCredential:failure", task.getException());
                                  if (task.getException() instanceof FirebaseAuthInvalidCredentialsException) {
                                      // The verification code entered was invalid
                                  }
                              }
                          }
                      });
          }
  </code></pre>
  
  <p>build.gradle(app):</p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 26
      defaultConfig {
          applicationId "com.root5solutions.loc8official"
          minSdkVersion 16
          targetSdkVersion 26
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      dataBinding {
          enabled = true
      }
  }
  
  dependencies {
      implementation fileTree(dir: 'libs', include: ['*.jar'])
      implementation 'com.android.support:appcompat-v7:26.1.0'
      implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
      implementation 'com.android.support.constraint:constraint-layout:1.1.0'
      implementation 'com.balysv:material-ripple:1.0.2'
  
  //    implementation 'com.appolica:flubber:1.0.1'
      implementation 'com.google.firebase:firebase-core:15.0.2'
      implementation 'com.google.firebase:firebase-auth:15.1.0'
      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'
  }
  apply plugin: 'com.google.gms.google-services'
  </code></pre>
  
  <p>build.gradle(Project):</p>
  
  <pre><code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
  
  buildscript {
  
      repositories {
          google()
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:3.1.1'
          classpath 'com.google.gms:google-services:3.2.0'
  
  
  
          // NOTE: Do not place your application dependencies here; they belong
          // in the individual module build.gradle files
      }
  }
  
  allprojects {
      repositories {
          google()
          jcenter()
          maven {
              url "https://maven.google.com" // Google's Maven repository
          }
      }
  }
  
  task clean(type: Delete) {
      delete rootProject.buildDir
  }
  </code></pre>