Reputation: 12300
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.
Upvotes: 9
Views: 19481
Reputation: 401
Updated answer for excluding reference libraries from your dependency groups
implementation (group: 'net.sf.jasperreports', name: 'jasperreports', version: '6.1.0'){
//example : org.olap4j:olap4j:0.9.7.309-JS-3
exclude group: 'org.olap4j', module: 'olap4j'
}
Upvotes: 0
Reputation: 3584
You can use sourceSets inside your build.gradle to filter the packages or classes you don't want to bundle in your apk or aab. For example -
android {
sourceSets {
main {
java {
exclude 'com/a/b/helper/**'
exclude 'com/a/ext/util/TestUtils.java'
}
}
}
}
Hope it will help :)
Upvotes: 1
Reputation: 41510
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.
Upvotes: 1
Reputation: 990
in this way , u can exclude few packages from the library, this is just a example of concept
compile ('com.github.ganfra:material-spinner:1.1.1'){
exclude group: 'com.nineoldandroids', module: 'library'
exclude group: 'com.android.support', module: 'appcompat-v7'
}
Upvotes: 0