Reputation: 1211
We want to set up instrumentation tests for our app, that also has 2 flavors. We have successfully set up Android Studio to run instrumented tests directly from the IDE, but trying to run instrumented tests from the command line via 'gradle connectedCheck' always results in the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDevelopmentDebugAndroidTestJavaResources'.
> Cannot determine expansion folder for /Users/james/Development/AndroidProjects/parkinsons11/app/build/intermediates/packagedJarsJavaResources/androidTest/development/debug/junit-4.12.jar936209038/LICENSE-junit.txt with folders
Our test app, which also has two flavours and is set up for instrumented tests, runs both from the IDE and from command line without incident.
Here is our gradle file from our main project:
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "com.app.ourapp"
minSdkVersion 16
versionCode 11
versionName "1.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets',
'src/main/assets/font']
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
live {
versionName "1.1 live"
applicationId "com.app.ourapp.live"
}
development {
versionName '1.1 development'
applicationId "com.app.ourapp.development"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':library:datetimepicker')
compile project(':library:tools')
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'org.quanqi:mpandroidchart:1.7.+'
compile 'commons-io:commons-io:2.+'
compile 'joda-time:joda-time:2.+'
compile 'com.microsoft.azure.android:azure-storage-android:0.4.+'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:${robolectricVersion}"
testCompile "org.mockito:mockito-core:1.+"
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:1.+"
}
And here is our gradle.build from our test app (which works):
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.test.picroft.instrumentationtestapp"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
newFlavour {
applicationId "com.test.picroft.instrumentationtestapp.newflavor"
}
oldFlavour {
applicationId "com.test.picroft.instrumentationtestapp.oldflavor"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.+"
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.mockito:mockito-core:1.+"
}
I'm at a loss as to where I'm going wrong. I've compared the directory structure from both apps and there's no meaningful difference. Here's a rough outline of our main project's structure:
src
-androidTest
--java
---*
-live
--res
---layout
---values
-main
--java
---*
-test
--java
---*
I'm totally confused why instrumented tests on one app works fine both in IDE and in command line, while the other refuses to work via command line.
Upvotes: 0
Views: 193
Reputation: 1211
It seems the issue resolved itself. I believe it was some kind of corruption of the build state that was fixed through an invalidate/restart.
Its also worth pointing out that when you switch build flavours in the Build Variation panel, its worth it to wait until Android Studio finishes synchronizing and is not performing any tasks before doing a build or run. I've found that when I was hitting build or run and Android Studio hadn't finished switching the build flavour, it caused all manner of unpredictable issues.
Upvotes: 1
Reputation: 1268
I think the problem might be that you haven't defined a default instrumentation runner, as mentioned here. You should include this in your build.gradle file
android {
defaultConfig {
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
Upvotes: 0