我试图在我的项目中使用Roboletric。开发环境 - Android Studio 0.5.8
应用/的build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+'
}
allprojects {
repositories {
mavenCentral()
}
}
}
apply plugin: 'android'
apply plugin: 'android-test'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
abortOnError false
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
androidTest {
setRoot('src/test');
}
}
}
androidTest {
include '**/*Test.class'
exclude '**/espresso/**/*.class'
}
dependencies {
androidTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.2.1',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3-SNAPSHOT') {
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'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'com.octo.android.robospice:robospice:1.4.11'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.11'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.squareup.dagger:dagger-compiler:1.2.1'
compile 'org.slf4j:slf4j-api:1.7.6'
compile 'com.github.tony19:logback-android-core:1.1.1-2'
compile 'com.github.tony19:logback-android-classic:1.1.1-2'
compile project('libraries:android-maps-utils')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
当我尝试使用控制台命令gradle clean test
执行测试用例时,控制台会提示错误消息:
java.lang.VerifyError
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: Could not initialize class org.gradle.internal.SystemProperties
at org.gradle.util.LineBufferingOutputStream.<init>(LineBufferingOutputStream.java:44)
at org.gradle.util.LineBufferingOutputStream.<init>(LineBufferingOutputStream.java:36)
at org.gradle.util.LinePerThreadBufferingOutputStream$1$1.run(LinePerThreadBufferingOutputStream.java:35)
at org.gradle.util.LinePerThreadBufferingOutputStream$1$1.run(LinePerThreadBufferingOutputStream.java:33)
at java.security.AccessController.doPrivileged(Native Method)
at org.gradle.util.LinePerThreadBufferingOutputStream$1.initialValue(LinePerThreadBufferingOutputStream.java:33)
at org.gradle.util.LinePerThreadBufferingOutputStream$1.initialValue(LinePerThreadBufferingOutputStream.java:30)
at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:160)
at java.lang.ThreadLocal.get(ThreadLocal.java:150)
at org.gradle.util.LinePerThreadBufferingOutputStream.getStream(LinePerThreadBufferingOutputStream.java:47)
at org.gradle.util.LinePerThreadBufferingOutputStream.flush(LinePerThreadBufferingOutputStream.java:80)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at java.util.logging.StreamHandler.flush(StreamHandler.java:242)
at java.util.logging.ConsoleHandler.close(ConsoleHandler.java:115)
at java.util.logging.LogManager.resetLogger(LogManager.java:860)
at java.util.logging.LogManager.reset(LogManager.java:843)
at java.util.logging.LogManager$Cleaner.run(LogManager.java:240)
有人遇到过类似的错误吗?
答案 0 :(得分:0)
其他gradle命令是否有效?它有一个VerifyError尝试初始化Gradle类的事实使我认为您的Gradle安装已损坏。尝试删除主目录和项目根目录中的.gradle目录。