gpt4 book ai didi

项目依赖中jar的Android "has already been added to output"错误

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:26:49 27 4
gpt4 key购买 nike

我有一个 Android 项目,它使用 gradle 和另一个项目作为依赖项。依赖项目有一个库 jar。当我尝试编译项目库时,编译了两次,但出现错误: 错误:Class no.nordicsemi.android.log.LogContract.Application 已经添加到输出中。请删除重复的副本。

这是包含相关文件的文件夹结构:

>ProjectRoot
>dFULibrary
>libs
-nrf-logger-v2.0.jar
-build.gradle
>Logger
-build.gradle

这是 dFULibrary 依赖的 build.gradle:

apply plugin: 'com.android.library'

android {
compileSdkVersion 19
buildToolsVersion "19.1.0"

defaultConfig {
applicationId "no.nordicsemi.android.dfu"
minSdkVersion 18
targetSdkVersion 19
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile 'com.android.support:support-v4:+'
compile files('libs/nrf-logger-v2.0.jar')
}

这是 Logger 的 build.gradle(主要项目):

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.4'
}
}

apply plugin: 'com.android.application'

android {

compileSdkVersion 20
buildToolsVersion '20'

sourceSets {
main {
java.srcDirs "src/main/java"
res.srcDirs "src/main/res"
assets.srcDirs = ['assets']
}
androidTest.setRoot('tests')
androidTest.java.srcDirs = ['tests/src']

}
dexOptions {
preDexLibraries = false
}
}

dependencies {
compile 'com.android.support:support-v4:+'
compile project':dFULibrary')
}

no.nordicsemi.android.log.LogContract.Application class is found of nrf-logger-v2.0.jar 为什么它被包含两次,我如何确保它没有被包含?

添加

这是 ../gradlew dependencies 返回的内容:

_debugApk - ## Internal use, do not manually configure ##
\--- project :dFULibrary

_debugCompile - ## Internal use, do not manually configure ##
+--- project :dFULibrary
\--- com.android.support:support-v4:+ -> 21.0.2
\--- com.android.support:support-annotations:21.0.2

_releaseApk - ## Internal use, do not manually configure ##
\--- project :dFULibrary

_releaseCompile - ## Internal use, do not manually configure ##
+--- project :dFULibrary
\--- com.android.support:support-v4:+ -> 21.0.2
\--- com.android.support:support-annotations:21.0.2

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

androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.7.1.201405082137 FAILED


compile - Classpath for compiling the main sources.
\--- project :dFULibrary


provided - Classpath for only compiling the main sources.
\--- com.android.support:support-v4:+ -> 21.0.2
\--- com.android.support:support-annotations:21.0.2

我删除了所有没有依赖关系的行。

编辑 #2 来自 ./gradlew androidDependencies 的输出

:DFULibrary:androidDependencies
debug
\--- LOCAL: nrf-logger-v2.0.jar

debugTest
+--- LOCAL: nrf-logger-v2.0.jar
\--- debug
\--- LOCAL: nrf-logger-v2.0.jar

release
\--- LOCAL: nrf-logger-v2.0.jar
:nRFToolbox:androidDependencies
debug
+--- LOCAL: achartengine-1.1.0.jar
\--- nrfToolbox:DFULibrary:unspecified
\--- LOCAL: nrf-logger-v2.0.jar

debugTest
No dependencies

release
+--- LOCAL: achartengine-1.1.0.jar
\--- nrfToolbox:DFULibrary:unspecified
\--- LOCAL: nrf-logger-v2.0.jar

BUILD SUCCESSFUL

最佳答案

宾果游戏,找到了。

只是很有趣,我试图找到 your project在互联网上。并开始我的调查.... :)。

问题隐藏在 nrf-logger-v2.0.jar 中。它包含.java.class 文件。解决方案是从中删除所有 .java 文件。

我做了那个 Total Commander。步骤:

  • nrf-logger-v2.0.jar重命名为nrf-logger-v2.0.zip;
  • 进入并删除所有 .java 文件;
  • 将文件重命名回jar
  • gradlew clean buildBuild-Rebuild project at Android Studio

关于项目依赖中jar的Android "has already been added to output"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27242331/

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