Commit Graph

221 Commits

Author SHA1 Message Date
TreeHugger Robot
76750266cd Merge "Fix aapt2 Maybe check" 2020-03-20 03:23:36 +00:00
Ryan Mitchell
60b74fb42f 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.

Bug: 147434671
Test: manual
Change-Id: I435ba07e29df0522c3a44cc5f2c460004a02d71c
2020-02-26 21:35:47 +00:00
Ryan Mitchell
30cd9b2a9a Fix aapt2 Maybe check
Fixed a bug in AliasAdaptiveIcon that occurs when building static
libraries.

Bug: 148455934
Test: build SysUIComposeLib && manual parity test
Change-Id: I6f29630ac3a92d431115885b1369f0541c5044cd
2020-02-20 12:06:49 -08:00
Ryan Mitchell
ee4a564d4f Allow for overlaying dynamic shared libraries
Overlays targeting shared libraries should be loaded into the
resources of every target that depends on the shared library.

Static shared libraries are currently not supported because overlays
should override all versions of static shared libraries and there is
not currently support for an overlay targeting multiple APKs.

Also created a test instrumentation and host test suite for testing
overlays and packages on the system image.

Bug: 140790224
Test: atest OverlayRemountedTest
Change-Id: I20a217b6368d6cf92b2b9f46908fd58012933f72
2020-01-10 23:20:19 +00:00
Donald Chai
94e4a01dec Add option to avoid clobbering visibility of <declare-styleable>
"aapt2 compile" marks styleables as public instead of preserving
information from <public/> or --visibility options.  This behavior can
now be disabled via --preserve-visibility-of-styleables.

Bug: 146649511
Change-Id: Ifb8ab396573d1393df737a59625e79e9cf2494a7
Tested: aapt2_tests
2020-01-07 12:55:52 -08:00
Jean-Luc Coelho
181cbfde80 Add "no-proguard-location-reference" flag to aapt2
This fixes relocatability issues with the code shrinkers.

Bug: 144529940
Test: None
Change-Id: I65e08e850193e67dcdf4c533d9e66332714f0c8c
2019-12-02 21:11:08 +00:00
Izabela Orlowska
5b89b2d320 Use case-sensitive regular expressions in --no-compress-regex
On some windows versions (plus wine) std::regex has issues with the
icase flag (making regex case insensitive). Put the responsibility of
the case sensitivity on the caller.

Fixes: 127793905
Test: wine aapt2_tests.exe -> Util_test
Change-Id: I6775514d3ef43c2c47465bf39ceaf2c195909724
2019-11-27 18:37:09 +00:00
Ryan Mitchell
e5981c075a Disable test broken on windows
RegularExperssions is broken on Windows, disable this test while a
fix is being worked on.

Bug: 127793905
Test: wine aapt2.exe
Change-Id: Ic78a7f12b004d2e8dbf5d79c5b52f00ca0ceb9e9
2019-11-26 18:28:01 +00:00
Mårten Kongstad
1d3b64855b aapt2: add 'dump overlayable' command
Add a command to print a resource table's <overlayable> resources. Given
the following input

  <overlayable name="TestResources">
    <policy type="system">
      <item type="string" name="a" />
    </policy>
    <policy type="sytem|vendor">
      <item type="string" name="b" />
      <item type="string" name="c" />
    </policy>
  </overlayable>

aapt2 dump overlayable will produce

  name="TestResources" actor=""
    policies="system"
      string/a
    policies="system|vendor"
      string/b
      string/c

Bug: 120609160
Test: manual (aapt2 dump overlayable $(gettop)/frameworks/base/cmds/idmap2/tests/data/target/target.apk)
Change-Id: I21041e6169c62d01f1a469624911ce7cad3e18a8
2019-09-18 07:35:44 -07:00
Brian Chang
3d1cde3fce Merge "Improve how we exempt resources from getting their names collapsed." 2019-09-17 17:31:18 +00:00
Brian Chang
dcef831e61 Improve how we exempt resources from getting their names collapsed.
Removed the --whitelist-path flag, which is poorly named and we can
already specify these resources with --resources-config-path.

Renamed TableFlattenerOptions.whitelisted_resources to keep_resources.
It holds ResourceName instead of std::string. This lets us include type
when specifying what gets exempted, for correctness.

Bug: 111115201
Test: make aapt2_tests
Change-Id: Ifa5df924b5e2265c32cdcf8ca7dfa4a3992a0468
2019-09-16 17:29:46 -07:00
Brian Chang
d882ba40db Rename flags in aapt2-optimize for more accuracy and consistency.
--enable-resource-path-shortening => --shorten-resource-paths
--enable-resource-obfuscation => --collapse-resource-names

Bug: 140883718
Test: Verified by running `aapt2 optimize
Change-Id: I697713f49b27ccf5f152c76e256234c041dc5f51
2019-09-16 13:09:56 -07:00
TreeHugger Robot
b13c6bbdf8 Merge "Allow compile output to be either a zip or dir" 2019-09-05 13:32:30 +00:00
Ryan Mitchell
c7db244cbe Allow compile output to be either a zip or dir
When passing a directory to compile using --zip or --dir, the -o flag
had to represent a zip file the compiled contents would be written to.
Now, if the path specified by the -o flag is a directory, the compiled
files will be written to the directory rather than erroring out.

Also when passing files to compile as file arguments, the -o flag had to
represent an existing directory. Now, if the path is not an existing
directory, the compiled files will create a zip file at the path that
contains the compiled files.

Test: manual
Change-Id: I92a8e124d53cdb653eb3a7ec549f09f9ad0ef04f
2019-08-28 11:21:47 -07:00
Ryan Mitchell
2814793744 Merge "Add --exclude-sources to AAPT2 link" 2019-08-14 21:29:16 +00:00
Ryan Mitchell
ef9e688393 Add --exclude-sources to AAPT2 link
Information about where resources are defined can make having
reproducible builds more difficult, makes the generates resources.pb
large, and can exposes details about the machines that compiled the
resources.

The --exclude-sources flags can only be used when building a proto APK
and prevents source information from being included in the generated
resources protobuf.

Bug: 134929532
Test: checked debug string with and without the string
Change-Id: Ia345f067fe781ea82a4bcad37eb55576c72c44d7
2019-08-14 19:28:32 +00:00
Donald Chai
d554f7c597 Fix uninitialized variable.
"aapt2 optimize" without --enable-resource-path-shortening should not do
resource-path-shortening.

Bug: 75965637
Change-Id: Ibcbf325e66ed7992bf81184260abd63711b2af2a
2019-07-10 18:50:15 -07:00
Udam Saini
1710e8370e Merge "Allows features to link to other feature splits without namespacing." 2019-06-27 16:05:22 +00:00
TreeHugger Robot
5e4c18b05c Merge "AAPT2: Merge-only mode for building static libraries" 2019-06-27 12:01:35 +00:00
Udam Saini
b228df32d9 Allows features to link to other feature splits without namespacing.
Add uses-split dependencies to AppInfo. At link time, this is used
and allows features to reference other features, before
resource namespacing is implemented in Android Studio.

bug:135681292
Test: Link_test, ReferenceLinker_test, and integration tests.
Change-Id: Ifdf0067e7370552b6b9d4d6d4713d4484b6ea154
2019-06-26 13:30:35 -07:00
Izabela Orlowska
84febeacb9 AAPT2: Merge-only mode for building static libraries
Add a new option for skipping resource references validation when
building a static library. This pushes resource reference validation
to the final link step (creating an installable APK), but allows a lib
to be linked without having the static libs of its dependencies.

More context: go/autonamespace-transform

Test: MergeOnlyTest + manually verified
Bug: 128824820
Change-Id: I1f3e3b7715a5244b8633c85519d94334c76ff664
2019-06-24 16:12:19 +01:00
Elliott Hughes
e6936e2792 Merge "Move off ZipString and over to std::string/std::string_view as appropriate." into qt-dev-plus-aosp am: ee1c95f060
am: 0566225cb8

Change-Id: I351ea009ee322ecd8bd117e4b2b686c636fb6770
2019-06-17 16:39:52 -07:00
Elliott Hughes
78de4f999d Move off ZipString and over to std::string/std::string_view as appropriate.
Bug: http://b/129068177
Test: treehugger
Change-Id: Ib46761d89772d3a3c655a39df573fd305c117d19
2019-06-17 16:47:58 +00:00
TreeHugger Robot
ea66257ecd Merge "Alias v26 round icons to adaptive icons like aapt1" 2019-06-14 18:14:14 +00:00
Ryan Mitchell
dba6456152 Alias v26 round icons to adaptive icons like aapt1
When a developer specifies an adaptive application icon,
and a non-adaptive round application icon, create an alias
from the round icon to the regular icon for v26 APIs and up.

We do this because certain devices prefer android:roundIcon over
android:icon regardless of the API levels of the drawables set for
either.

This auto-aliasing behaviour allows an app to prefer the
android:roundIcon on API 25 devices, and prefer the adaptive icon on
API 26 devices.

Bug: 34829129
Test: manual
Change-Id: Ifac49455da749afde636fd4bb8cf32308f8b1e0a
2019-06-14 09:31:44 -07:00
Donald Chai
121c6e8aa0 [aapt2] Add "link" option to override styles instead of overlaying.
For normal app development, the desired linking semantics are:
* styleables - take union of all definitions
* all other resources - take last non-weak definition

This differs from the semantics needed in other scenarios, where
merging/overlaying styles is desired.

Bug: 134525082
Change-Id: Iac0c43ca2ecf1f3fddc9c3367f8914c12c9258e1
Tested: aapt2_tests
2019-06-12 16:58:45 -07:00
Ryan Mitchell
81dfca0e05 Fix asset compression to check name ends with arg
There exists a discrepancy between how aapt1 and aapt2 prevent the
compression of assets using the -0 flag. aapt1 checked if the file name
ended with an argument, but aapt2 is checking if the file extension
exactly matches the argument. This change makes aapt2 behave the same as
aapt1 for asset compression using the -0 flag.

Bug: 132823799
Test: aapt2_tests
Change-Id: I641b3ebce29e4407b543faea373a5ce516b70cda
2019-06-10 08:59:52 -07:00
Elliott Hughes
65c8b86b3f Don't explicitly specify no prefix/suffix.
Bug: http://b/129068177
Test: treehugger
Change-Id: Ica29efa3c3e49f556157cb0f82fdadef91aadba8
2019-05-11 00:13:09 +00:00
Mihai Nita
d1a6521cc3 Fix aapt2 pseudo-translating donottranslate* files
Bug: 126423638

Test: After building android doing this in the 'out' folder:
Test:
Test: ./soong/host/linux-x86/bin/aapt d --values resources \
Test:     ./target/product/sailfish/system/product/priv-app/SystemUIGoogle/SystemUIGoogle.apk \
Test:     | less
Test:
Test: search for `system_ui_aod_date_pattern` in the output, found this:
Test:           (string8) "[éééḾḾḾð one two]"
Test:           (string8) "<U+200F><U+202E>eeeMMMd<U+202C><U+200F>"
Test: (the en-XA and ar-XB pseudo-translated versions of the string)
Test:
Test: After the fix and rebuild the dump only finds the original English string ("eeeMMMd")
Test: Also flashed the image, switched to en-XA, and left the phone around for more than 24 hours.
Change-Id: I2fb7c5b5ee7d3d3200410593346682ed16559056
2019-03-29 17:15:18 -07:00
Ryan Mitchell
95d2c302d5 Merge "Compile all files in res/xml as xml" 2019-03-25 15:49:14 +00:00
Fabien Sanglard
362da826af AAPT2: Add missing description for dump command
Test: None
Bug: None
Change-Id: Id9d6a38ad292dc2647bdb4ad9f7a0015120fa776
2019-03-14 11:39:39 -07:00
Ryan Mitchell
62b68341e8 Compile all files in res/xml as xml
AAPT(1) compiled all files in res/xml as xml. Continue to do the same to
prevent regressions.

Bug: 122321161
Test: manual
Change-Id: I99c80da6d304c13ce911cd5258fd561f3c9e91b4
2019-03-11 13:28:02 -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
1b05ef9cc1 Merge "Sort inputs to compile and link" 2019-02-26 21:48:08 +00:00
Ryan Mitchell
f22ed8dc0e Sort inputs to compile and link
This change sorts the input files of compile and link and also traverses
directories in sorted order in FileCollection::Create. This change
attempts to fix non-determinism issues with aapt2.

Bug: 122518436
Test: builds
Change-Id: I615b8d7f1117e3850366760f16672f0cf5b02070
2019-02-26 17:40:30 +00: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
03f311cb75 Merge "Revert "Fix loaded apk string pool order"" 2019-02-16 00:46:04 +00:00
TreeHugger Robot
6d9fc1c8de Merge "Prevent AAPT2 from versioning <set> tags" 2019-02-15 23:26:25 +00:00
Ryan Mitchell
90b7a08aaf Revert "Fix loaded apk string pool order"
This reverts commit 4e9a922ede.

Reason for revert: <b/122518436>

Change-Id: I3650b2c6c9bdfa69a3034f9ca49e95a9698c3cdd
2019-02-15 14:37:45 -08:00
TreeHugger Robot
275c3ec658 Merge "Option to exclude configs from AAPT2 Link" 2019-02-01 02:13:08 +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
TreeHugger Robot
ced0b0c90c Merge "De-duplicate entries written with AAPT2 convert" 2019-01-25 22:03:49 +00:00
Winson
f54c9a1d72 De-duplicate entries written with AAPT2 convert
There was no check for whether we had already written a specific file path to the APK when using the convert command.

If the resources table points 2 resource IDs at the same file on disk, the convert command would write the file twice, creating two entries.

This holds a set of file paths already written and ignores duplicates.

Bug: 123271593

Test: Ran convert on linked bug's weird.apk
Test: aapt2_tests case for duplicate entries

Change-Id: Ia22515bf8e8297624aaadbf6a9e47159026c63e5
2019-01-24 16:10:16 -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
TreeHugger Robot
636da777af Merge "Hold data pointer reference to AAPT2 test file" 2019-01-24 07:50:24 +00:00
Winson
b7be7934b0 Hold data pointer reference to AAPT2 test file
To try and solve test flakiness, hold the unique_ptr in the method scope to make sure it's cleaned up after we assert on it.

Bug: 123079798

Test: gonna merge and check for failures, since it passes locally

Change-Id: Id348d1112832cbb82f605a84ef675c25a7488b11
2019-01-23 11:11:12 -08:00
Ryan Mitchell
f67808b78d Optimize aapt2 compile for pngs
Do not copy the png data when compiling pngs.

Bug: 122950060
Test: aapt2 compile -o . BaseAppPhoto1_copy.png

Change-Id: I78fbdaa9a40ada406d7b07cf072d6cd76124168e
2019-01-22 16:16:13 -08:00
Izabela Orlowska
a3ab21f04a AAPT2: always say which file failed to compile
Sometimes AAPT2 doesn't include the path of the file in the error
message, or just outputs a warning where an error should be printed
(but the overall build still fails without an error message). Let's
always include the file path to make it easier for the users to find out
the source of the failure.

Fixes: 122856772
Test: manual
Change-Id: Ibbbfd21b372792e5eaa40278186eb64cdfb0f60e
2019-01-17 12:12:25 +00:00