我正在尝试运行一个单元测试,模拟SQLiteOpenHelper
的子类,但是我得到了以下错误。
java.lang.NoClassDefFoundError: android/database/sqlite/SQLiteOpenHelper
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
...
at org.dfhu.vpodplayer.util.JsonExporterTest.export(JsonExporterTest.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
...
我的Gradle文件看起来像
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion '25.0.1'
defaultConfig {
applicationId "org.dfhu.vpodplayer"
minSdkVersion 18
targetSdkVersion 24
versionCode 1
versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.7
sourceCompatibility 1.7
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
testCompile 'junit:junit:4.12'
testCompile 'org.powermock:powermock-api-mockito:1.6.5'
testCompile 'org.powermock:powermock-module-junit4:1.6.5'
}
在重新安装Android Studio并更新builtToolsVersion至'25.0.1'之后,此方法曾经有效。
我正在寻找一种方法,在我的测试运行程序中获取我的android依赖关系。
./gradlew test
一起运行吗? - tynn