How to remove single module from the jar file in gradle Android Studio

╄→гoц情女王★ 提交于 2021-01-27 11:39:52

问题


How can i remove the single package from the jar file.

I have two SDK's from diffent vendors and both the SDK's have google.gson package included in the jar files, because this causing me the issue in running a build in android studio it shows the error in image below

i know how to exclude the modules from the repository like this:

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

but i don't know how to exclude some package from the jar file that i need in my application. Any help would be appreciated.

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:


I realize that you did something similar to this but i would like to add that you can use Asterisks, this is just a snippet from an old project:

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'
}

Also just to clarify you should be excluding gson from one of the packages since you have a duplicate gson dependency.

exclude module: 'gson';


来源:https://stackoverflow.com/questions/34524437/how-to-remove-single-module-from-the-jar-file-in-gradle-android-studio

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