我在Android和Firebase上做了这个教程,但由于某些原因,当我尝试注册新的驱动程序时,它根本不与Firebase交互。虽然它确实显示它已连接到Firebase:
由于此错误,我已将API降级为26:
Google Play服务已过期。需要9256000但找到9080470。
所以我按照此平台上的贡献者的建议安装了Genymotion来解决这个问题。
但它仍然无法与Firebase通信。它返回0错误,但不起作用。
我安装了GenyMotion,但每次尝试在设备上运行时都会崩溃。
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);
}
}
这是我的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
}
这是我尝试在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)
我是学习者,感谢任何帮助。
答案 0 :(得分:3)
我得到了同样的错误,因为我使用了模拟器.. 但是当我在一个真实的设备中尝试它时,它工作得很好.. 希望它也适合你..
答案 1 :(得分:1)
使用这些依赖项为我工作:
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'
}
感谢您的帮助。
答案 2 :(得分:0)
使用'com.google.firebase:firebase-auth:11.6.0'
更改为'com.google.firebase:firebase-auth:11.2.0'
`
尝试此依赖项:
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'
答案 3 :(得分:0)
在我的项目中遇到了同样的问题,但我在 Android Studio 3.0.1
中使用了这个问题应用/的build.gradle 强>
compile "com.google.firebase:firebase-auth:9.0.2"
build.gradle(根目录)
classpath 'com.google.gms:google-services:3.0.0'
为我设定工作
答案 4 :(得分:0)
看https://github.com/firebase/FirebaseUI-Android/issues/1104。我认为这是SDK中的一个公认问题,将在下一个或两个SDK更新中解决。名为Samstern的github用户发布了这个 -
此错误的修复程序已在内部提交,因此应该这样做 修复了下一个1-2 Firebase Auth SDK版本,具体取决于 发布周期。
我将在这里关闭这个问题,因为没有更多 FIrebaseUI可以做,谢谢所有报道它的人!
尽管如此,请尝试以下操作,看看它是否有效。要重复Bob Snyder所说的内容 - 从依赖项块中删除此行:实现'com.google.gms:google-services:3.1.0'。将firebase升级到11.8.0。所以你的应用程序的build.gradle看起来应该是这样的。
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'
让我知道这是怎么回事。
答案 5 :(得分:0)
我通过在模拟器中升级Google Play服务来解决这个问题。没有必要在gradle中改变任何东西。
答案 6 :(得分:0)
对我来说,作品从编译改变:
com.google.firebase:firebase-auth:11.8.0
编译:
com.google.firebase:firebase-auth:11.2.0