Gradle,如何从依赖jar文件中排除类/包?

时间:2015-10-28 20:14:42

标签: android jar android-gradle

我的主build.gradle文件中有Findbugs插件。为了阻止其投诉,我已将annotation.jarjsr305.jar添加到我的libs文件夹中,并且我在需要的地方使用@SuppressFBWarnings

我在尝试构建项目时遇到以下错误。:passenger -

app:dexTaxDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
    at com.android.dx.command.dexer.Main.run(Main.java:277)
    at com.android.dx.command.dexer.Main.main(Main.java:245)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':passenger-app:dexTaxDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 2

注意:我知道解决方案是激活multidex Building Apps with Over 65K Methods。我也不相信Progard :(

所以,我正在寻找一种方法,如果可能的话,从依赖的jar文件中排除一个类。我们有模块的东西似乎不适用于jar文件。

compile('com.google.android.gms:play-services-analytics:7.3.0') {
        exclude group: 'com.google.android.gms', module: 'play-services-base'
    }

我在主build.gradle档案中的内容

configure(allprojects) {
    apply plugin: 'findbugs'

    task findbugs(type: FindBugs) {
        ignoreFailures = false
        effort = "max"

        classes = fileTree('build/intermediates/classes/')
        source = fileTree('src/main/java')
        classpath = files()

        excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml")

        reportLevel = "high"
        reports {
            xml.enabled = false
            html.enabled = true
        }
    }
}

和我的依赖项目中的这些依赖项

dependencies {
    ....

    // Findbugs libs in order to surpass warnings
    compile files('src/main/libs/annotations.jar')
    compile files('src/main/libs/jsr305.jar')

    ....
}

任何建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试修改jar闭包,就像这个例子一样

project(':api:core') {

        dependencies {
                compile project(':api:schema')
                compile project(':api:util')
        }

        jar {
                baseName = 'core'
                dependsOn classes
                from sourceSets.main.classes
                exclude('net/intellidata/core/**/*Impl*')
        }

        task caaJar(type: Jar) {
                baseName = 'caa' 
                dependsOn classes 
                from sourceSets.main.classes
                include('net/intellidata/core/**/CAA*Impl*')
        }
}