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'
}
}
but then different, because "package" is not a valid command.
You can tell Gradle to disable transitive dependency management for a dependency by setting ModuleDependency.
You can exclude a task from being executed using the -x or --exclude-task command-line option and providing the name of the task to exclude.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With