Duplicate Entry Error - Dependancy and Project Module Confliction - Android

你离开我真会死。 提交于 2019-12-25 04:40:33

问题


First of all. Below is the error that I am getting.

Now, What I am doing is like below....

I am integrating Speech To Text service of IBM. I have founded a demo HERE!

I am also using another two Services of IBM named Personality Insights and Cloudant Database.

I have successfully integrated Speech To Text example. But When I integrate Personality Insights and Cloudant Database it gives me above error.

WHAT I HAVE IDENTIFIED:

  • In STT demo there is a module called speech-android-wrapper.
  • Which I have included to my app and added a line to *build.gradle** file like compile project(':speech-android-wrapper').
  • For Cloudant Database service I have dependency like compile group: 'com.cloudant', name: 'cloudant-sync-datastore-android', version: 'latest.release'.
  • When I comment Cloudant Database dependency. It won't give me above error.
  • So, Some where these two dependencies are being conflicts.

Below is my Application's build.gradle file.

build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

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

    defaultConfig {
        multiDexEnabled true
        applicationId "com.stt_int.android01.sttdemofour"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    // ... other project repositories
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile project(':speech-android-wrapper')
    compile 'com.facebook.android:facebook-android-sdk:4.7.+'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    /*compile('com.mopub:mopub-sdk:4.3.0@aar') {
        transitive = true
    }*/
    compile('com.twitter.sdk.android:twitter:1.13.0@aar') {
        transitive = true;
    }
    compile 'com.ibm.watson.developer_cloud:java-sdk:2.6.0'
    compile group: 'com.cloudant', name: 'cloudant-sync-datastore-android', version: 'latest.release'
}

Below is speech-android-wrapper module's build.gradle file

apply plugin: 'com.android.library'

android {
    compileSdkVersion 21
    buildToolsVersion '22.0.1'
    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 16
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile files('libs/java_websocket.jar')
    compile files('libs/commons-io-2.4.jar')
    compile files('libs/jna.jar')
}

I have try to exclude ByteOrderMark.class class using below code but I can not get desire outcome.

android { packagingOptions { exclude 'org/apache/commons/io/ByteOrderMark.class' } }

Any help will be very very very appreciated. Thanks!!

Update-1: Dated: 28.03.2016

I have tried like below from two links suggested by @Nikolay Shmyrev but none of links worked for me.

From 1st link.
dependencies { compile files('libs/java_websocket.jar') //compile files('libs/commons-io-2.4.jar') compile('commons-io:commons-io:2.4') { exclude group: 'org.apache', module: 'commons-io' } compile files('libs/jna.jar') }

From 2nd link.
dependencies { compile files('libs/java_websocket.jar') //compile files('libs/commons-io-2.4.jar') compile('commons-io:commons-io:2.4') { exclude group: 'org.apache.commons.io' } compile files('libs/jna.jar') }
I have removed commons-io-2.4.jar file from libs folder of speech-android-wrapper module.

Update-2: Dated: 29.03.2016

I have tried below too.

dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.0' compile project(':speech-android-wrapper') compile 'com.facebook.android:facebook-android-sdk:4.7.+' compile 'com.mcxiaoke.volley:library:1.0.19' /*compile('com.mopub:mopub-sdk:4.3.0@aar') { transitive = true }*/ compile('com.twitter.sdk.android:twitter:1.13.0@aar') { transitive = true; } compile 'com.ibm.watson.developer_cloud:java-sdk:2.6.0' compile(group: 'com.cloudant', name: 'cloudant-sync-datastore-android', version: 'latest.release') { exclude group: 'org.apache', module: 'commons-io' } }

Below also..

dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.0' compile project(':speech-android-wrapper') compile 'com.facebook.android:facebook-android-sdk:4.7.+' compile 'com.mcxiaoke.volley:library:1.0.19' /*compile('com.mopub:mopub-sdk:4.3.0@aar') { transitive = true }*/ compile('com.twitter.sdk.android:twitter:1.13.0@aar') { transitive = true; } compile 'com.ibm.watson.developer_cloud:java-sdk:2.6.0' compile(group: 'com.cloudant', name: 'cloudant-sync-datastore-android', version: 'latest.release') { exclude group: 'org.apache.commons.io' } }

to my project's build.gradle file. While I have changed my project's build.gradle file, build.gradle file of speech-android-wrapper look like below.

dependencies { compile files('libs/java_websocket.jar') //compile files('libs/commons-io-2.4.jar') compile 'commons-io:commons-io:2.4' compile files('libs/jna.jar') }

But nothing works for me.


回答1:


I am not sure that it can work.

The issue happens because you are adding the same class (org/apache/commons/io/ByteOrderMark.class) twice.

If you checking the pom file of the com.cloudant:cloudant-sync-datastore-android library you will find this dependency:

commons-io:commons-io:2.4

In your speech-android-wrapper module you can:

  • remove the commons-io-2.4.jar from the libs folder
  • change the dependencies in the build.gradle removing the line compile files('libs/commons-io-2.4.jar') and adding compile commons-io:commons-io:2.4



回答2:


I found the solution, as one can exclude some group my following line.

configurations { all*.exclude group: 'commons-io' }

I have added above line error disappears.



来源:https://stackoverflow.com/questions/36235955/duplicate-entry-error-dependancy-and-project-module-confliction-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!