【问题标题】:Android - Firebase integration: CORRECT google-services.json but WRONG firebase urlAndroid - Firebase 集成:正确的 google-services.json 但错误的 firebase url
【发布时间】:2016-10-17 03:35:17
【问题描述】:

我一直在尝试将我的 Android 应用与 Firebase 集成。在我的第一个 Firebase 应用程序 (test-26ee4) 中,我错误地设置了应用程序,因为我被拒绝了权限...

读完这篇文章 (Firebase Database Permission denied with read/write permissions set to true) 后,我删除了 (test-26ee4) 并创建了一个新的 Firebase 应用程序 (awesome-etc)。但是,我注意到我遇到了同样的错误。

在 MainActivity.java 中放置日志后,

mDatabase = FirebaseDatabase.getInstance().getReference();
Log.d("testing", mDatabase.child("1").toString());

我发现引用仍然指向我的旧 firebase 应用。

10-16 12:00:06.882 14428-14428/com.example.twu.line D/testing: https://test-26ee4.firebaseio.com/1

google-services.json 反映了 url 应该很棒等等,但我不知道为什么我的 Android 应用程序从 google-services.json 读取不正确。

【问题讨论】:

    标签: android firebase firebase-realtime-database google-play-services


    【解决方案1】:

    您是否阅读过 Google 服务 json 中的内容?它指定了android项目的包名。

        {
      "project_info": {
        "project_number": "xxxxx",
        "firebase_url": "https://xx-zzzzz.firebaseio.com",
        "project_id": "nxjwjx-7f23b",
        "storage_bucket": "dkwncn-7f23b.appspot.com"
      },
      "client": [
        {
          "client_info": {
            "mobilesdk_app_id": "1jjsjwkd:xjdjejfb:sjwjsj",
            "android_client_info": {
              "package_name": "com.xxxxx.schwjxns"
            }
          },
          "oauth_client": [
            {
              "client_id": "xxxxxx.apps.googleusercontent.com",
              "client_type": 1,
              "android_info": {
                "package_name": "com.nixho.scheduled",
                "certificate_hash": "xxxx"
              }
            },
            {
              "client_id": "zxxxent.com",
              "client_type": 1,
              "android_info": {
                "package_name": "com.blah",
                "certificate_hash": "xxxxx"
              }
            },
            {
              "client_id": "xxxx.apps.googleusercontent.com",
              "client_type": 3
            }
          ],
          "api_key": [
            {
              "current_key": "xxxx"
            }
          ],
          "services": {
            "analytics_service": {
              "status": 1
            },
            "appinvite_service": {
              "status": 2,
              "other_platform_oauth_client": [
                {
                  "client_id": "xxxx.apps.googleusercontent.com",
                  "client_type": 3
                }
              ]
            },
            "ads_service": {
              "status": 2
            }
          }
        }
      ],
      "configuration_version": "1"
    }
    

    我建议替换 json,因为它特定于您创建的每个项目,否则您将无法让 firebase 正常工作

    编辑

    **public static DatabaseReference rootRef = FirebaseDatabase.getInstance().getReferenceFromUrl("https://myapp.firebaseio.com/"); // 我们必须使用新的 Firebase 3.0 API **

    这很重要

    【讨论】:

    • 嘿 Nicolas,当我创建一个新的 Firebase 应用程序(真棒等)时,我完全删除了旧的 google-services.json 并将一个新的 google-services.json 添加到 app/ 目录中跨度>
    • 只需按照我添加的新内容!如果有任何问题,请告诉我
    • java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.twu.line/com.example.twu.line.MainActivity}:com.google.firebase.database.DatabaseException:无效URL (awesome-etc.firebaseio.com) 传递给 getReference()。 URL 应与配置的数据库 URL 匹配:test-26ee4.firebaseio.com
    • 有趣...我觉得我们越来越接近这个问题了。
    • 你在 gradle 文件中添加了正确的包
    猜你喜欢
    • 2022-06-18
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 1970-01-01
    • 2021-04-02
    • 2019-06-29
    • 2018-04-12
    相关资源
    最近更新 更多