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

标签 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 文件中排除某些包。任何帮助将不胜感激。

我的 GRADLE 文件:

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

最佳答案

我知道你做了类似的事情,但我想补充一点,你可以使用 Asterisks,这只是一个旧项目的 fragment :

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

关于android - 如何从 gradle Android Studio 中的 jar 文件中删除单个模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34524437/

相关文章:

android - 如何围绕 20 分钟的 http session 构建我的 android 应用程序

android - Android 中基于字段查询 Firebase 并返回父级

android - 如何安装旧版本的 Android Studio

android - apache中的StringUtils.rightPad()在android中抛出NoSuchMethodError

android - Android 服务内的计时器

java - 从 RecyclerAdapter 使用异步任务时出错

maven - 添加 Maven 存储库而不需要索引

Android Studio Gradle 2.0.0-alpha1 构建错误

用于 Jenkins 的 Android Studio : How to create build. gradle 文件?

android - 设置我自己的库以供任何人作为依赖项包含在内