user268397
user268397

Reputation: 1927

Android - Duplicate Entry Error - How do I use one class from one JAR file when it exists in two JAR files without running into this error?

How do I get my code to use only one class from one JAR file when the same class from two JAR files exist in the files ormlite-android-4.6.jar & ormlite-core-4.45.jar without running into this error?

Here is a copy of my build.gradle file:

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.android.engineering"
    minSdkVersion 16
    targetSdkVersion 21
    multiDexEnabled true
}

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

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
}

dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.2.4'
compile 'joda-time:joda-time:2.0'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/butterknife-5.1.2.jar')
compile files('libs/com.google.guava_1.6.0.jar')
compile files('libs/com.springsource.org.junit-4.10.0.jar')
compile files('libs/commons-collections-3.2.1.jar')
compile files('libs/dagger-1.1.0.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/opencsv-3.3.jar')
compile files('libs/ormlite-android-4.6.jar')
compile files('libs/ormlite-core-4.45.jar')
compile files('libs/log4j-1.2.16.jar')
compile files('libs/icepick-2.3.jar')
compile files('libs/mockito-core-1.9.5.jar')
}

Here is the error I get:

   :app:packageAllDebugClassesForMultiDex FAILED

   FAILURE: Build failed with an exception.

The code I think is trying to use BaseDaoImpl.class which both exists in package com.j256.ormlite.dao.BaseDaoImpl in both ormlite-android-4.6.jar & ormlite-core-4.45.jar. How do I get it to use one class from one JAR file without running into this error?

Upvotes: 2

Views: 3083

Answers (2)

Ajay
Ajay

Reputation: 4971

You can use

   compile ("net.danlew:android.joda:2.9.0") {
        exclude group: 'org.joda.time'
    }

or to exclude module use

compile ("net.danlew:android.joda:2.9.0") {
    exclude module: 'jode-time'
}

Upvotes: 3

AndroidGuy
AndroidGuy

Reputation: 3451

Run "gradlew dependencies" which will allow you to see all the libraries. You can use the "exclude" directive to remove duplicate libraries.

Look here to read more about the exclude directive: https://gradle.org/docs/current/userguide/dependency_management.html#sub:exclude_transitive_dependencies

Upvotes: 0

Related Questions