我已经实施了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,
在构建应用程序时,根据构建版本的不同,它会在相应文件夹中查找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初始化错误
发布评论