我正在尝试将Firebase用于简单的CRUD android应用程序,但是在实例化Firebase数据库引用时,在运行时遇到以下异常:
java.lang.RuntimeException: Uncaught exception in Firebase Database runloop (3.0.0). Please report to firebase-database-client@google.com
at com.google.firebase.database.android.AndroidPlatform$1$1.run(com.google.firebase:firebase-database@@16.1.0:98)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
....
....
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/FirebaseApp$IdTokenListener;
....
....
at com.satwick.employeecrud.MainActivity.onCreate(MainActivity.java:76)
我经历了StackOverflow,尽管在Firebase中有很多NoClassDefFoundError的情况,但都与IdTokenListener
不相关。我主要意识到的是,这可能是在设置Firebase数据库时缺少某些步骤的错误。因此,我重新检查了所有步骤:
在onCreate()方法中:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
if (mFirebaseUser == null) {
List<AuthUI.IdpConfig> providers = Arrays.asList(new AuthUI.IdpConfig.PhoneBuilder().build());
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);
} else {
mUsername = mFirebaseUser.getDisplayName();
}
// MainActivity.java:76 The following line causes the exception.
mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
}
这是Firebase的错误吗?还是我做错了什么? 请帮忙。
此外,我不知道这是否相关,但是我有两个使用相同签名密钥(Android Studio的默认SHA1)注册到同一Firebase项目的应用程序。
编辑1- 添加build.gradle的依赖项{}:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha07'
// Google
implementation 'com.google.android.gms:play-services-auth:16.0.1'
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation platform('com.google.firebase:firebase-bom:17.0.0')
implementation 'com.google.firebase:firebase-database'
implementation 'com.google.firebase:firebase-storage'
implementation 'com.google.firebase:firebase-auth:17.0.0'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
// Firebase UI
implementation 'com.firebaseui:firebase-ui-database:3.3.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
答案 0 :(得分:1)
我在build.gradle
中使用了一些不需要的库,因此清除了Firebase的以下导入的混乱情况:
// Firebase
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-auth:17.0.0'
// Firebase UI
implementation 'com.firebaseui:firebase-ui-auth:5.0.0'
implementation 'com.firebaseui:firebase-ui-database:5.0.0'
因此,我尝试从4.3.1-> 5.0.0更新firebase-ui的版本,并且有效。
答案 1 :(得分:0)
我尝试从
实现'com.firebaseui:firebase-ui-auth: 4.3.1 '
到
实施'com.firebaseui:firebase-ui-auth: 4.3.0 '
和
实现'com.google.firebase:firebase-database: 19.2.0 '
到
实施'com.google.firebase:firebase-database: 16.0.4 '
成功了