0

I am attempting to write an app for android that uses Firebase Authentication via Email/Password. It is enabled. However the tutorial, and the code in Github for the examples are showing:

private FirebaseAuth mAuth;

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.firebase:firebase-core:9.0.2'



}


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

However, I get an error as if the "FirebaseAuth" doesn't exist. However the latest documentation says otherwise.

Github sample code

enter image description here

Any help would be greatly appreciated.

0

2 Answers 2

2

Replace the com.google.firebase:firebase-core:9.0.2' dependency with the com.google.firebase:firebase-auth:9.0.2 dependency. So:

compile 'com.google.firebase:firebase-auth:9.0.2'

instead of

compile 'com.google.firebase:firebase-core:9.0.2' under your dependencies.

I did not find the FirebaseAuth class in the core dependency but I did find it in the auth dependency. Furthermore, if you checkout their dependencies list, they do not add the core dependency, they add the auth dependency instead.

Sign up to request clarification or add additional context in comments.

6 Comments

Aren't they all the same thing? I'm a little confused on the dependencies. Using Firebase SDK 3.0
No, they aren't the same. Dependencies are just external libraries for you to use, nothing more than that. As to why they have more than one, well if they packaged all of the different types in one, it would be huge. One way to measure the footprint of a dependency is by method count and the higher the method count, the higher startup cost and APK size for your app. So they are kept separate.
Wow. My apologies. I missed the auth/core difference. Thank you. I will try that, that will most likely solve my issue. I will get back, and if it works I'll accept your answer.
It's also worth clarifying that it is up to the maintainer(s) of the library to decide how to split it up. If I remember correctly, there are some libraries where you have the option to compile the entire library as a dependency or just a part of it. I haven't used Firebase extensively but it seems like there is no overlap or if there is overlap, it doesn't satisfy your needs in this case.
This has worked, and I greatly appreciate your constructive feedback. This has really helped me understand dependencies a bit better.
|
0

According to documentation in the firebase web page you should create a Firebase object using the URL from your firebase and from there create usernames with passwords or log them in. The code you showed used this FirebaseAuth for that.

Here is the code to create a new user:

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.createUser("[email protected]", "correcthorsebatterystaple", new Firebase.ValueResultHandler<Map<String, Object>>() {
    @Override
    public void onSuccess(Map<String, Object> result) {
        System.out.println("Successfully created user account with uid: " + result.get("uid"));
    }
    @Override
    public void onError(FirebaseError firebaseError) {
        // there was an error
    }
});

Here is the code to log him in:

Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithPassword("[email protected]", "correcthorsebatterystaple", new Firebase.AuthResultHandler() {
    @Override
    public void onAuthenticated(AuthData authData) {
        System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
    }
    @Override
    public void onAuthenticationError(FirebaseError firebaseError) {
        // there was an error
    }
});

Got all of this info from the quick start guide here: https://www.firebase.com/docs/android/guide/login/password.html#section-logging-in

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.