Android客户端FirebaseApp初始化错误

编程入门 行业动态 更新时间:2024-10-10 21:27:47
本文介绍了Android客户端FirebaseApp初始化错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经实施了GCM,现在正尝试将GCM导入FCM.我不想使用google-services.json,因为我想在不同的环境(Dev,Stag,Prod)中使用不同的google项目.

I had GCM implemented and I am trying to import GCM to FCM now. I dont want to use google-services.json because I want to use different google projects for different environments(Dev, Stag, Prod).

我试图通过下面的这段代码初始化应用程序

I tried to initialize the app via this code below

FirebaseOptions.Builder options=new FirebaseOptions.Builder(); options.setGcmSenderId("<<project id>>"); options.setApplicationId("<<Project name>>"); FirebaseApp firebaseApp = FirebaseApp.initializeApp(getApplicationContext(),options.build(),"MyTestFCM"); String refreshedToken= FirebaseInstanceId.getInstance(firebaseApp).getToken();

我在Firebase App初始化过程中一直遇到异常情况

I keep getting exception on Firebase App initialization

原因:java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp不存在.可用的应用程序名称:MyTestFCM

Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. Available app names: MyTestFCM

如果我删除应用程序名称,那么我将不会获得令牌,然后当我重新运行应用程序时,我将获得令牌.我试图从Mainactivity和Application类执行以上代码.在两个地方,我得到相同的错误.

If I remove the app name then i dont get a token back, then when I re-run the application I get a token. I have tried to execute the above piece of code from Mainactivity and Application class. In both places I get the same error.

所以我的问题是如何在不使用google-services.json的情况下初始化Firebase应用程序

So my question is how do I initialize Firebase application without using google-services.json

谢谢, P

推荐答案

因此,您需要将google-services.json用于FCM,并处理多种构建变体情况,

So turns out that you need to use google-services.json for FCM, and to handle multiple build variants situation,

  • 从firebase控制台分别为不同的构建变体生成google-services.json.
  • 下载google-services.json
  • 在您的项目中,为变体创建文件夹,例如,如果要发布版本,请创建一个名称为"release"的文件夹,并将google-services.json放入其中.
  • 在构建应用程序时,根据构建版本的不同,它会在相应文件夹中查找google-services.json并从中获取项目详细信息.

    When the app builds, depending upon the build variant it looks for google-services.json in the respective folder and picks up the project details from it.

    可以在此线程上找到更多详细信息 Google服务问题54

    More details can be found on this thread google services issues 54

    感谢亚瑟·汤普森

    更多推荐

    Android客户端FirebaseApp初始化错误

    本文发布于:2023-11-16 14:48:45,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1605253.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:初始化   客户端   错误   Android   FirebaseApp

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!