3
packagingOptions {
 exclude 'org/apache/commons/codec/language/bm/gen_approx_portuguese.txt'
}

For example, this one will exclude 1 file. But how to exclude all file under a directory?

like: org/apache/commons/codec/language/bm/
folder? . does not work :)

Mahozad
  • 18,032
  • 13
  • 118
  • 133
Meng Tim
  • 408
  • 1
  • 6
  • 19
  • Possible duplicate of [Gradle 1.2: Exclude directory under resources sourceSets](http://stackoverflow.com/questions/12617827/gradle-1-2-exclude-directory-under-resources-sourcesets) Although this is source sets it still relates to using the exclude functionality. – Mr00Anderson May 17 '16 at 18:42
  • this does not work for me. I tried this. Is there any difference between packaging option and source set? Actually it gives me a lot of Duplicate files copied in APK xxxxxx, so I try to exclude the duplicate files. but there are too files under the same directory. So I try to exclude them all. – Meng Tim May 17 '16 at 18:48

2 Answers2

13

wild card can be used to enforce action to multiple file in directory. See this:-

packagingOptions {
 exclude 'org/apache/commons/codec/language/bm/*'
}

You can also exclude a file/directory with out specifying the full path this way:-

packagingOptions {
    exclude '**/language/bm/*'
}

Note: this will exclude any language/bm/ any where in the path

ambes
  • 5,272
  • 4
  • 26
  • 36
0

This is for Kotlin DSL (build.gradle.kts) and AGP (Android Gradle Plugin) version 7.0.0 and newer:

android {
  // ...
  packagingOptions {
    resources.excludes += "org/apache/commons/codec/language/bm/*"
    // OR
    // resources.excludes += setOf(
    //   "org/apache/commons/codec/language/bm/*"
    // )
  }
}
Mahozad
  • 18,032
  • 13
  • 118
  • 133