3

I want to add Firebase authentication and Firebase cloud messaging to my app. After following the latest get started guide i cannot create a new user. I also considered this code example. I enabled in my Firebase console:

  • login with with email/password
  • and for test purposes anonymus login

OTUPUT:

D/EmailPassword: onAuthStateChanged:signed_out
D/EmailPassword: createAccount:mail
W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/GooglePlayServicesUtil: Google Play services out of date.  Requires 10084000 but found 9877470

I found similar questions but all the answers didn't helped me within my problem... I think it's just a small silly bug but I cannot resolve the problem.


My gradle file on app level looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    defaultConfig {
        applicationId "app.radiant.c.lly"
        minSdkVersion 17
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:appcompat-v7:24.2.1'
    //compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    compile 'com.google.android.gms:play-services:10.0.0'
    compile 'com.android.support:design:24.2.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:cardview-v7:24.2.1'

    // Firebase Dependencies
    compile 'com.google.firebase:firebase-core:10.0.0'
    compile 'com.google.firebase:firebase-auth:10.0.0'
    compile 'com.google.firebase:firebase-messaging:10.0.0'
}

// Firebase Plugin
apply plugin: 'com.google.gms.google-services'

My gradle file on project level looks like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // Added this line for Firebase
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I have an external DB where I store the logged in users. In Firebase I only want to store the email address from my DB with a default password. To do this I just created a button that should store the user on Firebase when it's pressed.

public class InboxFragment extends Fragment {

    View view;
    Activity callingActivity;
    Account account;
    ListView chats;
    Button btn;

    ArrayList<String> exampleContent = new ArrayList<>();
    ArrayAdapter<String> adapter;

    // Firebase instance variables
    private static final String TAG = "EmailPassword";
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener mAuthListener;
    String username;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_inbox, container, false);
        callingActivity = getActivity();
        account = (Account) callingActivity.getApplication();

        // Firebase
        // [START initialize_auth]
        mAuth = FirebaseAuth.getInstance();
        // [END initialize_auth]

        // [START auth_state_listener]
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                FirebaseUser user = firebaseAuth.getCurrentUser();
                if (user != null) {
                    // User is signed in
                    Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
                } else {
                    // User is signed out
                    Log.d(TAG, "onAuthStateChanged:signed_out");
                }
                // [START_EXCLUDE]
                //updateUI(user);
                // [END_EXCLUDE]
            }
        };
        // [END auth_state_listener]

        btn = (Button) view.findViewById(R.id.addUsernameBtn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                createAccount(account.getEmail(), "empty");
            }
        });

        // Code
        chats = (ListView) view.findViewById(R.id.userChatList);

        // Add example content to array
        exampleContent.add("Chat 1");
        exampleContent.add("Chat 2");
        //exampleContent.add(username);

        adapter = new ArrayAdapter<String>(callingActivity, android.R.layout.simple_list_item_1, exampleContent);
        chats.setAdapter(adapter);

        chats.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent i = new Intent(getActivity(), ChatActivity.class);
                startActivity(i);
            }
        });

        return view;
    }

    // [START on_start_add_listener]
    @Override
    public void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }
    // [END on_start_add_listener]

    // [START on_stop_remove_listener]
    @Override
    public void onStop() {
        super.onStop();
        if (mAuthListener != null) {
            mAuth.removeAuthStateListener(mAuthListener);
        }
    }
    // [END on_stop_remove_listener]

    private void createAccount(String email, String password) {
        Log.d(TAG, "createAccount:" + email);
        /*if (!validateForm()) {
            return;
        }*/

        //showProgressDialog();

        // [START create_user_with_email]
        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Log.e(TAG, "ERROR");
                            /*Toast.makeText(EmailPasswordActivity.this, R.string.auth_failed,
                                    Toast.LENGTH_SHORT).show();*/
                        }

                        // [START_EXCLUDE]
                        //hideProgressDialog();
                        // [END_EXCLUDE]
                    }
                });
        // [END create_user_with_email]
    }

}

But this doesn't work. I get the Output (see at the top of the question).

LenC
  • 69
  • 1
  • 10

1 Answers1

8

This is the problem:

W/GooglePlayServicesUtil: Google Play services out of date.  Requires 10084000 but found 9877470

If you running on an emulator, you will need to downgrade to version 9.8.0 or 9.6.1 of the Play Services and Firebase libraries, depending on the API level you are emulating. There is no released emulator image that supports version 10.0.0.

If you are running on a real device, you need to update your version of Google Play Services. The current version is 10.0.84. You can see the version installed on your phone by going to Settings > Application Manager > Google Play services.

This log message is not an indication of a problem. It seems to be output during normal operation:

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158
  • Downgrading to 9.8.0 and 9.6.1 doesn't work. I downgraded firebase-core/auth/messaging and google-services to the same API level. But for each level I get the same warning and no new user is created. I'll try to run it on an real device too as soon as possible. Should I publish more code? I really don't get it why i cannot create an user. – LenC Nov 22 '16 at 22:27
  • It's important to keep all the versions of the Firebase libs and Play Services consistent. Try making them all (including play-services) 9.6.1. That should make the warning go away. Also, change your emphatic log message on account creation failure to include the reason: `task.getException().getMessage()`. See this related answer: http://stackoverflow.com/a/39427322/4815718 – Bob Snyder Nov 22 '16 at 22:40
  • It's also not good practice to have a dependency on `compile 'com.google.android.gms:play-services:x.x.x'`. That pulls in ALL of the Play Services APIs, making you APK larger, increasing build time, and often requiring Multidex on pre-Lollipop devices. See this related answer: http://stackoverflow.com/a/40635422/4815718 – Bob Snyder Nov 22 '16 at 22:46
  • 1
    Thank you very much. Adding the task.getException().getMessage() helped. It was an incorrect form of the email that caused the problem and the password needs to be at least 6 chars long. I removed the compile 'com.google.android.gms:play-services:x.x.x' dependency aswell. Now it works :) – LenC Nov 23 '16 at 13:56