【问题标题】:how to resolve duplicate entry in bulid gradle in android studio如何解决android studio中build gradle中的重复条目
【发布时间】:2018-03-21 19:10:57
【问题描述】:

我正在尝试将 eclipse 项目导入 android studio。之后将我的 jar 文件(即支持 jar)添加到 build gradle 文件中,无论我在 eclipse 中使用过什么。这样做时会低于错误。

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class

我的构建 gradle 文件是:

apply plugin: 'com.android.application'
configurations {
   // all*.exclude group: 'com.android.support', module: 'support-v4'
   // all*.exclude group: 'com.android.support', module: 'support-annotations'
}
android {
    compileSdkVersion 25
    buildToolsVersion "26.0.0"

    useLibrary  'org.apache.http.legacy'
    defaultConfig {
        applicationId "com.xxx.xxxxx"
        minSdkVersion 19
        targetSdkVersion 25
        multiDexEnabled true
    }

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

    aaptOptions {
        cruncherEnabled = false
    }

}

dependencies {
    //compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/android-query-full.0.26.7.jar')
    compile files('libs/commons-httpclient-3.0.1.jar')
    compile files('libs/glide-3.6.1.jar')
    compile files('libs/httpmime-4.1.3.jar')
    compile files('libs/library-1.2.1.jar')
    compile files('libs/mpandroidchartlibrary-2-2-4.jar')
    compile files('libs/picasso-2.4.0.jar')
    compile files('libs/android-support-v4.jar')
    compile files('libs/android-support-v7-appcompat.jar')
   compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
        exclude module: 'support-v4' // exclude duplicate library
    }

}

【问题讨论】:

  • 我被困在这里了。请帮帮我

标签: java android eclipse


【解决方案1】:

将下面的代码放在buildTypes重建再次项目

    packagingOptions {
    exclude 'META-INF/NOTICE' // will not include NOTICE file
    exclude 'META-INF/LICENSE' // will not include LICENSE file
    exclude 'META-INF/DEPENDENCIES' // will not include LICENSE file
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}

【讨论】:

  • 在 build.gradle ...在 buildTypes 标签下
【解决方案2】:

删除线

compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
    exclude module: 'support-v4' // exclude duplicate library
} 

并添加这一行

compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support:support-v4:25.4.0'
compile org.eclipse.paho:org.eclipse.paho.android.service:1.0.2

在 android{ }

中也添加这个
repositories {
    mavenCentral()
}

欲了解更多信息,请查看此链接 https://www.eclipse.org/paho/clients/android/

【讨论】:

  • 我试过这个..不工作..给我任何其他解决方案
  • 如果我替换这个给出另一个错误..安装存储库和同步项目
【解决方案3】:

java.util.zip.ZipException:重复条目: android/support/v4/database/DatabaseUtilsCompat.class

问题

  • exclude module: 'support-v4'

不要

compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') {
    exclude module: 'support-v4' // exclude duplicate library
}

你应该使用

compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.android.service', version: '1.0.2'

如果出现问题,请将其添加到您的 build.gradle 部分

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }

然后Clean-Rebuild-Run

【讨论】:

  • @Durga 添加packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' }
  • @Durga 内 android { ...}
  • @Durga stackoverflow.com/questions/22467127/… 。希望这对你有帮助。
  • @Durga 请告诉我。
  • 我正在尝试用你的链接解决.. bt 它给出的结果是一样的.. 我在代码中犯的任何其他错误???
猜你喜欢
  • 2019-09-25
  • 1970-01-01
  • 2019-12-20
  • 1970-01-01
  • 1970-01-01
  • 2021-09-14
  • 2021-06-02
  • 2015-11-07
相关资源
最近更新 更多