Gradle:排除依赖包 [英] Gradle: exclude a dependency's package

查看:200
本文介绍了Gradle:排除依赖包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Android Gradle依赖项中排除 package ,以便它不会最终出现在APK中?

Is it possible to exclude a package from an Android Gradle dependency so it does not end up inside the APK?

As:

dependencies {

    compile('com.facebook.android:facebook-android-sdk:4.17.0') {
        exclude package 'com.facebook.share'
    }
}

但又有所不同,因为 package不是有效命令。

but then different, because "package" is not a valid command.

推荐答案

您不能排除工件的某些特定部分,因为Gradle对其内部的东西一无所知。要使它具有整体性,您可以:要么在工件内部包括工件,要么不在工件内部。

You can't exclude some specific parts of the artifact because Gradle doesn't know anything about what is inside it. To Gradle it's monolithic: you either include the artifact with whatever is inside it, or not.

使用ProGuard可能会实现所需的目标。这是构建应用程序的发行版时的常见步骤,您可以指定执行收缩的规则,这将删除不必要的代码。 Android文档中有代码收缩文章,其中包含更多详细信息。

It may be possible to achieve what you want using ProGuard. This is a common step when building a release version of the application, you can specify the rules to do shrinking, which will remove unnecessary code. Android documentation has a code shrinking article with more details.

可能出现的唯一问题是,如果依赖项本身包含ProGuard配置文件,则可能无法强制缩小指定保留在其中的文件。但是,我只是调查了您询问的AAR,事实并非如此。

The only problem that could arise is that if the dependency includes a ProGuard configuration file itself, then it may not be possible to force shrinking of what is specified to be kept in there. However, I've just looked into the AAR you asked about, and that doesn't seem to be the case.

这篇关于Gradle:排除依赖包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆