Duplicate Entry in Android Studio

元气小坏坏 提交于 2019-12-24 05:40:10

问题


I am able to build the Project successfully in Android Studio but when I am trying to run the application getting error like this "duplicate entry: android/support/v4/print/PrintHelper$1.class.",I have searched lot of sites and tried lot of suggestions but failed.Please help me..below is my code.I was struggled 2 days for this.

 apply plugin: 'com.android.application'
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':appcompat_v7')
    compile project(':google-play-services_lib')
    compile project(':Cognalys')
    //noinspection GradleDynamicVersion
    compile 'com.android.support:recyclerview-v7:22.2.+'
}
android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc3"
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    defaultConfig {
        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
       release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

回答1:


I meet the same error, and I solve it, but I just give u that my case;

my bulid.gradle:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile ('com.android.support:appcompat-v7:22.0.0') 
    compile files('libs/android-async-http-1.4.8.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/universal-image-loader-1.9.4-with-sources.jar')
}

the error for is the com.android.support:appcompat-v7:22.0.0 include the support-v4.jar, so I remove it;

solve build.gradle:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile ('com.android.support:appcompat-v7:22.0.0') {
        exclude module: 'support-v4'
    }
    compile files('libs/android-async-http-1.4.8.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/universal-image-loader-1.9.4-with-sources.jar')
}

so maybe u should check ur dependencies, maybe ur compile files have two files include support-v4




回答2:


This question is that "duplicate entry " ,when ".java" become ".class" different jar maybe have the same class, your project maybe depend on many different libs which may have many jars ,so the key to solve this error is that avoid duplicate jar,as much as possible use online depend on not local jars,all this things can config in your gradle

for example: compile files('libs/com.nostra13.universalimageloader:universal-image-loader:1.9.5') need to change to compile'com.nostra13.universalimageloader:universal-image-loader:1.9.5'.

If you have to use a local jar, please make sure that in your prject and the libs that project depends on they share one jar.



来源:https://stackoverflow.com/questions/32007296/duplicate-entry-in-android-studio

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