Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: exclude a dependency's package

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.

like image 803
Frank Avatar asked Nov 30 '16 08:11

Frank


People also ask

How do you avoid transitive dependencies in Gradle?

You can tell Gradle to disable transitive dependency management for a dependency by setting ModuleDependency.

How do I exclude tasks in Gradle?

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.


1 Answers

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.

like image 176
Malcolm Avatar answered Sep 18 '22 16:09

Malcolm