Cannot invoke method systemProperty() on null object
jonneymendoza opened this issue · 4 comments
Hi .
i am trying to build and run unit tests via Robolectrie test framework but i am unable to do so due the actual plugin i use
Here is my build script i tried
//http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'http://www.testfairy.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'com.testfairy.plugins.gradle:testfairy:1.+'
classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
apply plugin: 'testfairy'
apply plugin: 'org.robolectric'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
testBuildType "debug"
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
testApplicationId "com.project.test"
// testInstrumentationRunner "android.test.InstrumentationTestRunner"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//testInstrumentationRunner "com.project.test.Runner"
manifestPlaceholders = [ adxUseQaServerEnabled: "ON" ]
}
testfairyConfig {
apiKey “xxxx”
metrics "cpu,memory,network,logcat"
video "wifi"
videoRate "0.5"
videoQuality "low"
maxDuration "10m"
recordOnBackground true
iconWatermark true
testersGroups “projectName_Android"
notify true
maxDuration "1h"
autoUpdate true
uploadProguardMapping true
}
productFlavors {
//testing {
//}
local {
}
mock {
}
qa {
}
//qa4 {
//}
production {
}
}
sourceSets {
local {
res.srcDir 'build-config/local/res'
}
testing {
res.srcDir 'build-config/testing/res'
}
mock {
res.srcDir 'build-config/mock/res'
}
qa {
res.srcDir 'build-config/qa/res'
}
qa4 {
res.srcDir 'build-config/qa4/res'
}
staging {
res.srcDir 'build-config/staging/res'
}
production {
res.srcDir 'build-config/production/res'
}
}
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile 'proguard-project.txt'
signingConfig signingConfigs.release
manifestPlaceholders = [ adxUseQaServerEnabled:"OFF" ]
}
debug {
versionNameSuffix "-debug"
}
}
}
android.lintOptions {
disable 'InvalidPackage'
abortOnError false
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.google.code.gson:gson:2.3'
compile 'com.android.support:support-v4:19.1.+'
compile 'com.android.support:appcompat-v7:19.1.+'
compile 'com.google.android.gms:play-services:5.0.+'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile "joda-time:joda-time:2.4"
androidTestCompile ('junit:junit:4.12') {
exclude module : 'hamcrest'
exclude module : 'hamcrest-core'
}
androidTestCompile 'org.hamcrest:hamcrest-all:1.3'
androidTestCompile ('org.mockito:mockito-core:1.9.5') {
exclude module : 'hamcrest'
exclude module : 'hamcrest-core'
}
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.sothree.slidinguppanel:library:3.0.0'
compile 'com.jakewharton:butterknife:6.1.0'
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-plugin-registry'
exclude module: 'maven-profile'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'nekohtml'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-http-shared'
exclude module: 'wagon-provider-api'
exclude module: 'objenesis'
}
}
here is a simple test class
/**
* This class tests api calls
*/
@RunWith(RobolectricTestRunner.class)
public class ApiTestRobo {
@Before
protected void setUp() throws Exception {
VolleyLog.DEBUG = true;
ProjectApplication = (ProjectApplication) Robolectric.application;
requestQueue = lmApplication.getRequestQueue();
response = null;
}
@After
protected void tearDown() throws Exception {
requestQueue.cancelAll(new RequestQueue.RequestFilter() {
@Override
public boolean apply(Request<?> request) {
return true;
}
});
response = null;
}
@Test
public void testGeocodeApi() {
response = makeRequestSynchronous(RequestManager.geoCodeAddress(“999 Bond High Road", new Response.Listener<GeocodeResponse>() {
@Override
public void onResponse(GeocodeResponse geocodeResponse) {
response = geocodeResponse;
notifyResponse();
}
}, errorListener));
GeocodeResponse geocodeResponse = (GeocodeResponse) response;
Assert.assertEquals("OK", geocodeResponse.status);
Assert.assertEquals(51.4912901, geocodeResponse.results.get(0).geometry.location.lat);
Assert.assertEquals(-0.2825666, geocodeResponse.results.get(0).geometry.location.lng);
}
}
Here is the error i get
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':project'.
> Cannot invoke method systemProperty() on null object
* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':project'.
at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:91)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:86)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:65)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:504)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:83)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:47)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: java.lang.NullPointerException: Cannot invoke method systemProperty() on null object
at org.robolectric.gradle.RobolectricPlugin$_apply_closure1_closure2.doCall(RobolectricPlugin.groovy:31)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:63)
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$1.call(Unknown Source)
at org.robolectric.gradle.RobolectricPlugin$_apply_closure1.doCall(RobolectricPlugin.groovy:27)
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.$Proxy13.afterEvaluate(Unknown Source)
at org.gradle.configuration.project.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:79)
... 28 more
BUILD FAILED
You need to be using version 1.1.+ of the android plugin which adds the test tasks rather than androidTest.
I had the same problem as @jonneymendoza. The same call stack when run "gradle clean test". @frownlee, Could you make it more clear which android plugin are you talking about? Thanks!
@jonneymendoza I see what you mean, after changing the version to
classpath 'com.android.tools.build:gradle:1.1.+'
in the parent build.gradle. Everything works fine. Thanks a lot!
As @zhanghaowx mentioned, make sure you are using version 1.1.+ of the android gradle plugin.