Vah*_*yan 10 database android firebase firebase-realtime-database
FirebaseApp 在 invoke 时抛出异常FirebaseDatabase.getInstance()。
错误信息
无法获取 FirebaseDatabase 实例:在 FirebaseApp 内或从您的 getInstance() 调用中指定 DatabaseURL。
Firebase项目配置正确。Authentication可以正常工作,但无法连接到firebase.
这是我的应用程序级别 gradle.build 文件
构建.gradle
dependencies {
.....
//Firebase database
implementation 'com.google.firebase:firebase-database:11.6.2'
// Firebase Invitation
implementation 'com.google.firebase:firebase-invites:11.6.2'
// Firebase Authentication
implementation 'com.google.firebase:firebase-auth:11.6.2'
// Google Sign In SDK (only required for Google Sign In)
implementation 'com.google.android.gms:play-services-auth:11.6.2'
// people api request libraries
implementation 'com.google.api-client:google-api-client:1.22.0'
implementation 'com.google.api-client:google-api-client-android:1.22.0'
implementation 'com.google.apis:google-api-services-people:v1-rev4-1.22.0'
compile project(':customsupport')
}
apply plugin: 'com.google.gms.google-services'
Run Code Online (Sandbox Code Playgroud)
和项目级别的build.gradle文件
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.2'
// We recommend changing it to the latest version from our changelog:
// https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
classpath 'io.fabric.tools:gradle:1.24.4'
}
}
Run Code Online (Sandbox Code Playgroud)
一个DatabaseException将发生在FirebaseDatabase.class
public static synchronized FirebaseDatabase getInstance(FirebaseApp var0, String var1) {
if(TextUtils.isEmpty(var1)) {
throw new DatabaseException("Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.");
} else {
...
}
Run Code Online (Sandbox Code Playgroud)
Man*_*ýãp 15
如果有人在 2021 年遇到这个问题,那么只需按照以下步骤操作:- 在 build.gradle/app 中添加这些依赖项
implementation platform('com.google.firebase:firebase-bom:26.3.0')
implementation 'com.google.firebase:firebase-database-ktx'
Run Code Online (Sandbox Code Playgroud)
然后使用数据库引用对象
databaseReference=Firebase.database.getReference("Users")
Run Code Online (Sandbox Code Playgroud)
仍然困惑然后在这里阅读此文档1
Lan*_*ria 11
这就是我为 iOS 项目所做的。
在我下载 GoogleService-Info.plist 文件并将其添加到我的项目后,我一直崩溃
无法获取 FirebaseDatabase 实例:在 FIRApp 内或从您的 databaseForApp:URL: 调用中指定 DatabaseURL。
在谷歌搜索并没有找到具体答案之后,我查看了GoogleService-info.plist我拥有的另一个项目中的文件,但DATABASE_URL密钥丢失了
您所要做的只是 3 个简单的步骤:
1-打开你的谷歌 GoogleService-info.plist
2-将DATABASE_URL密钥输入 回文件
3- 转到您的 Firebase 控制台 > RealtimeDatabase > 复制并粘贴或从那里输入https//...urlstring作为文件中DATABASE_URL键的值.plist
一定要加上https//:部分(从图片上看可能不明显)
我google-services.json再次下载了文件,因为我刚刚添加了实时数据库。
你的文件应该有
"project_info": {
"project_number": "123456789",
"firebase_url": "https://example.firebaseio.com",
"project_id": "example",
"storage_bucket": "example.appspot.com"
},
...
Run Code Online (Sandbox Code Playgroud)