【问题标题】:how to exclude module in build.gradle(Module app)?如何在 build.gradle(模块应用程序)中排除模块?
【发布时间】:2017-05-22 15:42:09
【问题描述】:

我需要排除第三方库 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 文件中的特定类。如果有任何其他方法可以做到这一点,请提出建议。提前致谢。

【问题讨论】:

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


    【解决方案1】:

    检查此postthis。两者都说您需要在sourceSets 中添加排除类名称。

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

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

    【讨论】:

    • 我检查了两个链接,但在我的情况下,我需要排除外部 jar 库中存在的“xxyyzz.class”。我尝试了类似 sourceSets { app { libs { exclude 'java/xml/stream/XMLConstants/**' } } } 的东西仍然出错。
    • 感谢@Somnath Pal,我仍然收到重复的类错误。这是我的库路径 C:\Users\Xyz\abc\WORK SPACE\MyApplication\app\libs 并且要排除的类是“XMLConstants.class”
    • 您可能会收到重复错误,因为您在 lib 文件夹中添加了两个类似的 jar 文件。就像添加 org.apache.legacy.jar 和 httpcore.jar 一样,在构建时会出现重复错误。我看到你已经包含了javax.xml.stream.jarjavax.xml.bind.jar。错误可能是由于这两个造成的。
    • 是的,我面临的问题完全相同。我有两个罐子,里面有两个相同的类。如果我删除任何一个库,我会收到导入错误。问题是我需要两个库来支持我的项目。你能帮我吗?
    • 告诉我你需要导入哪个类,我会检查是否可以删除。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 2016-04-26
    • 2017-12-10
    • 2021-12-17
    • 1970-01-01
    • 2019-02-24
    相关资源
    最近更新 更多