FirebaseApp初始化在Android Instant应用程序中失败 [英] FirebaseApp initialization unsuccessful in Android Instant apps

查看:214
本文介绍了FirebaseApp初始化在Android Instant应用程序中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在处理现有的Android应用程序,以创建Instant Apps版本.

I am currently working on an exiting Android application in order to create an Instant apps version.

我的Android Studio现在分为几个模块:

My Android Studio is now split into several modules :

  • 业务对象模块(它是一个库)
  • 基本-功能-模块
  • moduleA -feature-模块
  • 应用程序模块(电话/平板电脑模块)
  • 即时模块(这是即时应用模块)

我的即时应用程序模块可以在手机/平板电脑上编译并启动,但是每次由于Firebase问题而崩溃时,都可以使用.我在logcat中有以下消息:

My instant app module can be compiled and launched on a phone/tablet but each time it crashes due to Firebase issues. I have the following message into the logcat :

I/FirebaseInitProvider:FirebaseApp初始化失败

I/FirebaseInitProvider: FirebaseApp initialization unsuccessful

根据文档,Firebase库与Instant Apps,但我很确定我不会将google-services.json文件移动到项目中的正确位置...

According to the documentation the Firebase library is compatible with Instant Apps, but I am pretty sure that I do not move the google-services.json file into the right place in my project...

这是我所做的:

  1. 我在Android Studio项目的build.gradle文件中定义了以下类路径依赖项:classpath'com.google.gms:google-services:3.1.1'

  1. I defined the following classpath dependencies into the build.gradle file of the Android Studio project : classpath 'com.google.gms:google-services:3.1.1'

我将google-services.json文件放入我的模块库中(因为文档要求这样做)

I put the google-services.json file into my module base (because the documentation asks for it)

现在,如果我尝试将插件(应用插件:"com.google.gms.google-services")应用到基本模块的build.gradle文件中,则无法编译.我收到以下消息:

Now, if I try to apply the plugin (apply plugin: 'com.google.gms.google-services') into the build.gradle file of the base module, I cannot compile. I have the following message :

错误:任务':base:processGooglePlayProductionDebugFeatureGoogleServices'的执行失败.

Error:Execution failed for task ':base:processGooglePlayProductionDebugFeatureGoogleServices'.

>找不到与包名称'com.mycompany.myapp.base'匹配的客户端

> No matching client found for package name 'com.mycompany.myapp.base'

实际上,定义在google-services.json文件中的软件包名称是应用程序使用的软件包名称(因为根据

In fact, the package name defined into the google-services.json file is the one use by the app (because according to the documentation the base library cannot have the same package name as the installed android app.

我还尝试将插件应用到已安装应用程序的build.gradle文件和即时应用程序模块中,而将google-services.json文件应用到基本模块中.该应用程序已编译,但我有日志:"FirebaseApp初始化失败".

I also tried to apply the plugin into the build.gradle files of the installed app and into the instant apps module leaving the google-services.json file into the base module. The app compile but I have the log : "FirebaseApp initialization unsuccessful".

所以我尝试将google-services.json文件移到我的即时应用程序模块中,但仍然有日志:"FirebaseApp初始化失败"

So I tried moving the google-services.json file into my instant app module but I still have the log : "FirebaseApp initialization unsuccessful"

我还尝试强制从FirebaseApp类调用静态方法initializeApp的初始化,但是日志仍然存在.

I also tried to force the initialization calling the static method initializeApp from the FirebaseApp class but the log persists.

我在网络上找不到实现的示例.实际上, Google示例存储库不使用google-services.json文件.

I cannot find an example of implementation on the web. In fact, the Google Sample repository does not use a google-services.json file.

在此先感谢您的帮助!

这里是我模块的依赖项:

Edit : Here the dependencies of my modules :

我的基本-feature-模块的依赖项:

The dependencies of my base -feature- module :

  implementation project(':businessobject')
  feature project(':moduleA')
  application project(':app')

我的模块的依赖项-feature-模块:

The dependencies of my moduleA -feature- module :

api project(':base')
api project(':businessobject')

我的应用程序模块(电话/平板电脑模块)的依赖项:

The dependencies of my app module (which is a phone/tablet module) :

implementation (project(':base'))
implementation (project(':businessobject'))
implementation (project(':moduleA'))

我的即时模块(即时应用模块)的依赖项:

The dependencies of my instant module (which is an instant apps module) :

implementation project(':base')
implementation project(':businessobject')
implementation project(':moduleA')

推荐答案

因为根据文档,基础库不能具有 与已安装的android应用相同的软件包名称.

because according to the documentation the base library cannot have the same package name as the installed android app.

我认为文档有点过时了.每个"功能"模块都需要使用不同的包名称,因为这就是生成 R类名称的方法. AFAIK没有理由不让"基本"功能使用与应用程序本身相同的程序包名称.

I think the documentation is a bit out of date. Each "feature" module needs to use a different package name, because that's what's used to generate the name of the R class. AFAIK there's no reason why you can't have the "base" feature use the same package name as the app itself.

似乎需要为"功能"插件更新" google-services "插件以使用应用程序ID AndroidManifest.xml中指定的名称(,稍后将被覆盖为与应用程序ID 相同).

It seems like the "google-services" plugin needs to be updated for the "feature" plugin to use the application ID rather than the name specified in AndroidManifest.xml (which will be overwritten later to be the same as the application ID).

tl; dr- –将软件包名称从" base "更改为" com.mycompany.myapp "应该可以正常工作.

tl;dr---changing the package name of "base" to "com.mycompany.myapp" should get things working.

这篇关于FirebaseApp初始化在Android Instant应用程序中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆