Commit Graph

975 Commits

Author SHA1 Message Date
Ryan Mitchell
9cdb3cdbb8 Merge "Only check sibling config values to dedupe" 2019-08-19 23:53:55 +00:00
Ryan Mitchell
f64b9d8306 Only check sibling config values to dedupe
Currently more config values are being kept than necessesary. For
example, given config values for a string resource:

Config: default     Value: "keep"
Config: ldrtl       Value: "dedupe"
Config: ldrtl-night Value: "dedupe"
Config: land        Value: "keep2"

The ldrtl-night config value will fail to be removed despite being
equivalent to the ldrtl value. This is because the value for the land
configuration is not equivalent to the ldrtl-night value. Instead of
checking that every compatible config value not related by dominance
should have quivalent values, only check sibling config values within
the dominator tree.

Bug: 137230022
Test: aapt2_tests
Change-Id: I965365d1a9433ae595eab48d82837ac102148334
2019-08-19 17:48:46 +00: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
Mohamed Heikal
f41bd8d10c Merge "ResourcePathShortener deterministically handles hash collisions" 2019-08-06 20:42:48 +00:00
Dave Ingram
7e0e4c11f2 Badging should print package attributes at most once
Following up to change 7938786; if an APK had platformBuildVersionCode
compiled as *both* integer and string, it would be output twice. This
then confuses anything that tries to parse the output.

With this change, the value will be printed at most once, with the
string version taking priority.

Bug: 138666693
Test: manually built SDK28 APK and ran aapt2 dump badging
Change-Id: Icf6eb656ac0cb263969bb2f0c5ca03139985f6ca
2019-08-01 16:10:33 -07:00
Mohamed Heikal
b2bac12ce8 ResourcePathShortener deterministically handles hash collisions
ResourcePathShortener appends one digit at the end of colliding short
file names to disambiguate them. This cl sorts the list of file paths so
that colliding files always get the same disambiguating digit from one
run to the next rather than possibly alternating.

Test: make aapt2_tests

Change-Id: I983a1448c21f2c79d7cdb1de232e7758c04fc256
2019-07-30 15:52:38 -04:00
TreeHugger Robot
b502f1718c Merge "Adds queries tag to manifest" 2019-07-25 13:38:34 +00:00
Patrick Baumann
a4ffb4567e Adds queries tag to manifest
This change adds support for a new <queries> tag as a child of the
<manifest> tag, allowing a package to declare the intents it intends to
use to query for other apps on device.

Bug: 136675067
Test: build and boot
Change-Id: Ic8b40cabddee4b6404c220901efeaae680661c0c
2019-07-24 15:24:03 -07:00
Mohamed Heikal
60ca0dbefb Merge "Precalculate the required number of characters for path shortening" 2019-07-22 17:12:01 +00:00
Mohamed Heikal
525714a88b Precalculate the required number of characters for path shortening
It does not make sense for aapt2 to calculate the optimal number of
chars in the shortened path when it only depends on the number of
resources rather than anything apk specific. This cl precalculates the
number of chars and uses if conditions instead.

Test: manual testing + aapt2_tests still passes.
Change-Id: If2dc86952a6b6e01ce02dc42754c037d07d57325
2019-07-18 15:57:13 +00:00
TreeHugger Robot
3344bfcb84 Merge "Fix uninitialized variable." 2019-07-15 15:51:04 +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
Mohamed Heikal
61d528f49d Fix bug where aapt2 optimize obfuscated color-* resources
aapt2 optimize --enable-resource-path-shortening should ignore res/color
resources since android uses the path while loading them. This cl fixes
a bug where res/color-* (eg: res/color-v21) resource paths are shortened
when they should not be.

Test: make aapt2_tests
Bug: b/75965637
Change-Id: Ibbc3fe4d2e6bd4f31765a5aa85980907dc013ecd
2019-07-08 16:28:42 -04:00
TreeHugger Robot
55f43ef860 Merge "Remove lite optimization from protos" 2019-06-29 03:49:46 +00: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
Donald Chai
0cc25fe7f8 Merge "[aapt2] Ensure that attributes have declared namespaces when fixing manifest" 2019-06-10 20:36:49 +00:00
Ryan Mitchell
8bf7e092ba Merge "Fix asset compression to check name ends with arg" 2019-06-10 18:27:58 +00: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
Ryan Mitchell
c1676807f4 Retain parsed attribute type
If the value of an attribute enum is defined as a hexadecimal integer,
flatten uses of the attribute as with the
android::Res_value::TYPE_INT_HEX type.

This change adds a "type" field to pb::Attribute::Symbol, which if left
unset, will have a default value of android::Res_value::TYPE_INT_DEC
when deserialized by aapt2.

Bug: 124474141
Test: aapt2_tests and manual compilation of files and inspection using
`aapt2 dump chunks`
Change-Id: Ibf12394284fdbe3a8047f7ecf4fe68517dfc3abb
2019-06-06 14:19:26 +00:00
Donald Chai
6e49735aa8 [aapt2] Ensure that attributes have declared namespaces when fixing manifest
aapt::ManifestFixer might add attributes from
http://schemas.android.com/apk/res/android when none existed previously.
When that happens, something needs to ensure that the schema has a
declared xmlns prefix, otherwise this:

bdb3e97c47/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceLinker.java (L560)

will crash.  It's a bit odd that Bazel converts back and forth between
protobuf and XML, but as long as the fields exist in Resources.proto,
they should be set.

Bug: 133004752
Change-Id: I73fb3f713be34c9f81753fde2fd24c4524656b7d
Tested: aapt2_tests
2019-06-05 19:42:42 -07:00
Ryan Mitchell
a36cc98af5 Badging should print compiled platform version
aapt2 saves space by compiling all raw xml strings to the Res_value
structure. This causes the platformBuildVersionCode and
platformBuildVersionCodename attributes on the <manifest> tag to be
compilled as integers. aapt2 and aapt dump badging assumed these values
would be strings and is failing to print the value for these attributes.

With this change, the value will be printed regardless if it is encoded
as an integer or string.

Bug: 130830770
Test: manualy build APK and run aapt2 dump badging
Change-Id: I89487db36c6bc4d0fde3a410b7a64debfec5021e
2019-06-05 10:13:41 -07:00
Donald Chai
b479de36fa Merge "[aapt2] Pseudolocalize <plurals> values." 2019-06-03 21:58:59 +00:00
Donald Chai
44fa342eb9 [aapt2] Fix infinite loop in proguard::CollectLocations
std::set only works correctly when the < comparator is a strict weak
ordering, while UsageLocation::operator< was actually implementing !=.

Bug: 134190468
Change-Id: Icb9407e9c8451f9fcb4eb9b2cea310e3bcaf159e
Tested: aapt2_tests, and b/134190468#comment1
2019-06-03 11:28:45 -07:00
Donald Chai
4c3da0f8a4 [aapt2] Pseudolocalize <plurals> values.
(.won slaer roF)

Bug: 134190774
Test: aapt2_tests
Change-Id: If307af4adfb1d556c41d7cb08590d1c25287f992
2019-06-03 03:02:43 +00:00
Ryan Mitchell
fc3874ac82 Empty attribute values in styles should be strings
In aapt1, if you specified the value of an attribute in a style as an
empty string (eg. <item name="my_attr"></item>), the encoded value would
be an empty string. In aapt2 currently, @null is encoded instead. This
change restores aapt1 behavior. Use @null explicitly if the desired
value is to be @null.

Bug: 133450400
Test: manual comparison of APK created by aapt1 and aapt2
<attr name="my_attr" format="string|reference" />
<style name="MyName">
    <item name="my_attr"></item>
</style>

$ aapt p -M AndroidManifest.xml -F out1.apk -S res -f

$ aapt2 compile --dir res-o compiled.flata
$ aapt2 link --manifest AndroidManifest.xml -o out2.apk compiled.flata
$ aapt2 dump out2.apk

Change-Id: I8aa0ba30379dac0b1229da525abbc5482f40114b
2019-05-28 23:44:13 +00:00
Ryan Mitchell
22ead1c3b0 Remove lite optimization from protos
aapt2 does not require the lite runtime optimization to reduce binary
size. Removing the allows for the protos to be optimized for speed
instead of binary size and grants access to refelctive operations.

Test: aapt2_tests on linux and windows
Change-Id: Ie7ed9df4061e2eb60adbd300eb358d4c3f32c80c
2019-05-21 10:54:00 -07:00
Ian Pedowitz
b60dac3de7 Merge "Revert "Revert "Android Q is API 29""" into qt-dev am: a326dfb1e5
am: 203ac63ea6

Change-Id: Ie8de73de0fae8fe9cd044b122f8733f283662f3c
2019-05-15 23:43:17 -07:00
Ian Pedowitz
203ac63ea6 Merge "Revert "Revert "Android Q is API 29""" into qt-dev
am: a326dfb1e5

Change-Id: I50abb7ed7a0c3730da90c4a6951971df1e4e6ef3
2019-05-15 17:59:43 -07:00
Ian Pedowitz
563abce4ed Merge "Revert "Revert "Android Q is API 29""" into qt-dev
am: a326dfb1e5

Change-Id: I0674668835cd5a281e8a01c4b5bdb870595a8305
2019-05-15 13:36:05 -07:00
Ian Pedowitz
a326dfb1e5 Merge "Revert "Revert "Android Q is API 29""" into qt-dev 2019-05-15 16:28:54 +00:00
Elliott Hughes
225df5d563 Merge "Don't explicitly specify no prefix/suffix." am: 480d18c472 am: d47c87a2e6
am: 78e68ceb2b

Change-Id: I5040185c71b353fa028b1b21ddef7bfb37870e06
2019-05-13 11:36:39 -07:00
Elliott Hughes
78e68ceb2b Merge "Don't explicitly specify no prefix/suffix." am: 480d18c472
am: d47c87a2e6

Change-Id: I7cc6d962ec602c844ad9e7f6179260e247b04dc8
2019-05-13 11:22:04 -07:00
TreeHugger Robot
b73b3eab0f Merge "[aapt2] Set use_version_lib." 2019-05-13 14:50:48 +00:00
Elliott Hughes
a0a447024c Merge "Don't explicitly specify no prefix/suffix." into qt-dev-plus-aosp
am: 725cf7ff2b

Change-Id: Ib1864deeb20f99fbdf3f2b3a84e3beb7e9b63cc5
2019-05-12 20:50:28 -07:00
Ian Pedowitz
1912a57900 Revert "Revert "Android Q is API 29""
This reverts commit 60c71cee6e.

Reason for revert: Rolling forward for Q-Finalization

Bug: 131429032
Bug: 129975435
Change-Id: Idd812d93b767d8a672b9ada58c8bcc2441395847
2019-05-12 19:44:42 +00:00
Donald Chai
2ee7cc6ee9 [aapt2] Set use_version_lib.
This is needed by the build system to update soong_build_number.

On a local build, "aapt2 version" used to print:
  Android Asset Packaging Tool (aapt) 2.19-SOONG BUILD NUMBER PLACEHOLDER
Now it prints:
  Android Asset Packaging Tool (aapt) 2.19-eng.dchai.20190511.023434

Bug: 132476779
Bug: 123663089
Change-Id: I5bc5adc9f5b2a7a30bdc649e3c073868b55f17df
Tested: manual, see above
2019-05-11 20:38:43 +00: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
Elliott Hughes
f31f126ed8 Don't explicitly specify no prefix/suffix.
Bug: http://b/129068177
Test: treehugger
Change-Id: I987c88c17b7d1fd01129545bdbd4178de446188c
2019-05-10 17:02:14 -07:00
Donald Chai
e83c451060 Merge "[aapt2] Close empty lists in "dump resources"." 2019-05-08 20:51:10 +00:00
Donald Chai
42fe2b2ac7 [aapt2] Close empty lists in "dump resources".
Bug: 129134933
Test: manual (b/129134933#comment4) since there's no Debug_test.cpp
Change-Id: Ib31481457089eade6f1d380cff4eeba0ff0c499d
2019-05-07 21:08:36 -07:00
Ryan Mitchell
bfdebbbd3d Merge "DO NOT MERGE: Fixed broken aapt2 tests" into qt-dev
am: cbe933a40f

Change-Id: Ic0da145919936b8427ba9c6504606f1708832631
2019-05-07 10:48:07 -07:00