在项目依赖项中,jar"已添加到输出"错误

Stp*_*tpn 13 dependencies android gradle android-studio

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

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

>ProjectRoot
  >dFULibrary
    >libs
      -nrf-logger-v2.0.jar
    -build.gradle
  >Logger
    -build.gradle
Run Code Online (Sandbox Code Playgroud)

这是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')
}
Run Code Online (Sandbox Code Playgroud)

这是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')
}
Run Code Online (Sandbox Code Playgroud)

no.nordicsemi.android.log.LogContract.Application类是找到的nrf-logger-v2.0.jar为什么它被包含两次,我怎么能确定它没有?

加成

这是../gradlew依赖关系返回的内容:

_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
Run Code Online (Sandbox Code Playgroud)

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

从./gradlew androidDependencies 编辑#2输出

: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
Run Code Online (Sandbox Code Playgroud)

gio*_*gio 7

宾果,发现它.

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

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

我做了那个Total Commander.脚步:

  • 重命名nrf-logger-v2.0.jarnrf-logger-v2.0.zip;
  • 进去并删除所有.java文件;
  • 将文件重命名为jar ;
  • gradlew clean build或Android Studio上的Build-Rebuild项目