60 Commits

Author SHA1 Message Date
Ryan Mitchell
ac55e41f24 Fix memory leak in aapt2
Fix a memory leak in Main.cpp.

Bug: 141312058
Test: m -j aapt2 SANITIZE_TARGET=address
Change-Id: I54b61792ab75e2f59298dd38168653e496c84bff
2019-09-25 16:26:29 +00:00
Steven Moreland
2700afda04 aapt2: disable leak detection
When building with SANATIZE_HOST=address and ASAN_OPTIONS="" in order to
test that leaks are removed from AIDL, was hitting leaks here.
Explicitly setting ASAN_OPTIONS here so that we can detect leaks in
other host tools.

Bug: 141312058
Test: AIDL's runtests_asan.sh
Change-Id: Ibc599ab75bbf63eab1c7747d17952390a7967e87
2019-09-19 18:18:23 +00:00
Ryan Mitchell
34039b26f5 Add build number to aapt2 version
This changes adds the build id to the version printed by "aapt2
version". This change also adds a field to the ResourceTable proto that
specifies the fingerprints of tools used to build the table.

Bug: 123663089
Test: manual
Change-Id: Ifaf33c1e506b68e9f1d921fdbeddf36485e65790
2019-04-17 10:59:38 -07:00
Fabien Sanglard
2d34e76dac Add --trace_folder to aapt2
Add a tracing API and instrument key functions in order to profile
aapt2 bottleneck. The API allows to generate systrace fragment files.

Impact on performance is neglibible with each Trace requiring less
than 1us and the final Flush operation at the end of a command
requiring around 40us.

Bug: None
Test: None
Change-Id: I51b564d3694e9384679f43b878b32295527dddf6
2019-03-05 15:09:27 -08:00
Ryan Mitchell
214846df59 Created resuable DumpApkCommand and added "badger"
This change refactors the dump commands to inherit from a base
DumpApkCommand and adds a command that prints out an ASCII
image of a badger if the user wrote "badger" instead of
"badging". The command is hidden from the help menu.

Bug: 73535002
Test: manual
Change-Id: I9bdd8a7bbf6a4282c4933e5c478f6d1d8e32d99e
2018-10-09 10:51:25 -07:00
Ryan Mitchell
5d2755129d AAPT2: Reformatted dump command invocations
Use with:
  aapt2 dump apc [apc]
  aapt2 dump configurations [apk]
  aapt2 dump strings [apk]
  aapt2 dump resources [apk]
  aapt2 dump xmlstrings [apk] --file [file]
  aapt2 dump xmltree [apk] --file [file]

Will add permissions and badging in a later commit.

Bug: 73351292
Test: Manual tests of the commands
Change-Id: I97eec01222af14053a98bd70255f1bfecd16b1c4
2018-08-14 15:56:29 -07:00
Ryan Mitchell
833a1a6c4a AAPT2: Refactor flags into commands
Refactors the flag based command invocation into classes that make using
subcommands easier.

Test: manual tests of printing
Change-Id: Ic8df6af0be30db552e32150afebecbfeec7e1075
2018-07-13 14:26:06 -07: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
3420eed699 AAPT2: Bump to version 2.19
Test: manual
Bug: 65645766
Change-Id: Id8bdb14e498bd79ff642f9ad56ef05ec7a5825af
2017-09-14 17:00:56 -07:00
Adam Lesinski
43f6f77a72 AAPT2: Change the daemon mode to be line based
Accept a set of arguments separated by newlines.
This avoids path separator conflicts with the argument
format for passing splits.

Test: manual
Change-Id: Ia68122cb77b7dde2292a0fd953e79f02996ac01c
2017-08-25 14:20:24 +01:00
Izabela Orlowska
4a4ebe25f4 AAPT2: better error handling for daemon mode
Test: manual
Change-Id: Ia1997800ad94f386dbbb4195011395ecee1ba91f
2017-08-24 16:19:45 +01:00
Adam Lesinski
448a15c84f AAPT2: Add a daemon mode
Gradle and other build tools that need to frequently interact with aapt2
can use the daemon mode to issue regular CLI commands without paying
the process start cost for each invocation.

Test: manual
Change-Id: I543858ed46496278bad643f0dae688c924ec6c3f
2017-08-21 15:38:53 -07:00
Adam Lesinski
efeb7af13b AAPT2: Fix windows unicode path issues
Mingw64 was being difficult, so instead of defining a wmain entrypoint,
the command line parameters are parsed manually using built-in Windows
methods that support Unicode. The results are converted to UTF8 and
handled just like the rest of the linux/mac version of the code.

This also removes dependencies on std::istream in favour of a
FileInputStream which calls the appropriate unicode version of
open to read a file.

No speed regressions found on Linux or MacOS.

Bug: 62336414
Bug: 63830502
Test: manual
Change-Id: I597da51e33729ed1b98bf246e7e773337fd3fee8
2017-08-03 17:33:52 -07:00
Adam Lesinski
f903d5f15a AAPT2: Bump version number to v2.18
Test: none
Change-Id: I6e3b4c95a7d7ba416ba368e5b19782dbffa04fd8
2017-07-10 04:19:28 -07:00
Adam Lesinski
48a7659454 AAPT2: Mark version 2.17 and update readme
Test: none
Change-Id: I6429b1c3acbcbf2244a5a5c95bc48a5d66bdaebe
2017-06-08 18:13:01 +00:00
Adam Lesinski
c744ae8aca AAPT2: Implement attribute compat versioning
This change defines some hardcoded rules to degrade
attributes in newer SDKs to specific older attributes.

An attribute with a degrade rule will generate a new XML for the API
in which the attribute resulting from the degradation was introduced.

Since API 22 (Lollipop MR1), attributes are correctly ignored and do
not need to be versioned. In XML files defined for APIs 22+, the
original and degraded attributes coexist in the same XML file.

One such example is paddingHorizontal, introduced in API 26.
paddingHorizontal degrades to paddingLeft and paddingRight, which
were both introduced in API 1.

Bug: 35763493
Test: make aapt2_tests
Change-Id: I4aa8755a9ee2c0cc5afdc55c3d30093fd3a47f3d
2017-05-24 15:14:29 -07:00
Adam Lesinski
28e6c0bac2 AAPT2: Add option to disable PNG crunching
When compiling, a developer may want to disable PNG crunching
for a specific set of PNGs.

Bug: 37729284
Test: manual
Change-Id: I134f208f8bb212df07a4eef65b467985a6443375
2017-05-10 15:00:10 -07:00
TreeHugger Robot
53c9898e79 Merge changes I446fb6ab,Ife3bbd29 into oc-dev
* changes:
  Valid resource IDs may be negative
  AAPT2: Workaround for findViewById with package ID > 0x7f
2017-04-29 20:38:20 +00:00
Adam Lesinski
1e4b0e54a3 AAPT2: Workaround for findViewById with package ID > 0x7f
The entire View code base checks IDs against View.NO_ID except
findViewById(), which checks to see if the ID is negative.

Any package ID > 0x7f is interpreted as a negative number in Java
(no unsigned ints), so this check prevents the use of IDs > 0x7f.

findViewById is final, so support library workarounds are not possible.

Instead, IDs (@id/foo) are just sentinels, their values don't matter.
If building for pre-O devices, rewrite any references to these IDs of
the for 0xPPTTEEEE, where PP > 7f, to 0x7fPPEEEE.

The symbol table will check for potential collisions against the base
APK, so this should be safe.

Bug: 37498913
Test: manual
Change-Id: Ife3bbd29db287757ef8a2ffd83053d97f1db2613
2017-04-28 12:47:48 -07:00
Chris Warrington
820d72adc0 AAPT2: Error reporting through JNI.
Rather than relying on stderr being wired correctly.

Test: Tests for JNI integration in studio-master-dev.
Change-Id: I1c7e7130bc4e56d61de259a9596bee3a6b3520fb
2017-04-28 10:06:38 +01: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
33af6c730f AAPT2: Parse an ID encoded as a map
ID types should not be encoded as a map. AAPT and AAPT2 emit
IDs as boolean types.

Some apps exist that for some reason have their ID types encoded
as empty maps. This is the case only for the auto generated IDs
from enum values in <attr> tags.

Allow IDs as maps and ignore their content when processing an APK
for optimizing.

Also fixes an issue with expected size of the ResTable_package struct.

Bug: 35861796
Test: tested against the APK in b/35861796
Change-Id: I29a19cd9777bb10bed6766cd42e35e50e098797b
2017-03-29 20:11:04 +00:00
Adam Lesinski
06460ef0d7 AAPT2: Fix up file IO
This also enables an AAPT behavior that CTS tests have
come to depend on.

Small files that compress negatively (get larger) are stored
uncompressed. Some CTS tests assume this and try to open these
files by mmapping them, which is only possible if they are
uncompressed.

Bug: 35461578
Test: make aapt2_tests
Change-Id: Id622a6150fe72477ad65d67d1bad897a8ee2ffb9
2017-03-20 16:53:46 -07:00
Adam Lesinski
f34b6f4f2b AAPT2: Add --package-id flag for feature-split suppport
Bug: 35928935
Change-Id: Ia8496505e61cfcfdb8f9f62366d2f36e453db111
Test: make aapt2_tests
2017-03-07 11:06:16 -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
Adam Lesinski
ceb9b2f80f AAPT2: Shared library support
Test: make aapt2_tests
Change-Id: I98dddf1367e6c0ac425bb20be46e6ff05f4f2f45
2017-02-22 11:16:13 -08:00
Adam Lesinski
7542162cb1 AAPT2: Fix pseudolocalization to respect <xliff:g>
The XLIFF 'g' tag specifies content that should NOT be translated.
AAPT2's pseudolocalization process should respect it.

Bug:34064599
Test: make libandroidfw_tests
Change-Id: Ice437d7f0ff246730ee04896fd035e2d846148fb
2017-02-08 06:23:45 -08:00
Adam Lesinski
558a63056e Merge "AAPT2: Support CtsContentTestCases build" 2017-02-04 03:44:25 +00:00
Adam Lesinski
86d67df8d5 AAPT2: Support CtsContentTestCases build
- Add <feature-group> to ManifestFixer.
- Support <meta-data> in <instrumentation>
- Add support for <bag> and type="configVarying". Some CTS tests use this
  old notation, we need to support it (even though configVarying isn't
  anything supported by the framework convention).

Change-Id: I6946fa633ce513ea8437c1496db883cf27dcf6de
Test: make aapt2_tests
2017-02-01 15:28:23 -08:00
Pierre Lecesne
8a7b4cb992 Backbone of the new aapt2 strip command.
The strip command takes an APK as argument and a --target-densities flag which
contains the list of screen densities for which to optimize the APK. All
the resources that would be unused for a device having the given
densities are stripped from the APK leaving only the ones actually being
used.

Test: Manual.

Change-Id: I68368b00876a18ccdbbfc0a8dd265bd361117933
2017-02-01 18:49:19 +00:00
Yuichi Araki
4d35cca96c AAPT: Add --no-version-transitions flag
Add a new flag to disable versioning of Transition related XMLs.
Transition support library will use this to handle these XMLs on older
API levels.

Test: make libaapt_tests AaptTestAppOne
Bug: 34427868
Change-Id: I66e81cca049e71ef6704177b2ca21c9cdeaff78f
2017-01-24 14:59:51 +09:00
Adam Lesinski
d5083f6f6b Move StringPiece to libandroidfw
libandroidfw needs to make use of StringPiece, so
move it to libandroidfw and update all code referencing
StringPiece in aapt2.

Test: make libandroidfw_tests libaapt2_tests
Change-Id: I68d7f0fc7c651b048d9d1f5e7971f10ef5349fa1
2017-01-17 18:55:51 -08:00
Adam Lesinski
5119e51730 AAPT2: Allow <meta-data> in <manifest>
Bug:32171613
Test: libaapt2_tests
Change-Id: I30fdd9475ff7dff6ceb0ff46a4a00991b72db68b
2016-12-05 21:09:52 -08:00
Adam Lesinski
c0c366394c Add font type to AAPT2
Test: make libaapt2_tests AaptTestAppOne
Change-Id: I8fbf01675a218cc3c0b59598b6b1ec173851e946
2016-10-27 18:09:00 -07:00
Adam Lesinski
ce5e56e243 AAPT2: Rename to match new style
Use Google3 naming style to match new
projects' and open source google projects' style.

Preferred to do this in a massive CL so as to avoid
style inconsistencies that plague legacy code bases.
This is a relatively NEW code base, may as well keep
it up to date.

Test: name/style refactor - existing tests pass
Change-Id: Ie80ecb78d46ec53efdfca2336bb57d96cbb7fb87
2016-10-26 19:30:23 -07:00
Adam Lesinski
cacb28f2d6 Use Google3 style guide with .clang-format
Test: style change only, builds ok
Change-Id: I885180e24cb2e7b58cfb4967c3bcb40058ce4078
2016-10-19 12:18:14 -07:00
Adam Lesinski
5cb0530ca4 AAPT2: Update version and readme
Update version to 2.2 and update readme to reflect added
support for inline complex XML resources.

Change-Id: If825c96541952e95860d34390c6c36704a24129b
2016-09-06 17:34:06 -07:00
Adam Lesinski
36c73a5959 AAPT2: Expose split support to command line
Bug:30445078
Change-Id: If4b8530dba71b9059b8e62c04757da99c1119d22
2016-08-15 12:14:26 -07:00
Adam Lesinski
0368ebfc29 AAPT2: Add version info and release notes
Bug:30402888
Change-Id: Idb532cc71921eb1cfba31c00a6fb7108e31fddd8
2016-07-26 12:57:21 -07:00
Adam Lesinski
458b877488 AAPT2: Add diff command
Adds the diff command and various small fixes to issues
discovered when diffing old AAPT built APKs with new AAPT2
built APKS.

Bug:22775504
Change-Id: I682a7fe1cf4b3efa7cbd5d18b333cf2d1046fe1b
2016-04-30 01:36:12 +00:00
Adam Lesinski
59e04c6f92 AAPT2: Switch to protobuf for intermediate format
Without needing to conform to the runtime data format,
it is much easier to add new features such as debugging symbols
and carrying over product data to link time.

This also simplifies the runtime format parser and serializer,
which will change much less frequently than the protobuf intermediate
format.

Change-Id: I209787bbf087db0a58a534cb8511c51d21133e00
2016-02-09 19:59:17 +00:00
Adam Lesinski
1ab598f46c AAPT2: Separate out the various steps
An early refactor. Some ideas became clearer as
development continued. Now the various phases are much
clearer and more easily reusable.

Also added a ton of tests!

Change-Id: Ic8f0a70c8222370352e63533b329c40457c0903e
2015-10-16 12:13:08 -07:00
Adam Lesinski
6cc479b76e AAPT2: Remove the need for specifying package name in compile phase
The compile phase doesn't use the AndroidManifest, so we had to specify the
package name on the command line.

We can omit the package name, since we don't resolve external references
in the compile phase. Packages that reference the current package will be encoded
with no package name. When loaded by the link phase, the package name will be supplied
and all the references with no package name will use that one.

Change-Id: I9fe4902b747b06899b45c968f30ba1aa05c5cd69
2015-06-12 17:12:04 -07:00
Adam Lesinski
a1ad4a812a AAPT2: Proguard rules generation added.
Change-Id: Ifbe79516cd9a1ade471e211a259301c63b62ac67
2015-06-09 11:14:24 -07:00
Adam Lesinski
8c831ca87b AAPT2: Add manifest merging
Now that AAPT2 is library-aware, it needs to take care of
all library related work, including merging manifests.
The logic was taken from the current Java ManifestMerger.

Change-Id: Id93f713f27ae8617922bf89e325e45be9f863c06
2015-06-04 18:00:33 -07:00
Adam Lesinski
75f3a55cc5 AAPT2: Change xml file parsing to DOM based
We modify the XML of layouts and AndroidManifest enough
that it warrants we operate on the tree in memory.
These files are never very large so this should be fine.

Change-Id: I5d597abdb3fca2a203cf7c0b40fcd926aecb3137
2015-06-04 11:37:05 -07:00
Adam Lesinski
39c353a6ca AAPT2: Fix layout versioning
Change-Id: I37190cf8a1f0a81c068aeb2b5326b3b3080f75a5
2015-05-14 20:56:10 -07:00
Adam Lesinski
d13fb24986 AAPT2: Debug: Dump only targetted style
Change-Id: Id7c5a4b5d0880520e1fea05e5a31d398946c5f05
2015-05-12 20:45:20 -07:00
Adam Lesinski
bdaa092a19 AAPT2: inferred style parent processing
Change-Id: I8fbc4feef16b6039cf4c526fcfb767dc75a9c131
2015-05-12 20:41:31 -07:00
Adam Lesinski
330edcdf13 AAPT2: Support static lib referencing static lib
When a static library A references static library B,
and app C references both A and B, we get the following symbol merging,
symbols from library B get imported twice.

We must only check that symbol references to library B are valid
when building library A. We should only merge all the symbols
when building final app C.

Change-Id: I23cba33b0901dcbb5328d9c9dfaa6a979c073c36
2015-05-12 20:41:31 -07:00