2

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?

Zip
  • 809
  • 2
  • 14
  • 30

1 Answers1

1

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

Kingfisher Phuoc
  • 8,052
  • 9
  • 46
  • 86
  • is there any way to exclude files list passed in environment variable? https://stackoverflow.com/questions/46543271/how-to-exclude-files-from-aar-with-gradle-dynamically – 4ntoine Oct 12 '17 at 08:59