gpt4 book ai didi

android - Gradle 依赖 : How to figure out what's causing this duplication

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:00:48 24 4
gpt4 key购买 nike

我有一个 Android 项目,其中包含一个 MultiDex 应用程序。

我正在尝试使用 ./gradlew clean connectedAndroidTest 运行 Espresso 测试。此命令最终导致此错误消息:

:app:dexDebugAndroidTest
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/test/InstrumentationRegistry;

我的顶级 build.gradle 包含:

classpath 'com.android.tools.build:gradle:1.2.3'

我通过包装器使用 Gradle 2.4。

我项目的 build.gradle 是这样的:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.robolectric:robolectric-gradle-plugin:1.0.1'
// classpath 'me.tatarka:gradle-retrolambda:3.1.0'
}
}

apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
//apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'org.robolectric'

android {
compileSdkVersion 21
buildToolsVersion "22.0.1"

defaultConfig {
applicationId "com.something"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"

multiDexEnabled true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}

dexOptions {
javaMaxHeapSize "2g"
preDexLibraries = false
}

buildTypes {
debug {
versionNameSuffix '-DEBUG'

minifyEnabled false
shrinkResources = false
zipAlignEnabled = false
}

release {
minifyEnabled false

shrinkResources = true
zipAlignEnabled = true
}
}

lintOptions {
checkReleaseBuilds false
abortOnError false
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt' }
}

dependencies {
//compile 'com.google.dexmaker:dexmaker:1.0'
compile 'com.android.support:multidex:1.0.1'

// Auth0
compile 'com.auth0.android:lock:1.7.0'
compile 'com.auth0.android:lock-googleplus:1.7.0'

compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.picasso:picasso:2.1.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.google.android.gms:play-services-plus:7.3.0'
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.amazonaws:aws-android-sdk-cognito:2.2.1'
compile 'com.amazonaws:aws-android-sdk-core:2.2.1'
compile 'com.amazonaws:aws-android-sdk-mobileanalytics:2.2.1'

// Robolectric
//testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0-rc3"
testCompile "org.robolectric:shadows-multidex:3.0-rc3" // otherwise robolectric tests fail on MultiDex.install

androidTestCompile ('com.android.support.test:rules:0.2') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}

androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {
exclude group: 'junit'
}

androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
exclude module: 'testing-support-lib'
exclude module: 'support-v4'
exclude module: 'support-annotations'
exclude group: 'javax.inject'
}

}

robolectric {
// Configure includes / excludes
include '**/*Test.class'
exclude '**/espresso/**/*.class'

// Configure max heap size of the test JVM
maxHeapSize = '2048m'

// Configure the test JVM arguments - Does not apply to Java 8
//jvmArgs '-XX:MaxPermSize=512m', '-XX:-UseSplitVerifier'

// Specify max number of processes (default is 1)
maxParallelForks = 4

// Specify max number of test classes to execute in a test process
// before restarting the process (default is unlimited)
forkEvery = 150

// configure whether failing tests should fail the build
ignoreFailures true

// use afterTest to listen to the test execution results
afterTest { descriptor, result ->
println "Executing test for ${descriptor.name} with result: ${result.resultType}"
}
}

现在我一直在试图弄清楚发生了什么,例如通过使用 ./gradlew -q app:dependencies 查看依赖关系,结果(以及其他内部配置):

androidJacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.7.4.201502262128

androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.7.4.201502262128
+--- org.jacoco:org.jacoco.core:0.7.4.201502262128
| \--- org.ow2.asm:asm-debug-all:5.0.1
+--- org.jacoco:org.jacoco.report:0.7.4.201502262128
| +--- org.jacoco:org.jacoco.core:0.7.4.201502262128 (*)
| \--- org.ow2.asm:asm-debug-all:5.0.1
\--- org.jacoco:org.jacoco.agent:0.7.4.201502262128


androidTestCompile - Classpath for compiling the androidTest sources.
+--- com.android.support.test:rules:0.2
| \--- com.android.support.test:runner:0.2
| +--- junit:junit-dep:4.10
| | \--- org.hamcrest:hamcrest-core:1.1
| \--- com.android.support.test:exposed-instrumentation-api-publish:0.2
+--- com.android.support.test:testing-support-lib:0.1
\--- com.android.support.test.espresso:espresso-core:2.0
+--- com.squareup:javawriter:2.1.1
+--- org.hamcrest:hamcrest-integration:1.1
| \--- org.hamcrest:hamcrest-core:1.1
+--- org.hamcrest:hamcrest-library:1.1
| \--- org.hamcrest:hamcrest-core:1.1
+--- com.android.support.test.espresso:espresso-idling-resource:2.0
+--- com.google.code.findbugs:jsr305:2.0.1
+--- javax.annotation:javax.annotation-api:1.2
\--- org.hamcrest:hamcrest-core:1.1


compile - Classpath for compiling the main sources.
+--- com.android.support:multidex:1.0.1
+--- com.auth0.android:lock:1.7.0
| +--- com.android.support:appcompat-v7:22.0.0 -> 22.1.1
| | \--- com.android.support:support-v4:22.1.1
| | \--- com.android.support:support-annotations:22.1.1
| +--- com.squareup:otto:1.3.5
| +--- com.auth0.android:identity-core:1.7.0
| | +--- com.hannesdorfmann.smoothprogressbar:library:1.0.0
| | +--- com.android.support:appcompat-v7:21.0.2 -> 22.1.1 (*)
| | \--- com.auth0.android:core:1.7.0
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.4.1
| | +--- com.fasterxml.jackson.core:jackson-core:2.4.1
| | +--- com.loopj.android:android-async-http:1.4.5
| | \--- com.fasterxml.jackson.core:jackson-databind:2.4.1
| | +--- com.fasterxml.jackson.core:jackson-annotations:2.4.0 -> 2.4.1
| | \--- com.fasterxml.jackson.core:jackson-core:2.4.1
| \--- com.auth0.android:core:1.7.0 (*)
+--- com.auth0.android:lock-googleplus:1.7.0
| +--- com.android.support:appcompat-v7:21.0.2 -> 22.1.1 (*)
| +--- com.auth0.android:identity-core:1.7.0 (*)
| \--- com.google.android.gms:play-services-plus:6.5.87 -> 7.3.0
| \--- com.google.android.gms:play-services-base:7.3.0
| \--- com.android.support:support-v4:22.0.0 -> 22.1.1 (*)
+--- com.android.support:appcompat-v7:22.1.1 (*)
+--- com.google.code.gson:gson:2.3.1
+--- com.squareup.picasso:picasso:2.1.1
+--- com.squareup.retrofit:retrofit:1.9.0
| \--- com.google.code.gson:gson:2.3.1
+--- com.squareup.okhttp:okhttp:2.4.0
| \--- com.squareup.okio:okio:1.4.0
+--- com.google.android.gms:play-services-plus:7.3.0 (*)
+--- io.reactivex:rxandroid:0.24.0
| \--- io.reactivex:rxjava:1.0.4
+--- com.amazonaws:aws-android-sdk-cognito:2.2.1
| \--- com.amazonaws:aws-android-sdk-core:2.2.1
| +--- commons-logging:commons-logging:1.1.1
| \--- com.google.code.gson:gson:2.2.4 -> 2.3.1
+--- com.amazonaws:aws-android-sdk-core:2.2.1 (*)
\--- com.amazonaws:aws-android-sdk-mobileanalytics:2.2.1
\--- com.amazonaws:aws-android-sdk-core:2.2.1 (*)


testCompile - Classpath for compiling the test sources.
+--- org.robolectric:robolectric:3.0-rc3
| +--- junit:junit:4.8.2
| +--- org.robolectric:robolectric-annotations:3.0-rc3
| +--- org.robolectric:robolectric-resources:3.0-rc3
| | +--- org.robolectric:robolectric-utils:3.0-rc3
| | | +--- org.robolectric:robolectric-annotations:3.0-rc3
| | | \--- com.google.android.apps.common.testing.accessibility.framework:accessibility-test-framework:1.0
| | +--- org.robolectric:robolectric-annotations:3.0-rc3
| | \--- com.ximpleware:vtd-xml:2.11
| +--- org.robolectric:robolectric-utils:3.0-rc3 (*)
| +--- org.robolectric:shadows-core:3.0-rc3
| | +--- org.robolectric:robolectric-annotations:3.0-rc3
| | +--- org.robolectric:robolectric-utils:3.0-rc3 (*)
| | +--- org.robolectric:robolectric-resources:3.0-rc3 (*)
| | +--- com.ibm.icu:icu4j:53.1
| | \--- com.almworks.sqlite4java:sqlite4java:0.282
| +--- org.bouncycastle:bcprov-jdk16:1.46
| +--- org.ow2.asm:asm:5.0.1
| +--- org.ow2.asm:asm-commons:5.0.1
| | \--- org.ow2.asm:asm-tree:5.0.1
| | \--- org.ow2.asm:asm:5.0.1
| +--- org.ow2.asm:asm-util:5.0.1
| | \--- org.ow2.asm:asm-tree:5.0.1 (*)
| +--- org.ow2.asm:asm-analysis:5.0.1
| | \--- org.ow2.asm:asm-tree:5.0.1 (*)
| +--- com.ximpleware:vtd-xml:2.11
| +--- org.apache.maven:maven-ant-tasks:2.1.3
| \--- org.apache.ant:ant:1.8.0
| \--- org.apache.ant:ant-launcher:1.8.0
\--- org.robolectric:shadows-multidex:3.0-rc3
\--- org.robolectric:robolectric:3.0-rc3 (*)

现在我的问题是,我该如何着手找出导致重复的原因?据我了解,它应该是某个库,其中包括另一个定义 InstrumentationRegistry 的库。

最佳答案

来自 Espresso 2.1 release notes :

“...测试运行器构件一分为二,名称从 com.android.support.test:testing-support-lib:0.1 更改为 com.android.support.test:runner:0.2 + com .android.support.test:rules:0.2...”

在您的依赖项中,您通过包含旧的 testing-support-lib 和新规则来混合两个测试运行器。

因此,您要么通过添加 runner:0.2 依赖项而不是旧的 support-lib 完全切换到新的测试运行器,要么选择不使用规则。

如果您想遵守规则,您的 androidTest 依赖项将如下所示:

androidTestCompile('com.android.support.test:rules:0.2') {
exclude module: 'support-v4'
exclude module: 'support-annotations'
}

androidTestCompile('com.android.support.test:runner:0.2') {
exclude module: 'support-annotations'
}

androidTestCompile('com.android.support.test.espresso:espresso-core:2.0') {
exclude module: 'testing-support-lib'
exclude module: 'support-v4'
exclude module: 'support-annotations'
exclude group: 'javax.inject'
}

关于android - Gradle 依赖 : How to figure out what's causing this duplication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30507934/

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