Issue
Currently, my android project is using gradle plug-in version 1.2.3. I am able to successfully run the unit tests (android tests) using the gradle command "./gradlew clean connectedProductionAndroidTest" where "Production" is a flavor.
However, when I updated my gradle plug-in to 1.5.0, I am getting the following error.
17:35:16 Tests on Android SDK built for x86 - 4.2 failed: Instrumentation run failed due to 'java.lang.IllegalAccessError'
17:35:16
17:35:16 com.android.builder.testing.ConnectedDevice > No tests found.[Android SDK built for x86 - 4.2] [31mFAILED [0m
17:35:16 No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).
When I updated the gradle plug-in, I didn't make any changes to the directory structure nor any of my tests.
Here is the code I am using to update the gradle plug-in. This is in my root build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
I am just wondering if anything has changed between the two versions that might be making my tests fail?
Note that I've placed my tests in "$ROOT/app/src/androidTest/java/..." as specified in the documentation. Also, in gradle 1.2.3, I had to use the command "./gradlew clean connectedProductionAndroidTest" but in plug-in version 1.5.0, it looks like things have changed. I must now do: "./gradlew clean connectedAndroidTestProduction". Note the swap of "Production" and "AndroidTest".
Any help would be greatly appreciated.
EDIT:
Here is my app's build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
lintOptions {
disable 'OldTargetApi'
abortOnError false
}
defaultConfig {
applicationId "com.myapp"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode rootProject.getVersionCode()
versionName rootProject.getVersionName()
testApplicationId "com.myapp.test"
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles 'proguard.cfg'
signingConfig signingConfigs.release
multiDexEnabled false
}
debug {
debuggable true
testCoverageEnabled true
signingConfig signingConfigs.release
multiDexEnabled true
}
}
productFlavors {
production {
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
Solution
In your project.properties file add this line:
manifestmerger.enabled=true
and rebuild your app.
If it won't work check this solution:
I have finally found a solution. The problem was with dependencies indeed, it is still unknown why it used to work and then suddenly refused, but here is how the dependencies should look like for your test module:
So all in all you need to make sure all your libraries and project libraries are listed for your test module and marked as "Provided" except Robotium lib, which is "Compile".
From: Instrumentation run failed due to 'java.lang.IllegalAccessError'
And finally, if you still stuck at this problem:
Older devices have problems running tests when you have the same dependency in your app and test app that instruments the app.
To work around this issue, you will have to figure out which dependencies cause the problem.
In my case it was both Dagger and Espresso depending on
javax.injectand this is how it can be "fixed":androidTestCompile('com.android.support.test.espresso:espresso-core:2.0'){ exclude group: 'javax.inject' }
If you include more or weirder dependencies, you may have a look at this build.gradle.
When using espresso-contrib, you may need to do this:
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.0') { exclude group: 'javax.inject' exclude group: 'com.android.support' }
Answered By - piotrek1543

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.