我在制作应用时面临一个奇怪的异常。
以下是我的项目specificbuild.gradle文件在主应用程序文件夹中(不在app文件夹中)。
// 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()
}
}
但是,如果我将gradle依赖项更改为1.2.3版本,我能够解决这个问题,它工作正常。但是1.3.0它甚至没有启动构建并且给出了无法在null对象上调用方法systemProperty()例外。
classpath'com.android.tools.build:grad:1.2.3'
android studio日志文件中的详细信息显示:---
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
任何人都可以解释一下原因,为什么不采用1.3.0 gradle插件?
答案 0 :(得分:7)
该插件与Gradle插件的v1.3.0不兼容,并且自Robolectric 3.0起已被弃用,我怀疑您可能正在使用它。只需从您的配置中删除它(以及应用程序的build.gradle文件中对它的任何引用),您应该很高兴。
另外,fwiw - 你正在查看Studio日志文件中的正确线程。你只需要查看你引用的堆栈框架之前的堆栈框架,以获得有关根本原因的更具体的线索:
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)