找不到com.google.firebase.auth的本地模块描述符类(Firebase身份验证)

时间:2016-11-07 07:35:38

标签: java android dynamic google-play-services firebase-authentication

我是使用Firebase的初学者。目前,我正在尝试执行Firebase身份验证并从Youtube(https://www.youtube.com/watch?v=oi-UAwiBigQ&index=9&list=PLGCjwl1RrtcTXrWuRTa59RyRmQ4OedWrt)学习它,但它显示了我

W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
W/GooglePlayServicesUtil: Google Play Store is missing.

这是我的代码 的AndroidManifest.xml

 <?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />

<application
    android:name=".FireApp"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".AccountActivity"></activity>
</application>

FireApp.java

package com.google.firebasetester;

import android.app.Application;

import com.firebase.client.Firebase;

public class FireApp extends Application {
    @Override
    public void onCreate() {
    super.onCreate();

    Firebase.setAndroidContext(this);
}
}

MainActivity.java

    package com.google.firebasetester;

import android.accounts.Account;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;

import java.util.ArrayList;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
private EditText mEmailField;
private EditText mPasswordField;

private Button mLoginBtn;

private FirebaseAuth mAuth;

private FirebaseAuth.AuthStateListener mAuthListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //FirebaseAuth setup
    mAuth=FirebaseAuth.getInstance();
    mEmailField = (EditText) findViewById(R.id.emailField);
    mPasswordField = (EditText) findViewById(R.id.passwordField);

    mLoginBtn = (Button) findViewById(R.id.loginBtn);
    mAuthListener =new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            //if equal to null means user have not login, cannot find any user
            //if(firebaseAuth.getCurrentUser()==null)

            //user has login
            if(firebaseAuth.getCurrentUser()!=null)
            {
                startActivity(new Intent(MainActivity.this, AccountActivity.class));
            }
        }
    };

    mLoginBtn.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View view) {

         //click when user click on login button
         startSignIn();
     }
    }
    );

}
@Override
protected void onStart()
{
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);
}
private void startSignIn()
{
    String email=mEmailField.getText().toString();
    String password=mPasswordField.getText().toString();

    //to make sure user not blank the field
    if(TextUtils.isEmpty(email)||TextUtils.isEmpty(password)) {
        Toast.makeText(MainActivity.this, "Fields are empty.", Toast.LENGTH_LONG).show();

    }
    else
    {
        mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                //user not successful login
                if (!task.isSuccessful()) {
                    Toast.makeText(MainActivity.this, "Sign in Problem", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}
}

AccountActivity.java

     package com.google.firebasetester;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class AccountActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account);
    }
}

activity_account.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_account"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.google.firebasetester.AccountActivity">
<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:text="Account"
    android:ems="10"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="184dp"
    android:id="@+id/editText" />
</RelativeLayout>

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.google.firebasetester.MainActivity"
    android:padding="20dp">

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:ems="10"
    android:layout_below="@+id/emailField"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="61dp"
    android:id="@+id/passwordField"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:hint="Password" />

<Button
    android:text="Login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/passwordField"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="110dp"
    android:layout_marginStart="110dp"
    android:layout_marginTop="31dp"
    android:id="@+id/loginBtn" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:ems="10"
    android:id="@+id/emailField"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:hint="Email" />
</RelativeLayout>

的build.gradle(项目:FirebaseTester)

 // 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'
        classpath 'com.google.gms:google-services:3.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

的build.gradle(模块:应用)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "com.google.firebasetester"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    packagingOptions {
        exclude 'META-INF/NOTICE' // will not include NOTICE file
        exclude 'META-INF/LICENSE' // will not include LICENSE file
        // as noted by @Vishnuvathsan you may also need to include
        // variations on the file name. It depends on your dependencies.
        // Some other common variations on notice and license file names
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.firebase:firebase-database:9.8.0'
    compile 'com.google.firebase:firebase-crash:9.8.0'
    compile 'com.google.firebase:firebase-auth:9.8.0'
    compile 'com.firebase:firebase-client-android:2.5.2'
    compile 'com.google.firebase:firebase-core:9.8.0'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

请帮我解决问题。谢谢!

0 个答案:

没有答案