我正在嘗試編寫同時使用FirebaseAuth和Firebase實時數據庫的程序。當我嘗試運行沒有數據庫的程序時,它運行的很完美,但是當我試圖包含數據庫時什麼都不起作用。我看到這個錯誤:無法添加Firebase數據庫與Firebase身份驗證
java.lang.NoSuchMethodError: No direct method (Landroid/content/Context;Lcom/google/android/gms/internal/zzbma$zza;)V in class Lcom/google/android/gms/internal/zzbls; or its super classes (declaration of 'com.google.android.gms.internal.zzbls' appears in /data/app/com.dezlum.www.appforbank-2/split_lib_dependencies_apk.apk:classes12.dex) at com.google.android.gms.internal.zzbma.zza(Unknown Source) at com.google.firebase.auth.FirebaseAuth.zzb(Unknown Source) at com.google.firebase.auth.FirebaseAuth.(Unknown Source) at com.google.android.gms.internal.zzbne.(Unknown Source) at com.google.firebase.auth.FirebaseAuth.zzd(Unknown Source) at com.google.firebase.auth.FirebaseAuth.zzc(Unknown Source) at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source) at com.dezlum.www.appforbank.MainActivity.onCreate(MainActivity.java:50) at android.app.Activity.performCreate(Activity.java:6317) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2543) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2682) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1512) at android.os.Handler.dispatchMessage(Handler.java:111) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5811) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)
這件事發生時,我包括在我gradle這個文件中的火力地堡數據庫的依賴。這是它看起來像現在: -
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:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:customtabs:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:10.0.1'
compile 'com.firebaseui:firebase-ui-auth:1.2.0'
compile 'com.google.firebase:firebase-database:10.0.1'
testCompile 'junit:junit:4.12'
}
當我刪除從我的應用程序就開始做工精細
這是我的MainActivity的外觀的依賴和火力地堡的數據庫,如: -
package com.dezlum.www.appforbank;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.ui.auth.AuthUI;
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 java.util.Arrays;
public class MainActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private String mUsername;
private static final String TAG = "MainActivity";
FirebaseUser user;
public static final String ANONYMOUS = "anonymous";
public static final int DEFAULT_MSG_LENGTH_LIMIT = 1000;
public static final int RC_SIGN_IN = 1;
public TextView chechker;
private Button signout;
SharedPreferences preferences;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mMessagesDatabaseReference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mUsername = ANONYMOUS;
preferences = getSharedPreferences("text",0);
chechker = (TextView) findViewById(R.id.textview1);
mAuth = FirebaseAuth.getInstance();
mFirebaseDatabase = FirebaseDatabase.getInstance();
mMessagesDatabaseReference = mFirebaseDatabase.getReference().child("USERS");
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
user = firebaseAuth.getCurrentUser();
if (user != null) {
// User is signed in
Toast.makeText(MainActivity.this, "You're now signed in. Welcome.", Toast.LENGTH_SHORT).show();
onSignedInInitialize(user.getDisplayName());
Log.d("TAG", "onAuthStateChanged:signed_in:" + user.getUid());
} else {
// User is signed out
onSignedOutCleanup();
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setIsSmartLockEnabled(false)
.setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build()))
.build(),
RC_SIGN_IN);
Log.d("TAG", "onAuthStateChanged:signed_out");
}
}
};
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
if (resultCode == RESULT_OK) {
// Sign-in succeeded, set up the UI
//Toast.makeText(this, "Signed in!", Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
// Sign in was canceled by the user, finish the activity
Toast.makeText(this, "Sign in canceled", Toast.LENGTH_SHORT).show();
finish();
}
}
}
@Override
protected void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(mAuthListener);
}
@Override
protected void onResume() {
super.onResume();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
protected void onPause() {
super.onPause();
if(mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
mAuth.signOut();
onSignedOutCleanup();
return super.onOptionsItemSelected(item);
}
private void onSignedInInitialize(String username) {
String Name = username;
if(!preferences.contains("pan")){
Intent extendedsignup = new Intent(MainActivity.this,ExtendedSignUp.class);
startActivity(extendedsignup);
}
//Database work here
chechker.setText(Name);
}
private void onSignedOutCleanup() {
mUsername = ANONYMOUS;
user = null;
}
}
我該怎麼辦?由於提前
檢查您的版本。對於Firebase SDK版本10.0.1,請使用FirebaseUI 1.1.1。 –
兼容版本表[是](https://github.com/firebase/FirebaseUI-Android#compatibility-with-firebase--google-play-services-libraries) –
另請參閱http://stackoverflow.com/questions/39782445 /我如何設置firebaseadapter-in-android-studio/39782653#39782653 –