1

所以我已经更新到gradle 3.0.0(IDE),它开始让我遇到各种各样的问题。
首先我必须启用multiDex

实施项目multidex vailError:任务':sample:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败。> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 dex

这很奇怪,因为这些是我唯一的依赖项:

:样本

implementation project(':lib-module')
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'

:lib 模块

implementation "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'junit:junit:4.12'

如果multiDex由于这些依赖关系而必须启用它,那么默认情况下它也可能是真的......
启用它后,我在:sample模块中遇到了这个问题:

摇篮:

“所有 com.android.support 库必须使用完全相同的版本规范(混合版本会导致运行时崩溃)。找到版本 27.0.0、21.0.3。”

安慰:

java.io.IOException:

无法写入 [build/intermediates/multi-dex/debug/componentClasses.jar](无法读取 [.../build/intermediates/transforms/desugar/debug/14.jar(;;;;;;* *.class)] (重复的 zip 条目 [14.jar:android/support/v4/view/ViewPager$1.class]))

所以我做了一些调查:

$ ./gradlew -q dependencies sample:dependencies --configuration debugAndroidTestCompileClasspath
------------------------------------------------------------
Project :sample
------------------------------------------------------------

debugAndroidTestCompileClasspath - Resolved configuration for compilation for variant: debugAndroidTest
+--- project :lib-module
+--- com.android.databinding:library:1.3.1
|    +--- com.android.support:support-v4:21.0.3
|    |    \--- com.android.support:support-annotations:21.0.3 -> 27.0.0
|    \--- com.android.databinding:baseLibrary:2.3.0-dev -> 3.0.0
+--- com.android.databinding:baseLibrary:3.0.0
+--- com.android.databinding:adapters:1.3.1
|    +--- com.android.databinding:library:1.3 -> 1.3.1 (*)
|    \--- com.android.databinding:baseLibrary:2.3.0-dev -> 3.0.0
+--- com.android.support:multidex-instrumentation:1.0.2
|    \--- com.android.support:multidex:1.0.2
+--- com.android.support:appcompat-v7:27.0.0
|    +--- com.android.support:support-annotations:27.0.0
|    +--- com.android.support:support-core-utils:27.0.0
|    |    +--- com.android.support:support-annotations:27.0.0
|    |    \--- com.android.support:support-compat:27.0.0
|    |         +--- com.android.support:support-annotations:27.0.0
|    |         \--- android.arch.lifecycle:runtime:1.0.0
|    |              +--- android.arch.lifecycle:common:1.0.0
|    |              \--- android.arch.core:common:1.0.0
|    +--- com.android.support:support-fragment:27.0.0
|    |    +--- com.android.support:support-compat:27.0.0 (*)
|    |    +--- com.android.support:support-core-ui:27.0.0
|    |    |    +--- com.android.support:support-annotations:27.0.0
|    |    |    \--- com.android.support:support-compat:27.0.0 (*)
|    |    +--- com.android.support:support-core-utils:27.0.0 (*)
|    |    \--- com.android.support:support-annotations:27.0.0
|    +--- com.android.support:support-vector-drawable:27.0.0
|    |    +--- com.android.support:support-annotations:27.0.0
|    |    \--- com.android.support:support-compat:27.0.0 (*)
|    \--- com.android.support:animated-vector-drawable:27.0.0
|         +--- com.android.support:support-vector-drawable:27.0.0 (*)
|         \--- com.android.support:support-core-ui:27.0.0 (*)
\--- com.android.support.constraint:constraint-layout:1.0.2
     \--- com.android.support.constraint:constraint-layout-solver:1.0.2

(*) - dependencies omitted (listed previously)

$ ./gradlew -q dependencies lib-module:dependencies --configuration debugAndroidTestCompileClasspath

debugAndroidTestCompileClasspath - Resolved configuration for compilation for variant: debugAndroidTest
+--- com.android.support.test.espresso:espresso-core:2.2.2
|    +--- com.squareup:javawriter:2.1.1
|    +--- com.android.support.test:rules:0.5
|    |    \--- com.android.support.test:runner:0.5
|    |         +--- junit:junit:4.12
|    |         |    \--- org.hamcrest:hamcrest-core:1.3
|    |         \--- com.android.support.test:exposed-instrumentation-api-publish:0.5
|    +--- com.android.support.test:runner:0.5 (*)
|    +--- javax.inject:javax.inject:1
|    +--- org.hamcrest:hamcrest-library:1.3
|    |    \--- org.hamcrest:hamcrest-core:1.3
|    +--- com.android.support.test.espresso:espresso-idling-resource:2.2.2
|    +--- org.hamcrest:hamcrest-integration:1.3
|    |    \--- org.hamcrest:hamcrest-library:1.3 (*)
|    +--- com.google.code.findbugs:jsr305:2.0.1
|    \--- javax.annotation:javax.annotation-api:1.2
+--- junit:junit:4.12 (*)
\--- com.android.support:support-annotations:27.0.0

(*) - dependencies omitted (listed previously)

我发现数据绑定导入support-v4......如果发生这种情况:(com.android.support:support-annotations:21.0.3 -> 27.0.0更新支持注释版本)为什么不support-v4更新呢?
所以我不得不在我的:sample 模块中添加这个依赖项:

implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"

从项目中删除所有构建文件夹和.gradle后,从 user/.gradle 中删除缓存文件夹,运行 Clean 然后 Rebuild,我终于得到了一个 .apk

为什么3.0.0会gradle发生这种情况? 谢谢你的时间。Android Studio

============================

编辑:感谢Mark (@CommonsWare) 的评论,我发现这不仅是一个已知问题,在添加 support-v4 依赖项后,不再需要 multiDex。

4

0 回答 0