5

I have a projects with number of modules, each one is a separate app. I added Firebase to one module, and since then another one's gradle cannot be sync. I keep getting: "Cannot invoke method get() on null object", which disappear when I comment out the play-service" dependencies. My gradle is:

buildscript {
    repositories {
        google()
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "xxxx"
        minSdkVersion 14
        targetSdkVersion 27

//        multiDexEnabled true

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

}

dependencies {
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true;
    }
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.google.android.gms:play-services-location:15.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
}

The top-level project gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

I use gradle version 4.4 and Android plugin version 3.1.3 The error's stack

java.lang.NullPointerException: Cannot invoke method get() on null object
    at
 org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
    at
 org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
    at
 org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at
 org.codehaus.groovy.runtime.callsite.NullCallSite.call(NullCallSite.java:35)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at
 org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at com.google.gms.googleservices.GoogleServicesPlugin$1$_afterResolve_closure1.doCall(GoogleServicesPlugin.groovy:316)
    at
 sun.reflect.GeneratedMethodAccessor357.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at
 java.lang.reflect.Method.invoke(Method.java:498)
    at
 org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at
 groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at
 org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at
 groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
    at
 groovy.lang.Closure.call(Closure.java:414)
    at
 groovy.lang.Closure.call(Closure.java:430)

(another 150 lines)

Any suggestion will help, Cheers.

ollaw
  • 2,086
  • 1
  • 20
  • 33
Eran Shay
  • 107
  • 1
  • 1
  • 8
  • possible duplicate of https://stackoverflow.com/questions/40106266/ – ReyAnthonyRenacia Jun 17 '18 at 23:29
  • @noogui I don't think it's the same, or at least the solution here is not the same, as I don't use the notation"plugins {" – Eran Shay Jun 18 '18 at 06:32
  • More observation: When I remove the module that use Firebase from settings.gradle the module that use google-play-service is build and compile with no problem. When I add the Firebase using module back, the problem return. – Eran Shay Jun 20 '18 at 20:36
  • Where do you actually include and apply the com.google.gms.google-services plugin, which I think is the source of: `at com.google.gms.googleservices.GoogleServicesPlugin$1$_afterResolve_closure1.doCall(GoogleServicesPlugin.groovy:316)` – zfromg Jun 21 '18 at 13:22
  • @ZhiQiaoIt it is in a gradle of a different module in that project. The other module use Firebase. When I remove the other module, the first one build with no problem. – Eran Shay Jun 23 '18 at 01:49
  • Possible duplicate of [Firebase dependency in Android Library: Cannot invoke method get() on null object](https://stackoverflow.com/questions/50564754/firebase-dependency-in-android-library-cannot-invoke-method-get-on-null-objec) – Rosário Pereira Fernandes Jul 12 '18 at 21:24
  • 2
    @RosárioPereiraFernandes Thank you. Upgrading the google-services plugin to version 4.0.1 fixed the issue. – Eran Shay Jul 13 '18 at 00:43
  • @EranShay Thanks.. It worked for me.. for me latest version of google-services is **4.2.0**. i.e `classpath 'com.google.gms:google-services:4.2.0'` – Maulik Dodia Jan 17 '19 at 13:43

1 Answers1

2

if you use difference modules you must add firebase config to all android modules

therefor

  • add implementation 'com.google.firebase:firebase-core:x' to dependencies

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

  • get firebase config ("google-service.json") for each android module and add to each module

Kourosh
  • 2,239
  • 13
  • 18
  • 1
    Thanks, my problem is that other modules don't use Firebase, and I don't want to add them. It seems to me very aggressive of Firebase to say if you use one module in your project you must use Firebase in all of your modules. By the way, my problem is with a Module that use "com.google.android.gms:play-services-location" but not Firebase. As soon as I comment out the "implementation 'com.google.android.gms:play-services-location:15.0.1'" from the other module it all works. – Eran Shay Jul 05 '18 at 22:19
  • I was having the same issue after I added a new Wear module.... I did exactly what you said and it worked. I just need to edit the `package_name` inside the `google-service.json` based on the package name of the wear app. Thanks – Onivas Jul 16 '18 at 20:57