Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseApp initialization unsuccessful in Android Instant apps

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

My Android Studio is now split into several modules :

  • the business object module (which is a library)
  • the base -feature- module
  • the moduleA -feature- module
  • the app module (which is a phone/tablet module)
  • the instant module (which is an instant apps module)

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 initialization unsuccessful

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...

Here what I have done :

  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'

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

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 :

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

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

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.

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".

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

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

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

Thank you in advance for your help !

Edit : Here the dependencies of my modules :

The dependencies of my base -feature- module :

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

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')
like image 637
rolandl Avatar asked Oct 10 '17 12:10

rolandl


1 Answers

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

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.

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---changing the package name of "base" to "com.mycompany.myapp" should get things working.

like image 100
dchai Avatar answered Nov 02 '22 23:11

dchai