【问题标题】:Two modules use same library in Android Studio两个模块在 Android Studio 中使用相同的库
【发布时间】:2016-05-17 08:15:03
【问题描述】:

我有一个 android studio 项目包含两个使用相同库 (jsoup) 的模块。当我编译应用程序时,它会显示

错误:任务执行失败 ':app:transformResourcesWithMergeJavaResForDebug'。 > com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException:重复文件 复制到 APK META-INF/maven/org.jsoup/jsoup/pom.xml File1 中: C:\Users\G.gradle\caches\modules-2\files-2.1\org.jsoup\jsoup\1.8.2\64238922c4006c3d0a9951c4c03983ecc6a1e1a0\jsoup-1.8.2.jar 文件2: C:\Users\G\AndroidStudioProjects\twrb\app\build\intermediates\exploded-aar\twrb\webviewtimetablesearcher\unspecified\jars\classes.jar

两个模块在build.gradle中的依赖关系如下图。

dependencies {
    compile 'org.jsoup:jsoup:1.8.2'
}

这是 app 的 build.gradle。

dependencies {
    compile project(':moduleA')
    compile project(':moduleB')
}

如何解决?谢谢。


这是我的整个 build.gradle 应用程序

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.test.tmp"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/maven/org.jsoup/jsoup/pom.xml'
        exclude 'org/jsoup/nodes/entities-base.properties'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'me.tatarka:gradle-retrolambda:3.2.4'
    }
}

// Required because retrolambda is on maven central
repositories {
    mavenCentral()
}

apply plugin: 'com.android.application' //or apply plugin: 'java'
apply plugin: 'me.tatarka.retrolambda'

dependencies {
    compile 'com.android.support:support-v4:23.2.1'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'io.realm:realm-android:0.87.5'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'io.reactivex:rxandroid:1.1.0'
    compile 'io.reactivex:rxjava:1.1.0'
    compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
    testCompile 'junit:junit:4.12'
    androidTestCompile 'junit:junit:4.12'
    compile project(':moduleA')
    compile project(':moduelB')
}

【问题讨论】:

    标签: android android-studio gradle module libraries


    【解决方案1】:

    为了解决它,你必须添加

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

    build.gradle

    【讨论】:

    • 感谢您的回复。但重复文件是 META-INF/maven/org.jsoup/jsoup/pom.xml。我试过“排除”,但显示了另一个重复文件:org/jsoup/nodes/entities-base.properties。如果我排除它将不起作用。所以我搜索其他解决方案来解决这个问题。
    • 发布您的 build.gradle 应用程序。
    • 在你的 moduleA 和 moduleB 的 build.gradle 中写上我的答案代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多