Android tests build error: Multiple dex files define Landroid/support/test/BuildConfig
Update (9/07/2015):
You can continue to work with 22.2.1 if you use the following excludes:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
If you depend on espresso-contrib
, you need the exclude as well.
Update (8/03/2015):
With support library 22.2.1, the dependencies are broken again; please don't upgrade to 22.2.1 until a new runner is released.
Update (6/04/2015):
With the latest release of runner 0.3 and rules 0.3, this answer is no longer needed. You can simply use
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
with latest support libraries. (22.2.0
as of this writing)
Update (5/30/2015):
compile 'com.android.support:appcompat-v7:22.2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
// com.android.support.test:testing-support-lib:0.1 // <-- causes issue
Update (4/24/2015):
The problem is that com.android.support:support-v4:22.1.1
is clashing with com.android.support.test:runner:0.2
(as that depends on com.android.support:support-v4:22.0.0
).
com.android.support.test.espresso:espresso-core:2.1
has a dependency on com.android.support.test:runner:0.2
, so it also causes the same error.
So, this combination will work:
compile 'com.android.support:support-v4:22.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
...and so will this one (without 'com.android.support.test:runner:0.2'
):
compile 'com.android.support:support-v4:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
Original Answer:
Contrary to what the Espresso documentation says, you should remove this dependency:
androidTestCompile 'com.android.support.test:runner:0.2'
As it is the cause for library version conflict.
You should also update to Android gradle plugin 1.1.1, as that version will tell you the exact version conflict, which is useful in this case.
Unable to build : How to add Android Build Config for new Module
Here are some things to consider
- There are differences between
App Module
andLibrary Module
.
Library Module is complied to .aar/file
. However, App Module is Compiled to APK
.
This means that you can not import App Module as dependency to Library Module. Therefore, Remove This line from Library Module:
implementation project(':app')
- Make sure the library is listed at the top of your
settings.gradle
.
Open settings.gradle of the App Module and make sure there is your library listed
include ':app', ':chat'
- import the Library Module to your App Module Build Gradle
import your Library Module as dependency
dependencies {
implementation project(':chat')
}
Most Importantly Have a look at :Create an Android library
Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;
My problem was resolved after cleaning up some directories and files left over from the previous versions of the tools. ADT Rev 14 changes where binaries are stored. I deleted the entire bin directory, restarted Eclipse and cleaned the build and forced a rebuild. That seemed to do the trick initially but the problem came back after the next run.
I finally discovered that my bin directory was included in the project build path. I excluded bin from the build path and repeated the steps above. This resolved my problem.
Program type already present: BuildConfig
You are getting this error because you a have library module which has the same package name as the app module.
The solution would be to change package name of your library module. You can follow the accepted answer in this SO which describes how to change the package name in android studio.
How to resolve a library conflict (apache commons-codec)
Late reply but maybe usefull for someone.
Problem solved by using Maven Shade Plugin
This plugin allows to rename package names of conflicted library at compilation.
Usage :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>com.example.shaded.org.apache.commons</shadedPattern>
</relocation>
</relocations>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
</configuration>
</execution>
</executions>
</plugin>
Related Topics
Android Gives Error "Cannot Fit Requested Classes in a Single Dex File"
Problems Importing Project into Android Studio Regarding Actionbarsherlock
Android Intent for Sending Email with Attachment
How to Resolve "Duplicate Files Copied in APK Meta-Inf/*"
Divide Elements on Groups in Recyclerview or Grouping Recyclerview Items ,Say by Date
Return Data from Asynctask Class
Proguard and Reflection in Android
Android App Crashes After Sdk-Tools Update Version (Noclassdeffound, Tool Version 22)
How to Do an Https Post from Android
Click Is Not Working on the Listitem Listview Android
Eclipse: Jvm Terminated. Exit Code=2
Why Menuitemcompat.Getactionprovider Returns Null
How to Remove a Specific Element from a JSONarray
Noclassdeffounderror on External Library Project for Android
Google Cloud Messaging - Messages Either Received Instantly or with Long Delay