【问题标题】:Multiple dex files define Landroid/support/test/espresso/accessibility/R$attr;多个dex文件定义Landroid/support/test/espresso/accessibility/R$attr;
【发布时间】:2017-11-15 21:15:11
【问题描述】:

尝试运行 UI 测试 (androidTest) 后,我不断收到以下错误

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/test/espresso/accessibility/R$attr;

Error:Execution failed for task ':chegg-study:transformDexArchiveWithDexMergerForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Landroid/support/test/espresso/accessibility/R$attr;

AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: com.android.dex.DexException: Multiple dex files define Landroid/support/test/espresso/accessibility/R$attr;","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\ncom.android.dex.DexException: Multiple dex files define Landroid/support/test/espresso/accessibility/R$attr;\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"com.android.dex.DexException: Multiple dex files define Landroid/support/test/espresso/accessibility/R$attr;","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:198)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)","sources":[{}]}
AGPBI: {"kind":"error","text":"\tat java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)","sources":[{}]}

我的 gradle 包含以下依赖项:

androidTestImplementation "com.android.support.test.espresso:espresso-core:$espresso"
androidTestImplementation "com.android.support.test.espresso:espresso-contrib:$espresso"
androidTestImplementation "com.android.support.test.espresso:espresso-intents:$espresso"
androidTestImplementation "com.android.support.test.espresso:espresso-accessibility:$espresso"
androidTestImplementation "com.android.support.test.espresso:espresso-web:$espresso"
androidTestImplementation "com.android.support.test.espresso:espresso-idling-resource:$espresso"
androidTestImplementation "com.android.support.test.espresso.idling:idling-concurrent:$espresso"
androidTestImplementation 'com.android.support:multidex-instrumentation:1.0.2'
  • 浓缩咖啡 3.0.1

请指教

【问题讨论】:

  • libs文件夹中有jar文件吗?
  • 我刚刚在我的项目中尝试过,每次包含espresso-accessibility 时都会出现此错误。如果您现在不需要它,可以将其删除以解除阻止。我建议在这里提交一个错误:issuetracker.google.com/issues?q=componentid:192735%2B
  • 你能解决这个问题吗?我被困在同一个地方。
  • 是的。已经解决了。

标签: android android-gradle-plugin android-espresso android-multidex


【解决方案1】:

通过强制特定的库版本解决了这个问题:

   configurations.all {
        resolutionStrategy {
            // fail eagerly on version conflict (includes transitive dependencies)
            // e.g. multiple different versions of the same dependency (group and name are equal)
            failOnVersionConflict()

            // prefer modules that are part of this build (multi-project or composite build) over external modules
            preferProjectModules()

        force 'com.android.support:appcompat-v7:27.0.1'
        }
    }

并使用此 gradle 命令查看依赖关系树:

./gradlew -q dependencies :project_name:dependencies

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 2015-12-06
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多