DataBinding 1.DexArchiveMergerException: Unable to merge dex2.DexArchiveMergerException: Unable t...

在给项目中添加dataBinding{ enabled = true } 后安装时报错:
Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/LoaderManager

Error.png

具体解决方法如下:
错误的gradle引用:

    implementation fileTree(include: ['*.jar'], dir: 'libs')
   implementation 'com.android.support:appcompat-v7:27.1.1'
   implementation 'com.android.support.constraint:constraint-layout:1.1.3'
   testImplementation 'junit:junit:4.12'
   androidTestImplementation 'com.android.support.test:runner:1.0.2'
   androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

正确的gradle引用:

   implementation fileTree(include: ['*.jar'], dir: 'libs')
   testImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
       exclude group: 'com.android.support', module: 'support-annotations'
   })
   implementation 'com.android.support.constraint:constraint-layout:1.0.2'
   testImplementation 'junit:junit:4.12'
   implementation 'com.android.support:appcompat-v7:26.0.2'

换成下面的引用方式 完美运行。

你可能感兴趣的:(DataBinding 1.DexArchiveMergerException: Unable to merge dex2.DexArchiveMergerException: Unable t...)