firebase android user database Sign up Error - android

I was doing this tutorial on Android and Firebase but for some reason when I try to register a new driver it doesn't interact with Firebase at all. Though it does show it's connected to Firebase:
I have downgraded my API to 26 because of this error:
Google Play services out of date. Requires 9256000 but found 9080470.
So I installed Genymotion to solve this issue as advised by contributors on this platform.
But it still doesn't communicate with Firebase. It returns 0 Errors and yet doesn't work.
I've installed GenyMotion but every time I try to run on it's devices it keeps crashing.
public class DriverLoginActivity extends AppCompatActivity {
private EditText mEmail, mPassword;
private Button mLogin, mRegistration;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener firebaseAuthListener;
private static final String TAG = "Test";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_driver_login);
mAuth = FirebaseAuth.getInstance();
firebaseAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user!=null){
Intent intent = new Intent(DriverLoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
return;
}
}
};
mEmail = findViewById(R.id.email);
mPassword = findViewById(R.id.password);
mLogin = findViewById(R.id.login);
mRegistration = findViewById(R.id.registration);
mRegistration.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String email = mEmail.getText().toString();
final String password = mPassword.getText().toString();
mAuth.createUserWithEmailAndPassword(email,
password).addOnCompleteListener(DriverLoginActivity.this, new
OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(!task.isSuccessful()){
Toast.makeText(DriverLoginActivity.this, "sign up
error", Toast.LENGTH_SHORT).show();
}else {
String user_id = mAuth.getCurrentUser().getUid();
DatabaseReference current_user_db =
FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").child(user_id);
current_user_db.setValue(true);
}
}
});
}
});
mLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String email = mEmail.getText().toString();
final String password = mPassword.getText().toString();
mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(DriverLoginActivity.this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());
if(!task.isSuccessful()){
Log.d(TAG, "onComplete: Failed=" + task.getException().getMessage());
Toast.makeText(DriverLoginActivity.this, "sign up error", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
#Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(firebaseAuthListener);
}
#Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(firebaseAuthListener);
}
}
Here are my build.gradle (app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "ke.co.wafalmelogistics.wafalme"
minSdkVersion 17
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'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.gms:google-services:3.1.0'
implementation 'com.google.firebase:firebase-core:11.6.0'
implementation 'com.google.firebase:firebase-database:11.6.0'
implementation 'com.google.firebase:firebase-auth:11.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
build.gradle (module)
// 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.0.0'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And here is the Error I keep getting when I try to run the app on GenyMotion;
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: ke.co.wafalmelogistics.wafalme, PID: 1640
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)' on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(Unknown Source)
at ke.co.wafalmelogistics.wafalme.DriverLoginActivity$2.onClick(DriverLoginActivity.java:61)
at android.view.View.performClick(View.java:5637)
at android.view.View$PerformClick.run(View.java:22429)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
ItI am a learner, any help is appreciated.

I get the same error because I was use Emulator ..
but when I try it in a real device it is working perfectly ..
Hope it works for you too..

Worked for me using these dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//NOT DEFAULT BELOW
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.android.support:design:26.1.0'
compile 'com.github.rtoshiro.mflibrary:mflibrary:1.0.0'
compile 'com.google.firebase:firebase-core:11.2.0'
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
}
Thank you for all the help.

I have the same problem when I use 'com.google.firebase:firebase-auth:11.6.0'
change to 'com.google.firebase:firebase-auth:11.2.0'
`
Try this dependencies:
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.firebase:firebase-database:11.2.0'
compile 'com.google.firebase:firebase-crash:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

had the same issue in my project while running in the emulator but I solved this by using this in Android Studio 3.0.1
app/build.gradle
compile "com.google.firebase:firebase-auth:9.0.2"
build.gradle ( root directory )
classpath 'com.google.gms:google-services:3.0.0'
there setting work for me

Looking at https://github.com/firebase/FirebaseUI-Android/issues/1104. I think this is an acknowledged issue in the SDK that would be resolved in the next 1 or 2 SDK updates. A github user called Samstern posts this -
A fix for this bug has been submitted internally, so this should be
fixed in the next 1-2 Firebase Auth SDK releases depending on the
release cycle.
I am going to close this issue here since there's nothing more
FIrebaseUI can do, thanks for everyone who reported it!
Nonetheless, try the following and see if it works. To repeat what Bob Snyder said - Delete this line from the dependencies block: implementation 'com.google.gms:google-services:3.1.0'. Upgrade your firebase to 11.8.0. So your app's build.gradle should look like something like this.
implementation 'com.google.firebase:firebase-core:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.google.firebase:firebase-messaging:11.8.0'
implementation 'com.google.firebase:firebase-storage:11.8.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
Let me know how that goes.

I solved this by upgrading Google Play Services in the emulator. It was not necessary to change anything in gradle.

For me works change from compile:
com.google.firebase:firebase-auth:11.8.0
to compile:
com.google.firebase:firebase-auth:11.2.0

Related

Cannot resolve symbol 'FirebaseInstanceId' Android

I started to encounter this error when I upgraded the version of the project to androidx. I also upgraded the firebase sdks. I started getting error "Cannot resolve symbol 'FirebaseInstanceId' " . With this method, I was taking the user's token and printing it to the database. How can I solve this problem?
Manifest :
<service
android:name=".MyFirebaseIdService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_SERVICE" />
</intent-filter>
MyFirebaseIdService;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseIdService extends FirebaseInstanceIdService {
#Override
public void onTokenRefresh() {
super.onTokenRefresh();
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
String refreshToken = FirebaseInstanceId.getInstance().getToken();
if (firebaseUser != null){
updateToken(refreshToken);
}
}
private void updateToken(String refreshToken) {
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token = new Token(refreshToken);
reference.child(firebaseUser.getUid()).setValue(token);
}
}
Token ( model class ):
public class Token {
private String token;
public Token(String token) {
this.token = token;
}
public Token() {
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
}
I was rewriting the token code every time the user entered the home page.
MainActiviy :
updateToken(FirebaseInstanceId.getInstance().getToken());
private void updateToken(String token){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token1 = new Token(token);
reference.child(fuser.getUid()).setValue(token1);
}
build.gradle ( project )
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle ( module )
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
android {
compileSdkVersion 30
defaultConfig {
applicationId "***"
minSdkVersion 19
targetSdkVersion 30
versionCode 21
versionName "1.1.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design: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.firebaseui:firebase-ui-database:4.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.github.orangegangsters:swipy:1.2.3#aar'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:4.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-inappmessaging-display:17.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
implementation('com.google.apis:google-api-services-people:v1-rev2-1.21.0')
{
exclude module: 'guava-jdk5'
}
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.firebase:firebase-ads:15.0.1'
implementation "io.grpc:grpc-okhttp:1.32.2"
implementation 'com.android.billingclient:billing:3.0.0'
implementation platform('com.google.firebase:firebase-bom:29.3.0')
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-core:20.1.2'
implementation 'com.google.firebase:firebase-messaging:23.0.2'
implementation 'com.google.firebase:firebase-auth:21.0.3'
}
apply plugin: 'com.google.gms.google-services'
----- UPDATE ---- SOLUTÄ°ON :
FirebaseMessaging.getInstance ().getToken ()
.addOnCompleteListener ( task -> {
if (!task.isSuccessful ()) {
return;
}
if (null != task.getResult ()) {
String firebaseMessagingToken = Objects.requireNonNull ( task.getResult () );
updateToken(firebaseMessagingToken);
}
} );
private void updateToken(String firebaseMessagingToken) {
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token = new Token(firebaseMessagingToken);
reference.child(firebaseUser.getUid()).setValue(token);
}

BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq#a34f859

I'm working on a mobile application using android and Firebase from a while but only now i encounter some problems as you can see here
I/BiChannelGoogleApi: [FirebaseAuth: ] getGoogleApiForMethod() returned Gms:com.google.firebase.auth.api.internal.zzaq#f3584ed
In addition, keep in mind already add users when i testing the app and i verified the e-mail and password as you can see :
here is my app gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
/...
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha06'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//firebase
implementation 'com.google.firebase:firebase-analytics:17.3.0'
implementation 'com.google.firebase:firebase-auth:19.3.0'
implementation files('libs/ojdbc14.jar')
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'org.springframework.android:spring-android-rest-template:2.0.0.M1'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.4.1.3'
}
project gradle:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
my problem is when i sign in with registred and verified user, here is my sign in function:
private void verifyLogin(View view) {
if ( !ValidatePassword() || !ValidateEmail()){
return;
}
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
String email= login_email_field.getText().toString();
String password= login_password_field.getText().toString();
Log.d("password", password);
Log.d("email", email);
firebaseAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()){
if (firebaseAuth.getCurrentUser().isEmailVerified()){
Intent intent = new Intent(getApplicationContext(), PublicHomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
}
}
});
}

How to solve hashmap to string problem in android

I'm Trying to read data from Firebase but app crashes on generate error in logcat below. I have tried all solutions available on stackoverflow and other sites but still i m failed to solve this issue I have made changes and shared necessary code here
.gradle Project (dependencies)
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
}
app.gradle (dependencies)
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
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.android.support:support-annotations:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
}
main.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FirebaseApp.initializeApp(getApplicationContext());
initViews();
mBtn.setOnClickListener(this::readData);
}
public void readData(View view) {
mRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
String data = dataSnapshot.getValue(String.class);
setT.setText(data);
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
setT.setText("Sorry Data");
}
});
}
private void initViews() {
mBtn = findViewById(R.id.mBtn);
setT = findViewById(R.id.setT);
}
}
Logcat
try replace your database implementation version 17.0.0 to this version
implementation 'com.google.firebase:firebase-database:16.0.5'
and it will work

com.google.firebase:firebase-config:16.0.0 not working

I did everything by following the instructions. But mFirebaseRemoteConfig.fetch(cacheExpiration) haven't been working.
But when I changed a version to the earlier in my app build gradle file from
implementation 'com.google.firebase:firebase-config:16.0.0'
to
implementation 'com.google.firebase:firebase-config:11.0.4'
it's become working..
Do you have any idea, what can be the reason of it?
Also I checked in my previous projects. I changed the version from 11.0.4 to 16.0.0 and fetching stoped working...
my app build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.bestworldgames.bestwordgame"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
android.defaultConfig.vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.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'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.inkapplications.viewpageindicator:library:2.4.3'
implementation 'com.startapp:inapp-sdk:3.8.4'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
exclude module: 'support-v4'
}
}
apply plugin: 'com.google.gms.google-services'
my project gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Added:
mFirebaseRemoteConfig.fetch(cacheExpiration) not working is mean that public void onComplete(#NonNull Task<Void> task) haven't been called.
mFirebaseRemoteConfig.fetch(cacheExpiration)
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Fetch Succeeded",
Toast.LENGTH_SHORT).show();
// After config data is successfully fetched, it must be activated before newly fetched
// values are returned.
mFirebaseRemoteConfig.activateFetched();
} else {
Toast.makeText(MainActivity.this, "Fetch Failed",
Toast.LENGTH_SHORT).show();
}
displayWelcomeMessage();
}
});
logcat:
06-04 17:39:55.966 10786-10826/com.bestwordgame W/GooglePlayServicesUtil: Google Play services out of date. Requires 12451000 but found 11509470
06-04 17:39:55.966 10786-10786/com.bestwordgame W/FA: Service connection failed: ConnectionResult{statusCode=SERVICE_VERSION_UPDATE_REQUIRED, resolution=null, message=null}
The promlem is in emulator, I guess.. But now I can't find Google Play settings in the emulator's extanded window.. If I'm right, Is there another way to update Google Play Services on emulator?
This is my SDK Settings
with 'Show package details':
Yes, the problem is in emulator. But also I've found out that it's better to check the device for a compatible Google Play services by GoogleApiAvailability.makeGooglePlayServicesAvailable() method.
See the link.
It's my verification method, wich I call at onCreate():
private void checkGooglePlayServices() {
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
int status = api.isGooglePlayServicesAvailable(this);
Log.i("TAG", "AppController checkGooglePlayServices status " + status);
if (status != ConnectionResult.SUCCESS) {
api.makeGooglePlayServicesAvailable(this);
}
}
You need to add:
implementation 'com.google.firebase:firebase-core:16.0.0'
Your app gradle file now has to explicitly list com.google.firebase:firebase-core as a dependency for Firebase services to work as expected.
more info here:
https://firebase.google.com/support/release-notes/android
Faced the same problem. I just replaced the google() by maven { url 'https://maven.google.com' }, then it started working.
Refer the quickstart app here.

FirebaseAuth gives Null pointer exception

I'm trying to register a user in firebase. Here is my code:
App level gradle:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.firebase:firebase-core:11.6.2'
compile 'com.google.firebase:firebase-auth:11.6.2'
}
Project level gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1' // google-services plugin
My code for register user:
private void registerUser(String name,String email,String password) {
pBar.setVisibility(View.VISIBLE);
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(getApplicationContext(),"User Created. Please login.",Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(),task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
pBar.setVisibility(View.GONE);
}
});
}
Here is the exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)' on a null object reference
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.createUserWithEmailAndPassword(Unknown Source)
at com.banik.helloworld.SignUpActivity.registerUser(SignUpActivity.java:73)
at com.banik.helloworld.SignUpActivity.onClick(SignUpActivity.java:68)
I have initialized mAuth in oncreate method of the activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
mAuth = FirebaseAuth.getInstance();
name = findViewById(R.id.name);
email = findViewById(R.id.email);
mobileNumber = findViewById(R.id.mobilenumber);
password = findViewById(R.id.password);
signUpBtn = findViewById(R.id.signup);
signUpBtn.setOnClickListener(this);
pBar = findViewById(R.id.signupBar);
}
Please help me.......
You must have Google Play Services installed on your phone or emulator.
If you are testing it on the Emulator.
Try testing it on a real device or make sure you have GPS installed on your emulator and provides a correct longitude and latitude

Categories

Resources