7

I have an app that is modularized to support instant-apps.

App modules:

  • app
  • instantapp
  • base
  • main
  • detail
  • search

I tried to add Firebase by adding:

  • classpath 'com.google.gms:google-services:3.1.1' → to the Project Level build.gradle
  • api "com.google.firebase:firebase-core:${versions.firebase}" → to the Base Module
  • apply plugin: 'com.google.gms.google-services' → to the bottom of the Base Module
  • google-services.json → to the base module folder

When I run the non-instant app I receive the following errors:

I/FirebaseInitProvider: FirebaseApp initialization unsuccessful

E/FA: GoogleService failed to initialize, status: 10, Missing google app id value from from string resources with name google_app_id.

I/FA: App measurement is starting up, version: 11720

I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE

I/FA: To enable faster debug mode event logging run: adb shell setprop debug.firebase.analytics.app com.punpuf.chacaraselazer.app

E/FA: Missing google_app_id. Firebase Analytics disabled. See https://goo(...)

E/FA: Uploading is not possible. App measurement disabled

I/FA: Tag Manager is not found and thus will not be used

And when I run the instant app I receive the following error:

V/FA: Cancelling job. JobID: 1799580119

E/FirebaseApp: Firebase API initialization failure. (...) Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void android.app.job.IJobScheduler.cancel(int)' on a null object reference

I/FirebaseInitProvider: FirebaseApp initialization successful

If I add the following line: "FirebaseAnalytics.getInstance(this)", not only does it receive the previous errors, it also crashes:

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.punpuf.chacaraselazer.app, PID: 11273 java.lang.RuntimeException: Unable to start activity ComponentInfo{(...)}: java.lang.NullPointerException: Attempt to invoke interface method 'void android.app.job.IJobScheduler.cancel(int)' on a null object reference

So my question is how can I get Firebase Analytics to work, and not crash on both my instant and non-instant version of my app.

Although this question is a bit similar to FirebaseApp initialization unsuccessful in Android Instant apps , mine not contain the same type of errors.

Update: I've created a new Firebase Project, and updated my google-services.json, but still didn't work.

Here are my gradle files:

I've also tried replacing firebase analytics dependency with firebase messaging and I still received the "FirebaseApp initialization unsuccessful" error.

Prags
  • 2,457
  • 2
  • 21
  • 38
Punpuf
  • 2,042
  • 1
  • 19
  • 30
  • A sample for Firebase Analytics in combination with Android Instant Apps is [available on GitHub](https://github.com/googlesamples/android-instant-apps/tree/master/analytics) – Ben Weiss Nov 30 '17 at 15:07
  • I've already seen it, I've also compared my gradle files with theirs to check if I had made any mistakes. – Punpuf Nov 30 '17 at 15:09
  • just use firebase assistant, go to Tools>Firebase>connect to firebase and it will add the dependencies of firebase in the gradle – Peter Haddad Nov 30 '17 at 15:35
  • I had already tried that – Punpuf Nov 30 '17 at 17:30
  • @Marcola can you share sample project to understand clearly your concern if still have issues. – Prags Dec 03 '17 at 03:53
  • I can't tell what Firebase version you are using, is it updated to 11.6.2? https://firebase.google.com/support/releases – TWL Dec 04 '17 at 18:40
  • Also, this could also be an issue of an outdated `Google Play Services for Instant Apps` Uninstall it and then run an instant app to make sure the latest version gets installed. – TWL Dec 04 '17 at 18:41
  • 1
    If it still doesn't work and fede1608's solution also doesn't work, then I would suggest you to submit your project to Google's https://issuetracker.google.com/issues/new?component=316045&template=1018787 They will take a look at it. (also, please be sure to provide here the link to that filed bug) – TWL Dec 04 '17 at 18:42

1 Answers1

8

I've had the same problem, I solved it adding the google-services.json to both base and app module and applying the google services plugin in both build.gradle files

fede1608
  • 2,808
  • 1
  • 16
  • 17
  • 1
    Thank you!! For other people experiencing this issue, you may also have to edit your app module google-services.json file's "package_name" inside "client_info" to the package name of your app module – Punpuf Dec 04 '17 at 19:42
  • @fede1608 I followed the same steps but I am getting StackOverflowError at GoogleServicesPlugin.getAllDependencies ERROR Log: https://justpaste.it/1hhfv Any suggestion – Ajit Feb 23 '18 at 10:47
  • @Ajit Sorry no idea, It seems that there is a loop somewhere, maybe you are linking both build gradle to each other? – fede1608 Feb 23 '18 at 10:51
  • 1
    @fede1608 This issue occur when apply plugin: 'com.google.gms.google-services' to base module – Ajit Feb 23 '18 at 11:17
  • @Ajit Can you share both build.gradle? – fede1608 Feb 23 '18 at 11:31
  • This solution works however I find it odd to have to copy configuration for Firebase with Instant Apps. I'd rather prefer a solution where there's only one google-services.json. – Sven Jacobs Apr 09 '18 at 10:07