17

I'm using Phone Authentication in Android Studio via Firebase, I Enabled Phone SignIn and Add SHA-1 And SHA-256 in Firebase Project. here is all of my dependencies :

dependencies {

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
testImplementation 'junit:junit:4.13.1'
implementation 'com.hbb20:ccp:2.4.0'
implementation 'com.google.firebase:firebase-auth:20.0.0'
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:26.0.0')
implementation 'com.google.android.gms:play-services-safetynet:17.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

and here is the error logs:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.securechat, PID: 24159
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/browser/customtabs/CustomTabsIntent$Builder;
    at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.0:92)
    at com.google.firebase.auth.api.internal.zzeq.zza(com.google.firebase:firebase-auth@@20.0.0:79)
    at com.google.firebase.auth.api.internal.zzeq.onPostExecute(com.google.firebase:firebase-auth@@20.0.0:88)
    at android.os.AsyncTask.finish(AsyncTask.java:695)
    at android.os.AsyncTask.access$600(AsyncTask.java:180)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6692)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.browser.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.example.securechat-GUvvd01g4yeRO2eP4pBFfA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.securechat-GUvvd01g4yeRO2eP4pBFfA==/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at com.google.firebase.auth.internal.RecaptchaActivity.zza(com.google.firebase:firebase-auth@@20.0.0:92) 
    at com.google.firebase.auth.api.internal.zzeq.zza(com.google.firebase:firebase-auth@@20.0.0:79) 
    at com.google.firebase.auth.api.internal.zzeq.onPostExecute(com.google.firebase:firebase-auth@@20.0.0:88) 
    at android.os.AsyncTask.finish(AsyncTask.java:695) 
    at android.os.AsyncTask.access$600(AsyncTask.java:180) 
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:193) 
    at android.app.ActivityThread.main(ActivityThread.java:6692) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Sachin Deshpande
  • 171
  • 1
  • 1
  • 3

12 Answers12

31

implementation androidx.browser:browser:1.2.0

Use this dependency to solve the problem.

allenski
  • 1,652
  • 4
  • 23
  • 39
Taizul Islam
  • 310
  • 2
  • 4
  • I added this, but now it's asking for a browser when entering the OTP code, which is not good for user. I used to use the previous version (before 20.0.0) for the `com.google.firebase:firebase-auth`, and it wasn't asking for a browser. – user1801605 Nov 08 '20 at 01:06
  • If you see the firebase phone auth updated documentation and it says that first you need to reCAPTCHA verification through your browser. – Taizul Islam Nov 09 '20 at 08:06
  • 2
    @user1801605 you need to enable the Android DeviceCheck API for your project in the Google Cloud Console, follow the guide here: https://firebase.google.com/docs/auth/android/phone-auth If this API is not enabled the auth now defaults to reCAPTCHA verification to check if the user is a real person (which requires the browser, and the import that TaizulIslam mentioned) As for the previous versions not asking for this, that's true, but I suppose Google wanted to improve the security of this auth system. – Manuel Rego Nov 09 '20 at 18:23
  • If I enable the Android DeviceCheck API, will that affect users that are still using the old version (prior to 20.0.0)? – user1801605 Nov 10 '20 at 23:55
  • @ManuelRego enabled the Android DeviceCheck API, the captcha is still on, any more configuration is needed? – johnrao07 Dec 17 '20 at 17:53
  • @johnrao07 follow this [Enable Safety](https://stackoverflow.com/questions/64588281/caused-by-java-lang-classnotfoundexception-didnt-find-class-in-firebase-phone/65455063#65455063). – Devyank Shaw Dec 26 '20 at 09:36
22

In new Firebase auth version,they've made major changes like Recaptcha , SafetyNet for human verification. By adding

implementation "androidx.browser:browser:1.3.0"

it solved my problem but user experience was not good because firebase was opening browser to verify reCAPTCHA and that was looking odd in app flow.

Firebase Quote "The reCAPTCHA flow will only be triggered when SafetyNet is unavailable or your device does not pass suspicion checks. Nonetheless, you should ensure that both scenarios are working correctly." So to enable SafetyNet follow below steps or you can also visit Firebase Auth for more info.

  1. Go to google cloud console , select your project .

  2. Click on navigation menu and select APis & services and then select Dashboard .

  3. Click on enable api and services and enable api " Android Device Verification".

  4. Add SHA 256 in firebase project settings.(debug and release both)

  5. Download and replace the latest google-services.json file in your project.

Himanshi Thakur
  • 2,077
  • 14
  • 32
  • 1
    in the release note they claim it is a bug and its fixed, it'll fallback for whatever browser which exists!, my app just crashes on latest auth – Yadu Dec 10 '20 at 14:46
  • @Yadu my crash fixed after adding implementation "androidx.browser:browser:1.2.0" – Himanshi Thakur Dec 11 '20 at 09:28
  • Hey @HimanshiThakur , please help me understand, how do I connect the google cloud to my project so enabling the " Android Device Verification" API will have an effect? – Itay Feldman Jan 11 '21 at 18:12
  • 1
    Hi @ItayFeldman If your project is connected to firebase then just open google cloud console and select your project from dropdown you don't need to do any extra steps . – Himanshi Thakur Jan 12 '21 at 10:20
  • 2
    Enabling "Android Device Verification" and adding SHA256 to firebase project was my solution, thank you soo much. – Zurmati Jan 20 '21 at 22:03
  • 1
    This should be the accepted answer. Thanks a lot @HimanshiThakur. – Shrijan Regmi Feb 02 '21 at 06:00
14

If someone coming from react-native, after searching all around I found this temporary solution.

Adding the below

implementation "androidx.browser:browser:1.2.0"

into android/app/build.gradle dependencies solved issue.

Pratap Sharma
  • 2,633
  • 2
  • 18
  • 32
  • 1
    This solved my issue and my project is strictly android. I was also using the firebase bom so I think this should be the accepted answer. – Brook MG Nov 30 '20 at 15:56
  • 1
    This worked for me. Use the latest version. – gsm Feb 23 '21 at 04:48
3

You need CustomTabs to add to your project so your app in mobile can access browser using CustomTabs

implementation 'com.android.support:customtabs:28.0.0'
Sajid Zeb
  • 1,806
  • 18
  • 32
3

Same thing happened with me. What I did basically removed the following line-

implementation platform('com.google.firebase:firebase-bom:26.0.0')

shivam mishra
  • 41
  • 1
  • 3
3

Add this dependency in your build.gradle file... implementation 'com.android.support:customtabs:28.0.0-alpha3'

mail test
  • 31
  • 2
2

Since you're using the firebase-bom dependency, that library determines the version of all Firebase SDKs you use. This means that you should not specify version numbers for any other Firebase SDKs in your gradle file.

So remove the version number from firebase-auth:

implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:26.0.0')
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • @Frank van Puffelen this doesnt solve the problem, and firebase release notes states this is fixed and will fallback to whatever browser is present in the device but it aint happening – Yadu Dec 10 '20 at 15:23
2

Follow the below steps:

  1. In the Google Cloud console, enable the Android DeviceCheck API for your project.

  2. Get SHA-256 fingerprint for below frameworks:

  3. Go to Settings Page of the Firebase console, select your project and set the SHA-256 fingerprint for your app.

  4. Re-run the app.

For more info go to Enable app verification doc.

Devyank Shaw
  • 159
  • 7
0

Guys I have found a way just follow the steps. In "Phone Authentication docs" of firebase you will find the option (2.Enable app verification) Follow these steps:

  • Enable AndroidDevice check API by clicking on it.

  • Then add your SHA-256. (Gradle on your right side of android studio->Tasks->android->signingReports.)

You will get your SHA-256 there for your app.

greybeard
  • 2,249
  • 8
  • 30
  • 66
0

Just add this line: implementation "androidx.browser:browser:1.3.0"

It will solve your problem definitely. Make sure to also add the SHA-256 in Firebase.

Nafis Kabbo
  • 568
  • 5
  • 8
  • 2
    Welcome to Stack Overflow. This answer has already been given above. Please give answer that bring new information. – ChristianB Dec 31 '20 at 19:09
0

Add this dependency in your build.gradle file...

implementation platform('com.google.firebase:firebase-bom:26.2.0')

Now, Add your SHA-256 (Gradle on your right side of android studio->Tasks->android->signingReports) in settings of your project.

Following steps are very important...

  • Go to Google Cloud and select your project.
  • Select 'APis & services' from left hand side menu and then select Dashboard.
  • Click on 'Enable api and services' and then enable api 'Android Device Verification'.

enter image description here

In this click on 'VIEW ALL to get 'Android Device Verification' tab.

Mukul Raghav
  • 349
  • 2
  • 5
0

You can't test on an emulator, are you using a real phone? If you want to test from an emulator check this out https://firebase.flutter.dev/docs/auth/phone/#testing

alexalejandroem
  • 1,094
  • 12
  • 17