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
APK, add it to the APK.
- If any of the first-pick patterns match the path and that path has already been included in
the APK, do not include the path in the 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
APK, concatenate the contents of the file to the ones already in the 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/LICENCE
-
/META-INF/LICENCE.txt
-
/META-INF/NOTICE
-
/META-INF/NOTICE.txt
-
/LICENCE
-
/LICENCE.txt
-
/NOTICE
-
/NOTICE.txt
**/.svn/**
(all
.svn directory contents)
**/CVS/**
(all
CVS directory contents)
**/SCCS/**
(all
SCCS directory contents)
**/.*
(all UNIX hidden files)
**/.*/**
(all contents of UNIX hidden
directories)
**/*~
(temporary files)
**/thumbs.db
**/picasa.ini
**/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
LICENCE.txt files in the root.
packagingOptions {
merge "/LICENCE.txt" // Same as: merges += ["/LICENSE.txt"]
excludes -= ["/LICENCE.txt"] // Not really needed because merges take precedence over excludes.
}