如何在build.gradle(模块应用程序)中排除模块?

时间:2017-01-08 06:17:29

标签: java android android-studio jar build.gradle

我需要排除第三方库jar文件中存在的类。我不知道排除组的确切语法格式。我尝试使用以下语法在库“javax.xml.stream.jar”中排除名为XMLConstants.class的类。

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/xsdlib-1.5.jar')
compile files('libs/relaxngDatatype-2.2.jar')
compile files('libs/javax.xml.stream.jar'){
    exclude module: 'javax-xml-stream'
}
compile files('libs/pull-parser-2.jar')
compile files('libs/javax.xml.bind.jar')
compile files('libs/java-rt-jar-stubs-1.5.0.jar')
compile files('libs/jaxen-core.jar')
compile files('libs/jaxen-dom4j.jar')
compile files('libs/jaxen-1.1-beta-2.jar')
}

如果我使用此语法,则会收到以下错误。

Error:(52, 0) Could not find method exclude() for arguments [{module=javax-   
xml-stream-XMLConstants}] 

我是android的新手,所以我需要知道如何编写一个语法来排除第三方库jar文件中的特定类。如果有任何其他方法,请建议。提前谢谢。

1 个答案:

答案 0 :(得分:0)

检查此post以及this。两者都表示您需要在sourceSets内添加排除类名称。

编辑:像这样试试吧。编译时我没有遇到任何错误。

sourceSets {
        main {
            java {
                srcDir 'libs'
                exclude 'org.apache.http.protocol.RequestDate.class'
            }
        }
    }

相关问题