Le_Enot
Le_Enot

Reputation: 839

Android instrumentation test dexing error

I am trying to do some instrumentation tests with Espresso, but when I am compiling my test, gradle make return an error:

Error:Gradle: Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Landroid/databinding/DataBindingComponent;

I assumed that there was some dependency errors and listed dependencies like this:
.\gradlew app:dependencies

And there was the strange thing: I am using databinding version 1.0-rc4, but in the listed dependencies there was 1.0-rc3:

default - Configuration for default artifacts.
+--- com.android.databinding:library:1.0-rc3                                     
|    +--- com.android.databinding:baseLibrary:1.0-rc3
|    \--- com.android.support:support-v4:21.0.3 -> 23.1.1
|         \--- com.android.support:support-annotations:23.1.1
+--- com.android.databinding:adapters:1.0-rc3
|    \--- com.android.databinding:library:1.0-rc3 (*)
+--- com.android.support:appcompat-v7:23.1.1
|    \--- com.android.support:support-v4:23.1.1 (*)
+--- com.android.support:recyclerview-v7:23.1.1
|    +--- com.android.support:support-annotations:23.1.1
|    \--- com.android.support:support-v4:23.1.1 (*)
+--- com.google.dagger:dagger:2.0    
|    \--- javax.inject:javax.inject:1
\--- com.trello:rxlifecycle-components:0.4.0
     +--- com.trello:rxlifecycle:0.4.0
     |    +--- com.jakewharton.rxbinding:rxbinding:0.3.0
     |    |    +--- com.android.support:support-annotations:23.1.0 -> 23.1.1
     |    |    \--- io.reactivex:rxjava:1.0.14 -> 1.0.16
     |    \--- io.reactivex:rxjava:1.0.16
     +--- com.android.support:appcompat-v7:23.1.1 (*)
     \--- io.reactivex:rxjava:1.0.16 

provided - Classpath for only compiling the main sources.
+--- com.android.databinding:compiler:1.0-rc4                                     
|    \--- com.android.databinding:baseLibrary:1.0-rc4
\--- javax.annotation:javax.annotation-api:1.2

Where did this 1.0-rc3 come from? There is no such string "rc3" in my whole project (except in generated dex-cache files).

UPD:
I think this is an android gradle-plugin issue, because same code works with gradle 1.5 but fails with gradle 2.0.0-beta2 and 2.0.0-beta4.
UPD2:
Solved the problem.
Project was relatively old and android-databinding plugin grown from beta since gradle 1.5.0-beta1
Now to enable databinding you should only add

dataBinding {
    enabled = true
}

in your android{} section.

So if you face such problem, make sure you deleted these strings from your build.gradle files:
1) apply plugin: 'com.android.databinding'
2) classpath 'com.android.databinding:dataBinder:1.0-rc4'
3) apt 'com.android.databinding:compiler:1.0-rc4'

Upvotes: 2

Views: 401

Answers (1)

Le_Enot
Le_Enot

Reputation: 839

Solved the problem.
Project was relatively old and android-databinding plugin grown from beta since gradle 1.5.0-beta1
Now to enable databinding you should only add

dataBinding {
    enabled = true
}

in your android{} section.

So if you face such problem, make sure you deleted these strings from your build.gradle files:
1) apply plugin: 'com.android.databinding'
2) classpath 'com.android.databinding:dataBinder:1.0-rc4'
3) apt 'com.android.databinding:compiler:1.0-rc4'

Upvotes: 1

Related Questions