数据库= FirebaseDatabase.getInstance();错误

时间:2018-07-20 12:42:13

标签: android firebase-realtime-database

我想用Firebase创建一个应用程序,但是当我打开应用程序时它就停止了。

这些是我的依赖;

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:10.2.0'
implementation 'com.google.firebase:firebase-database:10.2.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:cardview-v7:27.+'
implementation 'com.android.support:design:27.+'
implementation 'com.android.support:appcompat-v7:27.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:16.0.0'
}

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

这是我的主要活动

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

database = FirebaseDatabase.getInstance();
users = database.getReference("Users");

edtUser=(MaterialEditText)findViewById(R.id.edtUser);
edtPassword=(MaterialEditText)findViewById(R.id.edtPassword);

当应用崩溃时,我看起来像logcat并说

数据库= FirebaseDatabase.getInstance();错误行

我该如何解决?你能帮我吗?

崩溃日志

  

java.lang.NoSuchMethodError:类Lcom / google / firebase / FirebaseApp中没有虚拟方法zzUU()Z;或其上级类(“ com.google.firebase.FirebaseApp”的声明出现在/data/app/com.example.cagri.kpssgenelkltrtesti-2/split_lib_dependencies_apk.apk中)           位于com.google.firebase.database.FirebaseDatabase.getInstance(未知来源)           位于com.google.firebase.database.FirebaseDatabase.getInstance(未知来源)           在com.example.cagri.kpssgenelkltrtesti.MainActivity.onCreate(MainActivity.java:35)           在android.app.Activity.performCreate(Activity.java:6237)           在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)           在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)           在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)           在android.app.ActivityThread.-wrap11(ActivityThread.java)           在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1344)           在android.os.Handler.dispatchMessage(Handler.java:102)           在android.os.Looper.loop(Looper.java:148)           在android.app.ActivityThread.main(ActivityThread.java:5417)           在java.lang.reflect.Method.invoke(本机方法)           在      com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)   07-20 12:30:25.004 8100-8145 / com.example.cagri.kpssgenelkltrtesti E / FirebaseInstanceId:令牌检索失败:SERVICE_NOT_AVAILABLE   07-20 12:30:37.529 8100-8100 / com.example.cagri.kpssgenelkltrtesti I / Process:正在发送信号。 PID:8100 SIG:9

1 个答案:

答案 0 :(得分:0)

您在项目中混合了Firebase SDK的不兼容版本。确保所有版本均为<16或所有版本均> =16。例如

implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:cardview-v7:27.+'
implementation 'com.android.support:design:27.+'
implementation 'com.android.support:appcompat-v7:27.+'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

遇到此类问题时,建议您检查Firebase documentation on getting started on Android