所以我已更新到gradle 3.0.0
(IDE也),它开始让我遇到各种各样的问题。
首先,我必须启用multiDex
:
实现项目multidex vailError:任务执行失败 ':样品:transformDexArchiveWithExternalLibsDexMergerForDebug&#39 ;. > 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-module
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] (不能读 [... /建造/中间体/变换/ desugar /调试/ 14.jar(;;;;;; **。类)] (重复的zip条目 [14.jar:机器人/支持/ V4 /视图/ 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
也得到更新?
所以我必须在:示例模块:
implementation "com.android.support:support-v4:$rootProject.supportLibraryVersion"
从项目中删除所有构建文件夹和 .gradle 后,从用户/ .gradle缓存文件夹,运行Clean然后重建,我终于得到了一个.apk
为什么gradle
和Android Studio
3.0.0会发生这种情况?
谢谢你的时间。
===========================
编辑:感谢 Mark (@CommonsWare)comment我发现不仅是已知的问题,添加support-v4依赖项,不再需要multiDex。