112 Commits

Author SHA1 Message Date
Chih-Hung Hsieh
1fc78e1814 Fix/suppress aapt/aapt2 google-explicit-constructor warnings
* Add explicit to conversion constructors/operators
* Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters

Bug: 28341362
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor
Change-Id: Ie02101ea7c422e8add535c111a30a2f21ead0ace
2019-01-04 17:38:13 +00:00
Chih-Hung Hsieh
a1b644e88c Fix performance-for-range-copy warnings
Bug: 30413223
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance*
Change-Id: Ie481e88025a7a1f3abde8ff63420d5ccd8577e52
2018-12-17 20:00:55 +00:00
Treehugger Robot
b14c887974 Merge "libandroidfw: move ConfigDescription from aapt2 to libandroidfw" 2018-10-09 21:43:38 +00:00
Mårten Kongstad
f99eda450f AAPT2: optionally keep resources without default value
Teach "aapt2 link" about a new flag --no-resource-removal. When given,
aapt2 will not filter out resources that lack default values. This is
useful mostly when building overlay packages that define resources for
non-default configurations, such as only for values-sv.

Test: manual: build package with resource only in values-vs, verify apk with aapt2 dump
Change-Id: Idc513bcb3f43bbff7f073163562c3dfccdb9bc9b
Merged-In: Idc513bcb3f43bbff7f073163562c3dfccdb9bc9b
2018-10-09 14:02:14 +00:00
Mårten Kongstad
5c541f6e36 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 09:56:09 -07:00
Todd Kennedy
895e19edf0 dump package name
Test: aapt2 dump packagename foo.apk bar.apk
Bug: 113105112
Change-Id: Ibea429adc3a2a890be10548824583addc59ad42d
Merged-In: Ibea429adc3a2a890be10548824583addc59ad42d
2018-08-24 19:29:22 +00:00
Colin Cross
da02feaca2 Add support for --replace-version to aapt2
Implement --replace-version to match aapt1.

Bug: 79755007
Test: aapt2_tests
Change-Id: Iee2bd9a3981c7d4681509f18b735c6e9e6c1a336
Merged-In: Iee2bd9a3981c7d4681509f18b735c6e9e6c1a336
(cherry picked from commit dcd58c420771af75c625242985bd96ba828aca56)
2018-05-30 23:25:21 +00:00
Todd Kennedy
13588dc9e4 Merge "Allow using reserved package IDs" into pi-dev 2018-04-26 21:29:17 +00:00
Todd Kennedy
325129964e Allow using reserved package IDs
Pre-O, the platform treats negative resource IDs [those with
a package ID of 0x80 or higher] as invalid.  In order to work
around this limitation, we allow the use of traditionally
reserved resource IDs [those between 0x02 and 0x7E].

Bug: 78041707
Test: ./out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests
Test: ./out/host/linux-x86/nativetest/libandroidfw_tests/libandroidfw_tests
Test: Manual. Create a feature split with a package ID of 0x7E and see it runs and can reference base resources.

Change-Id: I3d9782cc05d3a55e1a2467bf39566788847e1160
2018-04-26 10:27:30 -07:00
Todd Kennedy
9f6dec11e6 Allow overriding the compile SDK
We automatically pull the compile SDK from the platform. But,
in certain circumstances the platform's SDK codename is
incorrect. Allow the name to be overridden on the command line.

Change-Id: I398f1b00b29db42e4ce202b94cda483c98971a14
Fixes: 78324052
Test: ./out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests
2018-04-20 22:41:52 +00:00
y
d6b83299a6 AAPT: Multiple period legacy support and errors
AAPT would accept files with multiple periods in the filename as input.
This lead to cases explained in b/74999475. This change adds error
messages for files with multiple periods unless the legacy flag is
present. With the legacy flag present, AAPT2 will behave like AAPT
rather than throwing an error.

Test: Added tests to aapt2_tests
Bug: 73071563
Bug: 74999475
Change-Id: I28dfceeea7b39f8e4b9e6671e0fc8793cf388f52
2018-04-11 15:52:43 -07:00
Ryan Mitchell
498baa82e6 Merge "Added --debug-mode flag to AAPT2" into pi-dev 2018-04-04 21:21:28 +00:00
Ryan Mitchell
70414f22dc Check the size of the strings in the StringPool before flattening.
Test: Tested for normal functionality when string does not exceed
maximum length and tests for detection of string that is too lonhg for
UTF8i
Bug: b/74176037

Change-Id: Ic71d3671a069e7012e8ca107e79e071499eebbf6
(cherry picked from commit a15c2a8957b9883cb293fdacaeabd7f2e037a0a5)
2018-04-04 15:54:43 +00:00
Ryan Mitchell
e5b38a676c Added --debug-mode flag to AAPT2
Bug: 74968793
Test: Tested for correct debuggable attribute presense with and without
flag

Change-Id: I0148d1caba62db8cf258926f1d9e87a849aa283f
(cherry picked from commit 444f9bb6a18ff34b69cba504c8658b7013eaa53a)
2018-04-04 15:51:53 +00:00
Adam Lesinski
34a1687a67 AAPT2: Remove resources that define locales but no default values.
According to our docs:
https://developer.android.com/guide/topics/resources/localization.html#defaults-r-important

Some resources *require* that there is a default definition. So far,
the pain is felt when doing translations for strings that have been
renamed, etc.

This CL strips out resources that don't have a default value and define
a resource for a locale. This is conservative, but should be expanded
to other configuration properties moving forward.

Bug: 36572857
Test: make aapt2_tests
Change-Id: Ife94a1f8a2ee221f8532ffa856541a9c8c4e7143
2018-03-01 11:18:23 -08:00
Adam Lesinski
a65bbdf43c AAPT2: Ensure output formats of files are correctly set
When compiling straight to proto from source, the file types
were not set correctly (binary XML or proto XML).

Bug: 73406447
Test: manual
Change-Id: I68c1881a00a2ec1ad58f7ec485af2543d262d076
2018-02-15 16:44:15 -08:00
Adam Lesinski
bbf429795d AAPT2: Fix issue with deserializing binary XML
We assumed that a raw text value set for an attribute meant there
were no compiled values set either.

This would only really happen for attributes that did not belong to any
namespace (no prefix:), since we always kept their raw string values
in case some code relied on it.

Bug: 72700446
Test: make aapt2_tests
Change-Id: Icba40a1d4b181bfe7cad73131c4dbe5ba7f8b085
2018-02-14 16:11:23 -08:00
Adam Lesinski
da9eba300b Dump XML files in aapt2 dump
Test: manual
Change-Id: Id7f656c1385f6d1fec8eaa993c8e2b36bb1ae5b0
2018-02-14 10:49:32 -08:00
Nick Butcher
e78a816966 Prevent AAPT from versioning <animated-selector> tags.
Bug: 69359529
Test: Manually tested with ag/3178054
Change-Id: I10ae4d96c2a31a0a7c363d7a9292ecdfd3bb526a
2018-02-09 11:36:27 +00:00
Mohamed Heikal
1084432e1e AAPT2: Fix silent failure when ContainerReader fails during Link
Currently in the link step ContainerReader is used to read files but the
reader is not checked for errors prior to the read. This can lead to
silent failure when reading invalid resource files.

Change-Id: I6420699ad30b5b84b0b2c696af8eb5a6cbd4111e
2018-02-08 14:50:14 -05:00
David Chaloupka
415689bb1c Merge "Adjust file reference type in 'aapt2 convert'" 2018-01-18 10:06:01 +00:00
David Chaloupka
b66db4ec4c Adjust file reference type in 'aapt2 convert'
When converting between binary and proto APKs in either direction, the
'aapt2 convert' command did not adjust FileReference type for entries
inside the resource table. This fix makes in-place changes of the resource
table passed to ConvertApk, which is safe since the resource table is
thrown away after the conversion.

Bug: 71854843
Test: Manual
Change-Id: Ide6e141269392db15b399db3566f18175f5133d5
2018-01-17 11:07:44 +00:00
Izabela Orlowska
3c3f9b5d07 AAPT2: always compile 9patch files
Test: existing tests
Bug: 70578281
Change-Id: I7ffcbdd664108348182e71d01b1680e2399ec37c
2018-01-12 14:26:31 +00:00
Adam Lesinski
73bff1e851 AAPT2: Allow compatible duplicate Attributes
If a resource XML file defines two compatible Attributes, they should
be merged without throwing an error. Ex:

<declare-styleable>
  <attr name="conflict" format="string" />
</declare-styleable>

<declare-styleable>
  <attr name="conflict" format="string|reference" />
</declare-styleable>

In this case, string|reference and string are the same, so these should
merge correctly.

Bug: 65699599
Test: make aapt2_tests
Test: make AaptBasicTest
Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95
2018-01-11 13:54:11 -08:00
Adam Lesinski
e6aa6d1421 AAPT2: Keep file enumeration consistent across platforms
Filesystem directory enumeration is platform dependent, so
sort the files lexicographically according to source path before
consuming them in the compile command.

Bug: 70680618
Test: manual
Change-Id: I6706dea2eb40cbaff8a586994dd1013976e4ced4
2017-12-28 08:17:43 -08:00
TreeHugger Robot
d14c826c82 Merge changes I0face862,If2d091e5,I4e18e63f
* changes:
  AAPT2: Sort artifacts based on the Play Store rules.
  AAPT2: Allow empty group definitions
  AAPT2: Get list of multi-APK artifacts without APK file
2017-12-20 18:05:53 +00:00
TreeHugger Robot
54839e0d30 Merge "AAPT2: Add flag to compile command for outputting symbols" 2017-12-20 15:27:19 +00:00
Izabela Orlowska
ad9e1324ff AAPT2: treat manifest validation errors as warnings when asked
Bug: 65670329
Test: updated
Change-Id: Ic554cc20134fce66aa9ddf8d16ddffe0131c50e9
2017-12-20 13:25:59 +00:00
Izabela Orlowska
c81d9f36ec AAPT2: Add flag to compile command for outputting symbols
Only XML files can define resources inside of them, so the fragment
R.txt will only be created for XML files. The fragment R.txt will
contain files defined inside the XML files and the file itself.
For example for res/layout/my_layout.xml that defines "@+id/myView" the
fragment R.txt will contain "default int id myView" and "default int
layout my_layout".
Resources defined with the "public" keyword will have the word "public"
in the partial R.txt, resources defined with the "java-symbol" keyword
will have the word "private, and all other resources will have the word
"default".
If a string is declared in values/strings.xml as:
'<string name="foo">text</string>'
then the partial R.txt will contain "default int string foo". If the
same string is also marked as public in the values/public.xml as:
'<public type="string" name="foo" id="0x7f000001"/>
then the partial R.txt for that file will cointain:
"public int string foo".
Also, the resource IDs will be skipped as this is only for compilation,
proper IDs will be generated at linking phase.

Test: manual
Change-Id: I37d07d5ee4a9f2e5a60a54e48579eba86ae7dd60
2017-12-20 12:04:23 +00:00
Shane Farmer
2c12241fa8 AAPT2: Get list of multi-APK artifacts without APK file
Allow the optimize command to produce a list of output artifact names
without needing to read the input APK from disk. This not only saves
disk reads for a file that will not be used, it also allows the list
of outputs to be generated without having an APK file yet.

Test: unit tests
Test: split an APK
Test: print list of outputs without an APK
Change-Id: I4e18e63f298a07f26ab0de2b2f0acb769bb535ba
2017-12-19 13:52:30 -08:00
Adam Lesinski
71be70507d AAPT2: Propagate SPEC_OVERLAYABLE flag to final APK
Resources can be marked as overlayable, which means they can
be overlaid by runtime resource overlays.

This change propagates this state to the final resource table that
is installed on device.

Future work:
- Have the idmap tool respect the overlayable state and ignore
  entries that overlay anything else.

Bug: 64980941
Test: make aapt2_tests
Change-Id: Id45b1e141a281be2ee32a4ac3096fcf1114d523b
2017-12-18 14:16:02 -08:00
Shane Farmer
cb6c3f9b88 AAPT2: Push more configuration code into the parser
When parsing is complete, we now have a list of output artifacts that
have their referential integrity validated. This means that once the
configuration file is parsed, the only errors that can occur are related
to APK processing, and not the configuration itself.

This reduces the number of errors that could cause a partial output of
APK artifacts. It simplifies the public API and reduces the complexity of
the code to generate multiple APKs.

Test: Ran unit tests
Test: manually ran the optimize command to ensure it still works

Change-Id: I3f2d885b207a84c958f5348a4baa6718598184a4
2017-12-13 12:28:39 -08:00
Shane Farmer
99ac3fdbd8 AAPT2: Remove unused command line option.
--target-abis is never used and the same functionality works with
onfiguration files.

Test: Unit tests
Change-Id: Ic890eb0f15fade82cd85ba34d653d6cea3b79fb2
Bugs: b/70571736
2017-12-12 16:55:31 -08:00
TreeHugger Robot
b3b66ee66b Merge "AAPT2: allow to generate R.txt without R.java" 2017-12-12 13:21:05 +00:00
Tom Dobek
725fb12c0d Aapt2 convert: skip processing resources when resource table is absent.
Test: manual

Change-Id: Iafe20f98857a29d625e7a57a9201db6279d43e45
2017-12-11 10:30:12 +00:00
Izabela Orlowska
23a6e1e390 AAPT2: allow to generate R.txt without R.java
Bug: 69956357
Test: manual
Change-Id: If2bc32bd4efb1ea17c6cba7a17f2b2300164ede0
2017-12-05 20:59:08 +00:00
TreeHugger Robot
49639bf6cd Merge "AAPT2: Allow output artifacts to be filtered." 2017-12-05 20:36:47 +00:00
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
TreeHugger Robot
4ab869e1e6 Merge changes I2eef812b,I7b607192
* changes:
  AAPT v1 embed compile SDK version and codename into app
  AAPT2: Embed version of framework an app was compiled against.
2017-12-05 16:03:26 +00:00
Luke Nicholson
5e50588e49 Merge "Enable obfuscation of resource names, with whitelisting support." 2017-12-05 05:20:00 +00:00
Luke Nicholson
b0643302c7 Enable obfuscation of resource names, with whitelisting support.
Test: Built aapt2, ran optimize on gmail apk with sample whitelist
config file, and flags enabled. Added two unit tests to TableFlattener
covering obfuscation logic.

Change-Id: Iad6329d75ff440121bf1a2cdf09c5f4bf4199d9d
2017-12-04 17:54:05 -08:00
Adam Lesinski
c6284379a5 AAPT2: Embed version of framework an app was compiled against.
This change injects the 'android:compileSdkVersion' and
'android:compileSdkVersionCodename' into an app's AndroidManifest.xml,
whose values are dervied from the version name and version code of the
framework AndroidManifest.xml that is being linked against.

Bug: 63388434
Test: make aapt2_tests
Change-Id: I7b607192ecb337307c4bcb5770e7f716c6d4c9d2
2017-12-04 17:19:44 -08:00
Adam Lesinski
2427dce820 AAPT2: Fix issue where exported symbols (@+id/*) were not exported
Test: make AaptTestAppOne
Change-Id: If3218c880e83c2cfaf535a099db38504471be676
2017-11-30 16:12:29 -08:00
Adam Lesinski
a693c4a32e AAPT2: Move all file output to FileOutputStream
FileOutputStream is safe to use on Windows, as it opens
files using our compatibility API.

Bug: 68262818
Test: make aapt2_tests
Change-Id: Ib0b27e93edd609b49b1327db7d9867a002198ebb
2017-11-16 12:06:17 -08:00
Pierre Lecesne
d8b4beaae9 AAPT2 - Add ProtoApkSerializer implementation to convert from Binary to Proto.
Also new flag to choose the conversion direction:
  --output_format [binary|proto].

Test: Manual

Change-Id: I61d381aa49869b0fd6bd9f017dda0cac5ca998bb
2017-11-14 09:05:27 +00:00
Pierre Lecesne
d55bef78a5 AAPT2 - Convert command to copy all the files.
Test: Manual

Change-Id: I8705966cb34ff41eb362126a35956720147fae91
2017-11-13 21:07:34 +00:00
Pierre Lecesne
288536b6bd Merge "Refactor Convert command to use a ISerializer interface." 2017-11-10 20:09:47 +00:00
Donald Chai
414e48a541 AAPT2: whitelist alphanums instead of blacklisting hyphens in package names.
BCP 47 uses plus signs for name mangling, and future qualifiers may
start using other reserved characters as well, so we might as well
futureproof the sanitizer.

Change-Id: I1be7ee4234f8e30bb0ea832372b4dc932d30550c
Fixes: 69134786
Test: UtilTest.SplitNamesAreSanitized
2017-11-09 21:47:20 -08:00
Pierre Lecesne
7e8549dd57 Refactor Convert command to use a ISerializer interface.
This will allow for other implementations.

Test: Manual

Change-Id: Ibf9cf8f5ac2b5b8e51a5fb684b434a0f59a3cbee
2017-11-10 05:04:48 +00:00
Adam Lesinski
490595a5fc AAPT2: Workaround for feature splits without namespacing
Android Instant Apps in its current iteration does not use namespaces,
but due to limitations on the Android resource runtime, needs to make
it look like it does.

This is due to a bug that treats any package ID that's not 0x01 or 0x7F
as a shared library. Shared libraries require unique package names.

As a workaround, and since Android Instant Apps can not have a feature
depend on another feature, we can alter the resource package name of a
feature split just before writing it out to disk. This avoids using a
unique package name while linking, thereby avoiding namespace issues.

Bug: 68820737
Test: manual
Change-Id: Ic553ed42656436bbb949393d0248ee7bb9d37860
2017-11-09 14:57:49 -08:00