Unable to authenticate with Firebase

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Unable to authenticate with Firebase



I am trying to sign in to Firebase on an emulator using credentials I added via the console.



Here is the code:


val auth = FirebaseAuth.getInstance()

auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) task ->
if (task.isSuccessful)
// ...
else
// ...




The OnCompleteListener callback is never triggered.


OnCompleteListener



I have followed the guidelines from the Firebase documentation



Any idea what I am doing wrong?



Gradle file - project:


buildscript
ext.kotlin_version = '1.2.60'
repositories
google()
jcenter()

dependencies
classpath 'com.android.tools.build:gradle:3.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.google.gms:google-services:4.0.2'



allprojects
repositories
google()
jcenter()



task clean(type: Delete)
delete rootProject.buildDir



Gradle file - app


apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android
compileSdkVersion 27
defaultConfig
applicationId "..."
minSdkVersion 23
targetSdkVersion 27
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'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'

implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-core:16.0.1'


apply plugin: 'com.google.gms.google-services'





Plz share gradle files @345
– Raj
Aug 7 at 16:37





Have you put SHA key in firebase?
– Sushant Somani
Aug 7 at 16:51





@Raj I have shared the gradle files.
– 345
Aug 7 at 17:03





Yeah, the SHA-1 key is setup.
– 345
Aug 7 at 17:05





@345 Have you tried to log task.getException() in the else part of your if (task.isSuccessful) statement, to actually see what the problem is?
– Alex Mamo
Aug 8 at 8:49


task.getException()


if (task.isSuccessful)




3 Answers
3



Is your email or password are valid?



You can add 'addOnFailureListener' to see what really happened.


auth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this) task ->
if (task.isSuccessful)
// ...
else
// ...

).addOnFailureListener(new OnFailureListener()
@Override
public void onFailure(@NonNull Exception e)
Toast.makeText(context, e.getMessage(),Toast.LENGTH_SHORT).show();

);





The credentials are valid. onFailure is not firing either.
– 345
Aug 7 at 17:07






Or you have to update your firebase-auth dependencies to newer version. Now is 16.0.2
– Lipondevf
Aug 7 at 17:09





I have updated to the latest dependencies but the problem persists.
– 345
Aug 7 at 17:21





Did you have added internet permission? <uses-permission android:name="android.permission.INTERNET" />
– Lipondevf
Aug 7 at 17:45





Yeah the permission is in the manifest.
– 345
Aug 7 at 18:23



Try to add the following dependency in the build.gradle file:-


implementation 'com.google.firebase:firebase-core:16.0.1'



And I also recommend you to use the latest firebase dependencies.





I have added the core dependency and updated the others but the problem persists.
– 345
Aug 7 at 17:22





Also update google services to classpath 'com.google.gms:google-services:4.0.2'
– Raj
Aug 7 at 17:51





I did but still no success :(
– 345
Aug 7 at 18:24



I solved the issue by



This solution may be helpful for those of you who are using an emulator and have tried all the suggested answers...






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard