Reputation: 859
I've checked lots of posts on stackoverflow, none of them worked so far. So I have an APK that depends on a bunch of AARs, one of the AAR has 10 audio files that I do not need. Since I can't remove the dependency directly because I need some APIs in it, I want to make sure those audio fils don't get built into the APK.
The way I check if audio files get built into or not is by running this command:
zipinfo MyApk.apk | grep .mp3
Does anyone know how to exclude these audio fils from my dependency AARs?
Upvotes: 3
Views: 2922
Reputation: 8190
This is what I used to exclude few files in AAR
:
final List<String> exclusions = [];
Dependency.metaClass.exclude = { String[] currentExclusions ->
currentExclusions.each {
exclusions.add("${getGroup()}/${getName()}/${getVersion()}/${it}")
}
return thisObject
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile ('com.android.support:appcompat-v7:20.+')
debugCompile ('com.squareup.leakcanary:leakcanary-android:1.3.1')
.exclude("res/values-v21/values-v21.xml")
releaseCompile ('com.squareup.leakcanary:leakcanary-android-no-op:1.3.1')
}
tasks.create("excludeTask") << {
exclusions.each {
File file = file("${buildDir}/intermediates/exploded-aar/${it}")
println("Excluding file " + file)
if (file.exists()) {
file.delete();
}
}
}
tasks.whenTaskAdded({
if (it.name.matches(/^process.*Resources$/)) {
it.dependsOn excludeTask
}
})
You can check this Original Answer here
Upvotes: 1