项目依赖关系中的jar已经添加到Android的“输出”错误

前端之家收集整理的这篇文章主要介绍了项目依赖关系中的jar已经添加到Android的“输出”错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 Android项目,使用gradle与另一个项目作为依赖.依赖项目有一个库jar.当我尝试编译的项目库被编译了两次,我得到错误
错误:类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类被发现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

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

编辑#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文件.

我做了总指挥官.脚步:

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

猜你在找的设计模式相关文章