Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke method systemProperty() on null object -- android studio and gradle

I am facing a strange exception while building my app.

Following is my project specificbuild.gradle file in main application folder(not in app folder).

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
    }
}

apply plugin: 'java'

dependencies {
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.9.5"
}

allprojects {
    repositories {
        jcenter()
    }
}

However, I am able to fix this if I change the gradle dependency to version 1.2.3, it works fine.but with 1.3.0 it is not even starting the build and gives Cannot invoke method systemProperty() on null object exception.

classpath 'com.android.tools.build:gradle:1.2.3'

The details in android studio log file shows:---

2015-09-09 15:28:18,211 [120924807]   WARN - nal.AbstractExternalSystemTask - Cannot invoke method systemProperty() on null object 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot invoke method systemProperty() on null object
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
    at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.getUserFriendlyError(BaseProjectImportErrorHandler.java:158)
    at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.getUserFriendlyError(BaseGradleProjectResolverExtension.java:438)
    at com.android.tools.idea.gradle.project.AndroidGradleProjectResolver.getUserFriendlyError(AndroidGradleProjectResolver.java:348)
    at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver

Can anyone explain me the reason, why it is not taking 1.3.0 gradle plugin??

like image 201
Nicks Avatar asked Mar 15 '23 20:03

Nicks


1 Answers

i had the same issue. see this link.

the plug-in is not compatible with v1.3.0 of the Gradle plugin and has been deprecated as of Robolectric 3.0, which i suspect you may be using. just remove it (along with any references to it in your app's build.gradle file) from your configuration and you should be good to go.

also, fwiw - you were pulling on the right threads in looking at the Studio log file. you just needed to look at the stack frame that preceded the one you referenced to get more specific clues as to the root cause:

Caused by: java.lang.NullPointerException: Cannot invoke method systemProperty() on null object
    at org.robolectric.gradle.RobolectricPlugin$_apply_closure1_closure2.doCall(RobolectricPlugin.groovy:28)
    at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
    at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:110)
    at org.gradle.api.internal.DefaultDomainObjectCollection.all(DefaultDomainObjectCollection.java:115)
    at org.gradle.api.DomainObjectCollection$all$3.call(Unknown Source)
    at org.robolectric.gradle.RobolectricPlugin$_apply_closure1.doCall(RobolectricPlugin.groovy:19)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
    at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:83)
    at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:31)
    at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
    at com.sun.proxy.$Proxy10.afterEvaluate(Unknown Source)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:79)
like image 182
homerman Avatar answered Mar 21 '23 15:03

homerman