Commit Graph

96 Commits

Author SHA1 Message Date
Ryan Mitchell
9ed5638125 Do not rename R.java package
When the --rename-resources-package flag is used, only rename the
package name within the resources.arsc. Generate the R.java under
the package name defined by the manifest unless --custom-package is
used.

(This is a cherry pick.)

Bug: 147434671
Test: manual
Merged-In: Id9d10e16f32533da1b67ab72ac846791526e7a76
Change-Id: Id9d10e16f32533da1b67ab72ac846791526e7a76
2020-05-13 09:04:14 -07:00
Ryan Mitchell
940ae50498 Add --rename-resources-package to aapt2
There is currently no way to change the package name encoded in the
resources table. This change adds a flag that controls rewriting the
package name encoded into the resources table. This flag does not
rewrite the package name in the manifest xml.

(This is a cherry pick.)

Bug: 147434671
Test: manual
Merged-In: I435ba07e29df0522c3a44cc5f2c460004a02d71c
Change-Id: I435ba07e29df0522c3a44cc5f2c460004a02d71c
2020-05-07 17:03:12 -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
a55dc2ed6b Fix long paths on Windows
util::mkdirs iteratively creates each directory of a specified path. For
windows, Calling mkdir on only the drive letter or on the extended path
prefix (\?\\) will result in an error. Start after the long path prefix
and the drive letter.

This also changes AAPT2 to use AssetMaanager2 to retrieve symbols from
the symbol table. AssetManager2's zip library uses _wopen to open
windows files.

Bug:123251200
Test: aapt2_tests.exe
Change-Id: I26169d83b22d441485de3c49d63a6c4ed710e292
2019-02-20 09:46:00 -08:00
Izabela Orlowska
a1dea5f915 Merge "AAPT2: allow regexes for extensions to not compress" 2019-02-20 12:55:58 +00:00
Izabela Orlowska
0faba5fdfa AAPT2: allow regexes for extensions to not compress
Change-Id: I09d2ad1d1466643ca7628c6480224e16b9002ee5
Fixes: 67575899
Test: added + manual
2019-02-20 10:36:43 +00:00
TreeHugger Robot
6d9fc1c8de Merge "Prevent AAPT2 from versioning <set> tags" 2019-02-15 23:26:25 +00:00
Winson
3c918b8cee Option to exclude configs from AAPT2 Link
Adds --exclude-configs to remove matching configs from resulting APK. This matches on explicitness, so if the resource contains all the flags set by the option exactly, it will be removed, but not the other way around.

"--exclude-configs fr" with fr-land resource will remove.
"--exclude-configs fr-land" with fr resource will not remove.

Bug: 119678846

Test: aapt2_tests ResourceExcluder_test
Test: manually ran link on a test set of res

Change-Id: Ieccdecde4aea1fa0502abfd092dffa7da8f929ea
2019-01-28 11:06:33 -08:00
Winson
a00d969c9c Prevent AAPT2 from versioning <set> tags
In AAPT, if --no-version-vectors is added and an XML file is a vector, it prevents the entire XML's contents, including children attributes, from being split by version for compat.

In AAPT2, each element is checked individually, and so "set" has to be ignored manually.

Bug: 111056281

Test: Compiled avd_progress_indeterminate_horizontal.xml linked in bug

Change-Id: I20a7888f36cf5923b6dd8e3b701243c74f8d421b
2019-01-24 15:59:16 -08:00
Chih-Hung Hsieh
3b3be3f10f Merge "Fix/suppress aapt/aapt2 google-explicit-constructor warnings" am: cdf6be573f am: d42fe48c93
am: 0bf62f1309

Change-Id: Iffb7e4a145b172a35dd58b9450d4a5184d8b07f7
2019-01-04 12:20:01 -08:00
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
Ryan Mitchell
479fa39d65 Remove raw values from proto APK
Raw attribute values are not included in xml files when building binary
APKs but they are when building proto APKs. Remove raw attribute values
and create a new convert flag that (--keep-raw-values) that allows raw
value to be kept.

Also added flag to link to keep raw attribute values.

Bug: 115915884
Bug: 116700688
Test: aapt2_tests
Change-Id: Id50136b775b3f43d159ca06181282f6a7b8eaf40
2019-01-03 16:19:04 -08:00
Ryan Mitchell
467b689a4c Do not serialize empty text in manifest proto
When linking an APK in the proto format, the manifest is currently
serializes text nodes that only contain whitespace:

child: {
  text: "\n        "
  source: {
    line_number  : 0x0000000f
    column_number: 0x0000002f
  }
}

These whitespace bloat the proto size unnecessarily. Do not write these
text nodes for proto apks.

Bug: 118800653
Test: make aapt2_tests
Change-Id: Icfaaf88976f81450bbf51610a316b336deeae60c
2018-11-16 15:58:06 -08:00
Treehugger Robot
b14c887974 Merge "libandroidfw: move ConfigDescription from aapt2 to libandroidfw" 2018-10-09 21:43:38 +00:00
TreeHugger Robot
96af49eb01 Merge "AAPT2: optionally keep resources without default value" 2018-10-09 17:32:29 +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
d8d290107a 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
2018-10-09 07:01:17 -07: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
Mårten Kongstad
24c9aa6541 libandroidfw: move ConfigDescription from aapt2 to libandroidfw
This is to allow idmap2 to access ConfigDescription.

Test: libandroidfw_tests
Test: aapt2_tests
Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08 06:50:22 -07:00
Ryan Mitchell
7e5236dc56 Restore Proguard behavior and add minimal flag
We previously changed AAPT2 to correctly only generate keep rules for
the constructors required to inflate the different views. This cause
projects that did not have keep rules for the other constructors that
were accessed through reflection to have runtime crashes. This change
adds a flag to the link stage (--proguard-minimal-keep-rules) that
allows AAPT2 to only keep the constructors required for layout
inflation. If the flag is not present, then AAPT2 will generate less
specific keep rules than keep all constructors.

Bug: 116201243
Test: aapt2_tests
Change-Id: I8bb5cdf8446518ab153ea988e1243ca9494258c7
2018-09-25 15:20:59 -07:00
Todd Kennedy
9fbdf89dda Don't allow splitting on an empty configuration
When aapt breaks out splits, it may remove the SDK constraint [if
it's lower than the min sdk]. If that is the only constraint, we
would create a resource split with no constraints. Don't allow
that situation. There must always be _some_ constraint.

Bug: 113115970
Test: atest CtsAppSecurityHostTestCases:SplitTests
Test: aapt2_tests
Change-Id: I424c875677c3be2a3ff5ddd39100b998bd650a4b
2018-09-17 14:16:21 -07:00
Ryan Mitchell
70f797208c AAPT2: Adaptive icon refactor
Part of a refactor to specify sdk version for all <adaptive-icons> xml
resources.

Bug: 79676805
Test: build success
Change-Id: I1cf1109103722a9562eaf6bf2dcd68d0ef8757eb
2018-08-13 07:37:24 -07:00
Chris Warrington
58e2fbf169 Revert "AAPT2: Automatic Static Library Namespacing."
This reverts commit 481f027ddc.

Reason for revert: Not needed any more

Bug: 111543815
Test: existing unit and integration tests
Change-Id: I87b039192682636d81c2d33512495cb005c9504d
2018-07-23 17:23:25 +01:00
Ryan Mitchell
5fa2bb14ec AAPT2: Fix long version code bugs
Refactoring areas in AAPT2 that use android:versionCode to also use
abdroid:versionCodeMajor. Does not add versionCodeMajor command line flag yet.

Bug: 109883459
Test: aapt2_tests
Change-Id: I573fbea37491cf8c5742f9e385c66ee64c4e5166
2018-07-13 23:41:46 +00: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
Ryan Mitchell
40c95320fd Merge "AAPT2: Add Proguard rules for nav fragments" 2018-05-31 21:32:39 +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 dcd58c4207)
2018-05-30 23:25:21 +00:00
Colin Cross
dcd58c4207 Add support for --replace-version to aapt2
Implement --replace-version to match aapt1.

Bug: 79755007
Test: aapt2_tests
Change-Id: Iee2bd9a3981c7d4681509f18b735c6e9e6c1a336
2018-05-30 14:48:52 -07:00
Ryan Mitchell
9a2f6e60c6 AAPT2: Add Proguard rules for nav fragments
Adds generation of proguard rules for fragments in res/navigation. All
android:name attributes have keep rules generated for the classes they
reference.

Bug: 69929974
Test: aapt2_tests
Change-Id: I05a87484ab357ea5629b73caad8488182f474e1f
2018-05-24 09:58:27 -07:00
Izabela Orlowska
d51efe818b AAPT2: add flag for strict visibility
Will only detect whether a resource was defined as both 'public' and
'private' (but will allow overriding 'undefined' visiblity for now).

Test: TableMerger_test + manual
Bug: 72735798

Change-Id: If0749559c91c4d8820a6286fc9ddc80209c1e5e9
2018-05-02 13:14:33 +01:00
Todd Kennedy
0a81745b48 Merge "Allow using reserved package IDs" into pi-dev am: 13588dc9e4
am: c323122e93

Change-Id: I0addf146d9519a93bc2f8f73898a3454cb1cfb56
2018-04-26 15:27:00 -07: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
4cb8826c28 Merge "Allow overriding the compile SDK" into pi-dev am: fd5166ddac
am: e31a442140

Change-Id: Iaaaee5337ba37a24d409c2e453995e314c562bce
2018-04-23 20:30:05 -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
Mohamed Heikal
57ffac7f10 Merge "AAPT2: Adds config support for manipulating resources" 2018-04-09 14:57:04 +00:00
Mohamed Heikal
d3c5fb64e3 AAPT2: Adds config support for manipulating resources
aapt2 optimise command can now take a resources config file as an
argument. The config has the name of each resource and a list of
directives. Currently implemented is the "remove" directive which marks
the resource for deletion.

The obfuscation whitelist code and argument name was changed to prevent
confusion.

Test: make aapt2_tests
Bug: b/27523794

Change-Id: I2d8e1985e5ea2286131c25231e2c411f3d9610ce
2018-04-06 15:03:23 -04: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 a15c2a8957)
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 444f9bb6a1)
2018-04-04 15:51:53 +00:00
TreeHugger Robot
68c02569ef Merge "Check the size of the strings in the StringPool before flattening." 2018-03-30 00:15:39 +00:00
Ryan Mitchell
a15c2a8957 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
2018-03-29 15:42:13 -07:00
Ryan Mitchell
444f9bb6a1 Added --debug-mode flag to AAPT2
Bug: 74968793
Test: Tested for correct debuggable attribute presense with and without
flag

Change-Id: I0148d1caba62db8cf258926f1d9e87a849aa283f
2018-03-23 13:35:00 -07:00
Chris Warrington
481f027ddc AAPT2: Automatic Static Library Namespacing.
Introduces a link flag --auto-namespace-static-lib for use when linking
static libraries.

When linking a static library with compiled sources that have references
to resources in provided libraries without an explicit package name,
the flag enables automatic inference of the package.

If a resource is present in the package that is being compiled, that is
used, otherwise the reference is rewritten to the highest precedence
resource with matching name and type.

Test: m out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests && \
      $ANDROID_HOST_OUT/nativetest64/aapt2_tests/aapt2_tests
Test: m frameworks/base/tools/aapt2/integration-tests
Change-Id: I6c6017e054654d1f60782d0a428a7a2a47f8952b
2018-03-14 15:05:39 +00:00
Izabela Orlowska
6f34e0dff6 AAPT2: add flag for not compressing resources
Option and behaviour was already implemented, just missing the flag.

Test: N/A
Bug: 70118728
Change-Id: Ib1902cf547b4961395e6c6c99e02f32556981f48
2018-03-05 14:21:36 +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
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
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