DSL object for configuring APK packaging options.
Packaging options are configured with three sets of paths: first-picks, merges and excludes:
- First-pick
- Paths that match a first-pick pattern will be selected into the APK. If more than one path matches the first-pick, only the first found will be selected.
- Merge
- Paths that match a merge pattern will be concatenated and merged into the APK. When merging two files, a newline will be appended to the end of the first file, if it doesn't end with a newline already. This is done for all files, regardless of the type of contents.
- Exclude
- Paths that match an exclude pattern will not be included in the APK.
To decide the action on a specific path, the following algorithm is used:
- If any of the first-pick patterns match the path and that path has not been included in the FULL_APK, add it to the FULL_APK.
- If any of the first-pick patterns match the path and that path has already been included in the FULL_APK, do not include the path in the FULL_APK.
- If any of the merge patterns match the path and that path has not been included in the APK, add it to the APK.
- If any of the merge patterns match the path and that path has already been included in the FULL_APK, concatenate the contents of the file to the ones already in the FULL_APK.
- If any of the exclude patterns match the path, do not include it in the APK.
- If none of the patterns above match the path and the path has not been included in the APK, add it to the APK.
- Id none of the patterns above match the path and the path has been included in the APK, fail the build and signal a duplicate path error.
Patterns in packaging options are specified as globs following the syntax in the
Java Filesystem API. All paths should be configured using forward slashes (/
).
All paths to be matched are provided as absolute paths from the root of the apk archive. So,
for example, classes.dex
is matched as /classes.dex
. This allows defining
patterns such as **/foo
to match the file foo
in any directory,
including the root. Any pattern that does not start with a forward slash (or wildcard) is
automatically prepended with a forward slash. So, file
and /file
are effectively
the same pattern.
The default values are:
- Pick first: none
- Merge:
/META-INF/services/**
- Exclude:
/META-INF/LICENSE
/META-INF/LICENSE.txt
/META-INF/NOTICE
/META-INF/NOTICE.txt
/LICENSE
/LICENSE.txt
/NOTICE
/NOTICE.txt
/META-INF/*.DSA
(all DSA signature files)/META-INF/*.EC
(all EC signature files)/META-INF/*.SF
(all signature files)/META-INF/*.RSA
(all RSA signature files)/META-INF/maven/**
(all files in themaven
meta inf directory)/META-INF/proguard/*
(all files in theproguard
meta inf directory)**/.svn/**
(all.svn
directory contents)**/CVS/**
(allCVS
directory contents)**/SCCS/**
(allSCCS
directory contents)**/.*
(all UNIX hidden files)**/.*/**
(all contents of UNIX hidden directories)**/*~
(temporary files)**/thumbs.db
**/picasa.ini
**/protobuf.meta
**/about.html
**/package.html
**/overview.html
**/_*
**/_*/**
Example that adds the first anyFileWillDo
file found and ignores all the others and
that excludes anything inside a secret-data
directory that exists in the root:
packagingOptions { pickFirst "anyFileWillDo" exclude "/secret-data/**" }
Example that removes all patterns:
packagingOptions { pickFirsts = [] // Not really needed because the default is empty. merges = [] // Not really needed because the default is empty. excludes = [] }
Example that merges all LICENSE.txt
files in the root.
packagingOptions { merge "/LICENSE.txt" // Same as: merges += ["/LICENSE.txt"] excludes -= ["/LICENSE.txt"] // Not really needed because merges take precedence over excludes. }
Property | Description |
doNotStrip | The list of patterns for native library that should not be stripped of debug symbols. |
excludes | The list of excluded paths. |
merges | The list of patterns where all occurrences are concatenated and packaged in the APK. |
pickFirsts | The list of patterns where the first occurrence is packaged in the APK. First pick patterns do get packaged in the APK, but only the first occurrence found gets packaged. |
The list of patterns for native library that should not be stripped of debug symbols.
Example: packagingOptions.doNotStrip "*/armeabi-v7a/libhello-jni.so"
The list of patterns where all occurrences are concatenated and packaged in the APK.