Firebase dependency in Android Library: Cannot invoke method get() on null object

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Firebase dependency in Android Library: Cannot invoke method get() on null object



I'm experiencing a build issue when adding a firebase dependency to a android library.



My setup is as follows



/settings.gradle


include ':module-lib'
include ':module-app'



/build.gradle


buildscript
dependencies
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:4.0.0'




/module-lib/build.gradle


apply plugin: 'com.android.library'
android
...

dependencies
api "com.google.firebase:firebase-config:16.0.0"



/module-app/build.gradle


apply plugin: 'com.android.application'
android
...

dependencies
implementation project(':module-lib')

apply plugin: 'com.google.gms.google-services'



Short log:


$ ./gradlew clean build

Starting a Gradle Daemon, 1 busy and 2 stopped Daemons could not be reused, use --status for details

Parallel execution is an incubating feature.

> Configure project :module-app
Detected alwaysUpdateBuildId set to false while obfuscation is enabled. This may result in obfuscated stack traces in Crashlytics.
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

> Task :module-lib:compileDebugAidl FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Failed to notify dependency resolution listener.
> Cannot invoke method get() on null object
> Cannot invoke method get() on null object

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 18s
13 actionable tasks: 8 executed, 5 from cache



You can find the full stacktrace of the original error in this pastebin



The funny thing is that module-lib only contains a placeholder, empty and useless class. If I removed the firebase dependency from module-lib and move it to module-app, the build works fine.


module-lib


module-lib


module-app



I'm not using Android Studio, so this is a purely Gradle and/or plugin
and/or dependencies issue.



Also note that


./gradlew clean // Always succeds
./gradlew build // Sometimes works with above error
./gradlew clean build // Always fails with above error



This also happens with any firebase-* dependency included in a module that applies the library plugin com.android.library.


firebase-*


com.android.library



More environment info


$ ./gradlew -version

------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------

Build time: 2018-04-18 09:09:12 UTC
Revision: b9a962bf70638332300e7f810689cb2febbd4a6c

Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 1.8.0_162 (Oracle Corporation 25.162-b12)
OS: Mac OS X 10.13.4 x86_64



Any clues or tips are more than welcome :)



Thanks!





Did you manage to find a way around this?
– Nami Alejandro Salimi
Jun 8 at 5:23





No. Not yet. It looks like a race condition, as from the command line sometimes works and sometimes doesn't. It always fails in Android Studio though.
– Robert Estivill
Jun 8 at 9:00





@NamiAlejandroSalimi check the answer. Updating the plugin to 4.0.1 solved the issue.
– Robert Estivill
Jun 19 at 15:06




1 Answer
1



Upgrading the google-services plugin to version 4.0.1 fixed the issue.


google-services


4.0.1



From the Firebase sdk changelog page: https://firebase.google.com/support/release-notes/android



enter image description here



In other words, change this:


classpath 'com.google.gms:google-services:4.0.0'



to this:


classpath 'com.google.gms:google-services:4.0.1'





I'm seeing this error with classpath 'com.google.gms:google-services:4.1.0'
– SimpleJ
Sep 5 at 20:31


classpath 'com.google.gms:google-services:4.1.0'





Downgrade to 4.0.1 and give it a try. There might be a regression bug.
– Robert Estivill
Sep 6 at 7:52





Thanks for tip!
– nicolascanto
Sep 10 at 18:05






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered