I have an Android project that uses gradle with another project as dependency. Dependency project has a library jar. When I try to compile the project library is compiled twice and I get error: Error:Class no.nordicsemi.android.log.LogContract.Application has already been added to output. Please remove duplicate copies.
Here is the folder structure with files in question:
>ProjectRoot
>dFULibrary
>libs
-nrf-logger-v2.0.jar
-build.gradle
>Logger
-build.gradle
This is build.gradle for dFULibrary dependency:
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')
}
This is build.gradle for Logger (main project):
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 Why is it being included twice and how can I make sure it does not?
ADDITION
Here is what ../gradlew dependencies return:
_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
I removed all the lines that had no dependencies.
EDIT #2 output from ./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
Bingo, found it.
Just was interesting and I tried to find your project at Internet. And started my investigation .... :).
The problem is hidden at nrf-logger-v2.0.jar
. It contains .java and .class files.
Solution is to remove all .java files from it.
I did that Total Commander. Steps:
nrf-logger-v2.0.jar
into nrf-logger-v2.0.zip
;gradlew clean build
or Build-Rebuild project at Android StudioIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With