加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 00:47:49 所属栏目:百科 来源:网络整理
导读:我有一个 Android项目,使用gradle与另一个项目作为依赖.依赖项目有一个库jar.当我尝试编译的项目库被编译了两次,我得到错误: 错误:类no.nordicsemi.android.log.LogContract.Application已经添加到输出.请删除重复的副本. 这是与文件有关的文件夹结构: Pr
我有一个 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项目瞧瞧

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读