如何从gradle Android Studio中的jar文件中删除单个模块

时间:2015-12-30 06:52:22

标签: android android-studio gradle

如何从jar文件中删除单个包。

the package hierarchy

我有来自不同供应商的两个SDK,并且两个SDK都包含在jar文件中的 google.gson 包,因为这导致我在android studio中运行构建的问题它显示错误图片

enter image description here

我知道如何从存储库中排除模块,如下所示:

compile('com.android.support:design:23.1.1') {
        exclude module: 'support-v4'
    }

但我不知道如何从我的应用程序中需要的jar文件中排除某些包。任何帮助将不胜感激。

MY GRADLE FILE:

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.1"
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'libs/SDK/com.google.gson'
    }


    defaultConfig {
        applicationId "**********"
        minSdkVersion 16
        targetSdkVersion 21
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }

    }
    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }

}

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

dependencies {
    compile('com.facebook.android:facebook-android-sdk:4.1.0') {
        exclude module: 'support-v4'
    }
    compile('org.twitter4j:twitter4j-core:4.0.2') {
        exclude module: 'support-v4'
    }
    compile('com.android.support:design:22.2.0') {
        exclude module: 'support-v4'
    }
    compile files('libs/FlurryAnalytics-5.3.0.jar')
    compile files('libs/gcm.jar')
    compile('com.android.support:design:23.1.1') {
        exclude module: 'support-v4'
    }
    compile files('libs/SDK.jar')

    compile project(':volley')
    compile project(':viewPagerIndicator')
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.squareup.picasso:picasso:2.5.0'
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
    compile 'com.android.support:support-v4:23.1.0'
    compile project(':android-country-picker-master')
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'javax.annotation:javax.annotation-api:1.2'
}

1 个答案:

答案 0 :(得分:1)

我意识到你做了类似的事情,但我想补充说你可以使用Asterisks,这只是一个旧项目的片段:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'com.android.support:cardview-v7:21.0.3'
    compile 'com.android.support:support-v4:22.2.0'
    compile('com.google.android.gms:play-services:7.3.0') {
        exclude group: "com/google/android/gms/location/**"
        exclude group: "com/google/android/gms/wearable/**"
        exclude group: "com/google/android/gms/maps/**"
        exclude group: "com/google/android/gms/games/**"
        exclude group: "com/google/android/gms/plus/**"
        exclude group: "com/google/android/gms/drive/**"
        exclude group: "com/google/android/gms/panorama/**"
        exclude group: "com/google/android/gms/wallet/**"
        exclude group: "com/google/android/gms/tagmanager/**"
        exclude group: "com/google/android/gms/fitness/**"
        exclude group: "com/google/android/gms/security/**"
        exclude group: "com/google/android/gms/identity/**"
    }
    compile 'com.github.amlcurran.showcaseview:library:5.0.0'
}

另外只是为了澄清你应该从其中一个包中排除gson,因为你有一个重复的gson依赖。

exclude module: 'gson';