gpt4 book ai didi

unit-testing - Android Studio,assembleDebugTest导致多个dex文件定义

转载 作者:行者123 更新时间:2023-12-03 17:57:24 25 4
gpt4 key购买 nike

试图在android studio 0.8.1中运行android测试

我可以正确运行assembleDebug和assembleTest。但是,当我尝试运行android测试时,它会调用assembleDebug和assembleDebugTest,而后者会出现“多个dex文件定义”问题

一些图片:





和项目的build.gradle

dependencies {
compile project(':libraries:someLib')
compile ('com.google.android.gms:play-services:5.+')
compile ('fr.avianey:facebook-android-api:+@aar')
compile ('com.fasterxml.jackson.core:jackson-databind:2.3.1')
compile ('com.fasterxml.jackson.core:jackson-core:2.3.1')
compile ('com.fasterxml.jackson.core:jackson-annotations:2.3.0')
compile fileTree(dir: 'libs', include: '*.jar')

//androidTestCompile 'junit:junit:4.10'
//androidTestCompile 'org.robolectric:robolectric:2.1.+'
//androidTestCompile 'com.squareup:fest-android:1.0.+'
//androidTestCompile 'org.powermock:powermock-api-mockito:1.5.1'
}


和“ someLib”的build.gradle

dependencies {
compile ('com.android.support:appcompat-v7:19.1.+')
compile ('com.nineoldandroids:library:2.4.0')
compile (group: 'com.google.guava', name: 'guava', version: '16.0-rc1')
}


他们俩都分享

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
apply plugin: 'com.android.library'

repositories {
mavenCentral()
}

android {
compileSdkVersion 19
buildToolsVersion '19.1.0'

defaultConfig {
minSdkVersion 9
targetSdkVersion 19
}

lintOptions {
abortOnError false
}
}

最佳答案

到目前为止,我尝试了两种似乎可行的解决方案,但我很确定必须有更好的解决方案。

无论如何1解决方案:

tasks.whenTaskAdded { theTask ->
if("assembleDebugTest".toString().equals(theTask.name.toString())) {
def yourTaskName = "cleanLibs"
project.task(yourTaskName) << {
println "${project.buildDir}/intermediates/pre-dexed/test/debug/"
delete fileTree(dir: ("${project.buildDir}/intermediates/pre-dexed/test/debug/"))
}
theTask.dependsOn(yourTaskName)
def processTask = "preDexDebugTest"
project.(yourTaskName.toString()).dependsOn(processTask)
project.(processTask.toString()).dependsOn("compileDebugTestJava")
}
}


这会在再次创建它们之前删除这些库,这又缓慢又费力,请先创建这些库,然后再删除它们并再次创建它们

解决方案2:

tasks.whenTaskAdded { theTask ->
if("assembleDebugTest".toString().equals(theTask.name.toString())) {
def processTask = "preDexDebugTest"
project.(processTask.toString()).enabled = false
}
}


只需跳过创建第一个库的任务,这比第一个库更好

然后,对于两者,您都必须扩展

android {

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'com/flurry/org/codehaus/jackson/map/VERSION.txt'
exclude 'com/flurry/org/codehaus/jackson/impl/VERSION.txt'
exclude 'com/flurry/org/apache/avro/data/Json.avsc'
exclude 'META-INF/ASL2.0'
}
}


两倍

关于unit-testing - Android Studio,assembleDebugTest导致多个dex文件定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24692846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com