Reputation: 2976
I am trying to setup up androidTests in an existing project.
Following the official guide by Google I added following dependencies:
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.robolectric:robolectric:3.1.2'
androidTestCompile 'org.assertj:assertj-core:3.5.2'
androidTestCompile 'com.android.support:support-annotations:25.3.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
The first problem was, that there were multiple confilicting files (duplicates) within the APK:
packagingOptions {
pickFirst '.readme'
pickFirst 'META-INF/LICENSE.txt'
pickFirst 'META-INF/plexus/components.xml'
pickFirst 'META-INF/NOTICE.txt'
pickFirst 'META-INF/MANIFEST.MF'
pickFirst 'licenses/thoughtworks.TXT'
pickFirst 'licenses/javolution.license.TXT'
pickFirst 'licenses/extreme.indiana.edu.license.TXT'
pickFirst 'org/apache/maven/project/pom-4.0.0.xml'
pickFirst 'org/codehaus/plexus/plexus-bootstrap.xml'
pickFirst 'org/cyberneko/html/res/HTMLlat1.properties'
pickFirst 'org/cyberneko/html/res/HTMLsymbol.properties'
pickFirst 'org/cyberneko/html/res/XMLbuiltin.properties'
pickFirst 'org/cyberneko/html/res/HTMLspecial.properties'
pickFirst 'org/cyberneko/html/res/ErrorMessages_ja.properties'
pickFirst 'org/cyberneko/html/res/ErrorMessages.properties'
pickFirst 'org/cyberneko/html/res/ErrorMessages_ja.txt'
pickFirst 'org/cyberneko/html/res/ErrorMessages.txt'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/DEPENDENCIES'
}
After excluding the duplicates, I ended up with ~1700 warning about classes, superclasses and interface which chould not be found, along with the error:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForMediadeDebugAndroidTest'.
> Job failed, see logs for details
I really don't know at which parts to further look at,to make tests work.
EDIT: Here are the Gradle Logs
Upvotes: 0
Views: 515
Reputation: 7761
You need not run ProGuard while running tests, so you can remove the proguardFiles
lines and change minifyEnabled
to false.
EDIT
To get rid of duplicate dependencies, you need to check the Gradle Console logs to look for the lines about java.util.zip.ZipException: duplicate entry
to find which classes are being added multiple times.
Once you know which classes are duplicated, you can fix it as explained here: Fixing ZipException: duplicate entry
Upvotes: 1