Firebase例外在FirebaseApp中指定DatabaseURL

时间:2017-12-09 16:59:12

标签: android database firebase firebase-realtime-database

当我打电话时,应用程序崩溃了

FirebaseDatabase database = FirebaseDatabase.getInstance();

日志

 com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
 at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
 at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)

Firebase项目配置正确。 Authentication无问题,但无法连接到firebase

这是我的应用级gradle.build文件

的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' 

项目级别 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'
    }
}

FirebaseDatabase.class

中将发生 DatabaseException
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 {
...
}

11 个答案:

答案 0 :(得分:14)

如果有人在 2021 年遇到这个问题,那么只需按照以下步骤操作:- 在 build.gradle/app 中添加这些依赖

unfinishedTodos.forEach((each, index) => {
 firebaseApp.firestore().collection("todos").doc(each.id).update({
   index: index})
});

然后使用数据库引用对象

  implementation platform('com.google.firebase:firebase-bom:26.3.0')
implementation 'com.google.firebase:firebase-database-ktx'

仍然困惑,请在此处阅读此文档1

答案 1 :(得分:11)

这就是我为 iOS 项目所做的。

在我下载 GoogleService-Info.plist 文件并将其添加到我的项目后,我一直崩溃

<块引用>

无法获取 FirebaseDatabase 实例:在其中指定 DatabaseURL FIRApp 或从您的 databaseForApp:URL: 调用。

在谷歌搜索并没有找到具体答案后,我查看了我拥有的另一个项目中的 GoogleService-info.plist 文件,但 DATABASE_URL 键丢失了

您只需简单的 3 个步骤:

1- 打开你的谷歌 GoogleService-info.plist

2- 将 DATABASE_URL 键输入回文件

enter image description here

3- 转到您的 Firebase 控制台 > RealtimeDatabase > 从那里复制并粘贴或输入 https//... url string 作为 DATABASE_URL 文件中 .plist 键的值

enter image description here

一定要加上https//:部分(从图片上看可能不明显)

答案 2 :(得分:8)

我再次下载了 <TouchSensor DEF="TOUCH_SENSOR_node1" enabled="true"></TouchSensor> 文件,因为我刚刚添加了实时数据库。

你的文件应该有

google-services.json

答案 3 :(得分:3)

只需在 getInstance() 中添加您的 firebase 网址

FirebaseDatabase database = FirebaseDatabase.getInstance("YOUR FIREBASE URL HERE");

这对我有用。

答案 4 :(得分:1)

您可以转到Firebase控制台:  1 - 选择您的项目。 2-From&#34;实时数据库&#34;点击左侧菜单转到&#34;数据&#34;选项卡,在这里您可以轻松访问所需的数据库URL,您可以在第一行找到它,然后请使用以下代码行:

DatabaseRefernce mdatabaseref = FirebaseDatabase.getInstance()。getReferenceFromUrl(url);.

你们都已经准备好了。 for example you can find the URL in this picture underlined by red

请看一下: Assign a firebase database url(String) to a Database Reference variable?

答案 5 :(得分:1)

在 build.gradle(modular) 中升级以下实现包的版本。

dependencies {

    //noinspection GradleDependency
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.google.firebase:firebase-database:19.6.0'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

答案 6 :(得分:1)

enter image description here

在科特林 从此处复制您的数据库网址,然后将此网址粘贴到您的代码中。

refUsers = FirebaseDatabase.getInstance("https://tictic-97910.firebaseio.com/").reference.child("Users").child(firebaseUserId)

答案 7 :(得分:1)

在 AndroidManifest.xml 中将您的构建依赖项升级到 19.7.0

    implementation 'com.google.firebase:firebase-database:19.7.0'

Android Studio -> Tools -> Firebase 中的默认设置使用了导致此问题的旧版本。

答案 8 :(得分:0)

<key>DATABASE_URL</key>
    <string>https://appName-bgbtty-default-bblebut.firebaseio.com</string>

转到 google service 作为源代码打开,然后将其插入到 google api id(底部)下方

答案 9 :(得分:-1)

google-services.json
"project_info": { "firebase_url":""<- 这是您的实时数据库 url` }

答案 10 :(得分:-1)

这是您的 Google p.list 的问题。启用 Firebase 数据库后,只需从 Firebase 信息中心/项目设置重新下载即可。