Firebase Analytics not working with Instant App or

2019-02-17 12:34发布

问题:

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:

  • project: https://gist.github.com/Punpuf/8582fa3610a1c3dea13627e1207a6064
  • app: https://gist.github.com/Punpuf/2104ffe0c90927cb79944860a7cb6c46
  • instantapp: https://gist.github.com/Punpuf/233d96e91293a2a14e8fdf50092edd2d
  • base: https://gist.github.com/Punpuf/e1646f67d8a6094773c390d2df209eae
  • main: https://gist.github.com/Punpuf/f8bdd8789b11d274afdb1c51f490ed25
  • detail: https://gist.github.com/Punpuf/0a4f87b4fb512557ffe6cd110ce667de
  • search: https://gist.github.com/Punpuf/455e28b38baad23294dda6c9592586a2

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

回答1:

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