有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在安卓 studio中解决bulid gradle中的重复条目

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

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

我的构建梯度文件是:

apply plugin: 'com.安卓.application'
configurations {
   // all*.exclude group: 'com.安卓.support', module: 'support-v4'
   // all*.exclude group: 'com.安卓.support', module: 'support-annotations'
}
安卓 {
    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-安卓.txt'), 'proguard-rules.txt'
        }
    }

    aaptOptions {
        cruncherEnabled = false
    }

}

dependencies {
    //compile 'com.安卓.support:appcompat-v7:25.2.0'
    compile 'com.google.安卓.gms:play-services:+'
    compile files('libs/安卓-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/mp安卓chartlibrary-2-2-4.jar')
    compile files('libs/picasso-2.4.0.jar')
    compile files('libs/安卓-support-v4.jar')
    compile files('libs/安卓-support-v7-appcompat.jar')
   compile('org.eclipse.paho:org.eclipse.paho.安卓.service:1.0.2') {
        exclude module: 'support-v4' // exclude duplicate library
    }

}

共 (3) 个答案

  1. # 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'
    }
    
  2. # 2 楼答案

    java.util.zip.ZipException: duplicate entry: 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

  3. # 3 楼答案

    拆下电话线

    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/