15 Commits

Author SHA1 Message Date
Shane Farmer
666de34a58 AAPT2: Allow output artifacts to be filtered.
A new optional flag has been added to allow a list of artifacts that
should be written as output to be provided. If the flag is provided,
only artifacts that have an output name matching an entry in the list
will be processed.

Test: manually ran against an APK with multiple artifacts in the
configuration and confirmed that only the specified artifacts were
written.
Test: Ran all unit tests.

Change-Id: Ia32b19acf1b2ef3711abf13df08dc7b1aa0cf161
2017-12-05 10:52:48 -08:00
Shane Farmer
20ac034086 AAPT2: Specify the output APK in log messages
Extend the context wrapper to allow it to also know the current artifact
that is being generated and to use that as a source for diagnostics
messages.

Test: ran unit tests
Test: manually ran optimize to split and APK and verified log messages

Change-Id: I1d66dacb38db58d57d2fffaa19f5fdaff9f908df
2017-11-30 10:24:18 -08:00
Adam Lesinski
8780eb6e49 AAPT2: Add convert command
This command allows a developer to convert their proto APK
(generated from the link phase using --proto-format) into
a binary APK suitable for use on device.

  aapt2 convert -o output.apk input.apk

Test: manual + make aapt2_tests
Change-Id: I10a7c33bb4b57006d01fe00a8bf92f78e04e7e50
2017-11-01 10:58:28 -07:00
Adam Lesinski
4670805ea4 AAPT2: Move format related files under same directory
Test: make aapt2_tests
Change-Id: Id72cdfc12ba3add294048e60c55f2461344464bf
2017-10-04 14:26:55 -07:00
Shane Farmer
e17993597e AAPT2: Set compatible-screens in manifest for multi-APK
If an artifact in a multi-apk set is for a scpecific set of screen
densities then update the manifest to set the compatible-screens element
to match.

Test: ran unit tests
Test: manually ran optimize command

Change-Id: I07e90850ab2f4647a8623acbeaccbebbe81c3a6a
2017-10-03 16:14:07 +00:00
Shane Farmer
810fd18435 AAPT2: Update versionCode in multi-APKs.
Set versionCode in the AndroidManifest.xml so each artifact has a unique
version code. This will allow the play store to serve up the correct
APKs.

The versionCode is determined by taking the versionCode from the input
APK and adding the configured version to that. If an artifact does not
have a version, the next version is used based on the order in the
configuration file. If the firs artifact does not have a version, it
starts at 1, so that all artifacts have a different version code to the
base APK.

Bug: 64972562

Test: unit tests
Test: manually optimized an APK into multiple APKs and confirmed versions:
  aapt dump badging ${apk} | grep versionCode

Change-Id: Ie12b3e42bbd8ce9a2819712c2c56b24c0a901e6b
2017-10-03 16:13:04 +00:00
Shane Farmer
3edd472643 AAPT2: Set the minSdkVersion when generating multiple APKs.
When generating multiple APKs from a configuration file, check to see if
we have filtered resource by minSdkVersion and update the manifest to
reflect this. We only want to inflate and modify the manifest file if
there is an update to be applied.

Bug: 37944703
Bug: 67005138

Test: Ran unit tests
Test: Manually split an APK and verified the manifest by dumping with
      AAPT (both xmltree and badging).

Change-Id: I64a0e4889d7d9e57373369b044a091287b06cc35
2017-10-03 16:02:38 +00:00
Shane Farmer
efe45392c3 AAPT2: Multi APK generator by version
- Added an additional axis for generating a multi-apk split by minimum
Android SDK version. This removes any resources that will not be used
for the desired minimum SDK version. If there are multiple resources
that would be valid for any version newer than the requested minimum,
then all would be kept so that the best match can be found.

- Added a context wrapper to set the appropriate Android SDK version for
each generated artifact.

- Split out the FilterTable method to allow it to be directly tested
without the need to mock the APK writing steps.

Test: Unit tests
Test: manually run optimize command

Change-Id: I7e6018df081af9ed5d9e8aaf40ed216c1275f138
2017-08-31 16:30:38 -07:00
Shane Farmer
9ecc0751e3 AAPT2: Add flag to print multi APK artifact names.
- Added new flag that exits after printing the list of artifact names
  that would be generated from the combination of the configuration file
  and input APK.

- Cleaned up the code to generate the artifact names which also involved
  adding some more test cases for corner cases.

Test: Unit tests
Test: Manually ran new command
Test: Manually ran old command
Change-Id: I8d30e7a4a070af26945b8f544a13f23bdf1ba169
2017-08-31 10:17:39 -07:00
Shane Farmer
3d66afe208 AAPT2: Fix multi APK output
- Ensure that the output directory exists before generating APKs
- Only use the file name (and not the path) for creating output
  file names

Test: manually ran optimize command

Change-Id: I5f5ecb5dcec4d17cdbca5709f2dd17e6d53df986
2017-08-24 11:35:09 -07:00
Shane Farmer
0a5b201156 AAPT2: Add a APK filtering.
Allow resource files to be removed from the final artifact based on the
density and locale configuration in the config file. The APK is split
along the density, locale and ABI axis. Each split is generated from the
original APK without modifying the original. The new resource table is
written back to the file system with unneeded assets etc removed.

Test: Unit tests
Test: Manually run optimize command against an APK and inspect results
Test: Installed split searchlite APK (after resigning) and ran on N6

Change-Id: If73597dcfd88c02d2616518585d0e25a5c6a84d1
2017-08-16 19:19:54 +00:00
Adam Lesinski
e38567480b AAPT2: Disable locale domination for deduping
Locale deduping isn't straightforward, as parenting rules
change between platform versions and the selection
preference of a specific locale variant over the default
configuration lead to incorrect results at runtime.

Bug: 62409213
Test: make aapt2_tests
Change-Id: Iec8f1cfba7ae43c847d163529891fdc15f3db826
2017-06-13 11:00:04 -07:00
Adam Lesinski
d0f492db03 AAPT2: Share split functionality between link and optimize
Generating splits should be possible to do from the optimize command.
This means that a lot of infrastructure around split APKs can be
shared by both the optimize and link phase.

Bug: 35925830
Change-Id: Ia88b9e4bff300a56353b2f7a4a2547c8eb43a299
Test: manual
2017-04-10 11:59:18 -07:00
Adam Lesinski
8f7c550e20 AAPT2: Fix Plural::Equals() method
Test: make aapt2_tests
Bug: 35902437
Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24
2017-03-02 17:45:51 -08:00
Adam Lesinski
d48944a745 AAPT2: Rename strip phase to optimize
- Allow resource deduping, version collapsing, and sparse resource
  encoding.

Test: manual
Change-Id: Ia4aa892ab5b06ba1d5ea4a6efb51b00bc3a980c4
2017-02-22 11:41:55 -08:00