我正在尝试将Espresso添加为我的Android项目的测试框架,并在运行样本测试时遇到以下运行时错误。
error: package android.support.test.rule does not exist
error: package android.support.test.runner does not exist
我的文件夹结构如下:
app/src/androidTest/java/com/[identifier]/support/[app_folders]
app/src/com/java/com/[identifier]/support/[app_folders]
我的build.gradle
看起来像以下减去编辑不相关的陈述。
apply plugin: 'com.android.application'
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
}
}
allprojects {
repositories {
mavenCentral();
jcenter()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.13'
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'LICENSE.txt'
}
compileSdkVersion 23
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
applicationId privateHelpers.extractStringFromManifest("package")
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode Integer.parseInt("" + project.VERSION_CODE)
versionName project.VERSION_NAME
}
lintOptions {
abortOnError false;
}
dexOptions {
javaMaxHeapSize "4096m"
preDexLibraries = false
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
debugCompile project(path: "CordovaLib", configuration: "debug")
releaseCompile project(path: "CordovaLib", configuration: "release")
compile "com.google.android.gms:play-services-analytics:+"
compile "com.google.android.gms:play-services-gcm:+"
compile "com.google.android.gms:play-services-location:+"
compile "com.pushwoosh:pushwoosh:4.6.3"
compile "io.branch.sdk.android:library:1+"
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'joda-time:joda-time:2.9.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.4.1'
compile 'io.intercom.android:intercom-sdk:3.0.20'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.jakewharton.threetenabp:threetenabp:1.0.5'
compile 'com.jakewharton:butterknife:8.5.1'
compile 'com.joshdholtz.sentry:sentry-android:1.6.0'
compile 'com.instabug.library:instabug:4.0.7'
compile 'com.workday:postman:1.3'
compile ('com.afollestad.material-dialogs:core:0.9.0.0') {
exclude module: 'support-annotations'
}
compile 'com.workday:postman-processor:1.3'
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile 'com.android.support:support-v4:23.4.0'
androidTestCompile 'com.android.support:support-annotations:26.0.0-alpha1'
androidTestCompile 'com.squareup:javawriter:2.5.1'
androidTestCompile ('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
testCompile 'org.threeten:threetenbp:1.3.1'
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
androidTestCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
}
sourceSets {
main {
java {
srcDir 'src'
}
}
}
buildscript {
dependencies {
classpath 'net.ltgt.gradle:gradle-apt-plugin:0.6' // Java annotation processing
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // Android annotation processing
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
compile 'com.google.dagger:dagger:2.6.1'
apt 'com.google.dagger:dagger-compiler:2.6.1'
compile 'com.jakewharton:butterknife:8.3.0'
apt 'com.jakewharton:butterknife-compiler:8.3.0'
provided 'javax.annotation:jsr250-api:1.0'
}
android {
testBuildType "debug"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}