79 Commits

Author SHA1 Message Date
Adam Lesinski
38665547bb AAPT2: Treat non-AAPT attributes as Attributes with no format specified.
Attributes in XML like "class" should be treated as attributes with no
format specified. That means that something like 'version="1"' will
be interpreted as an Integer value instead of as a string.

This is more in line with the old AAPT behaviour.
Bug: 30763349
Test: make libaapt2_tests

Change-Id: I02fe41617e3c62c354714056198ef480d62afee7
2016-12-28 12:40:35 -05: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
e343eb145c AAPT2: Insert <uses-sdk> element before <application>
PackageParser on the device uses the targetSdkVersion of the
app while it parses <application>. That means that if the
<uses-sdk> tag comes after <application>, the targetSdkVersion
is assumed to be 0.

Test: make libaapt2_tests
Change-Id: I60f2179a7ff44e7419217afb53f3d24f8c030f6e
2016-10-27 16:31:58 -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
6a396c1abb AAPT2: Error on uncompiled XML or PNG files in link phase
Incorrectly passing text XML and unprocessed PNG files to
the AAPT2 link phase should raise an error.

Test: manual incorrect invocation of aapt2
Change-Id: Iab47f99bc378b5d1c4f4d87098f08243b9a4dc6a
2016-10-20 14:40:49 -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
Alexandria Cornwall
77788eb4cf AAPT2: Add dominator tree analysis and resource removal
Added dominator tree analysis of resource configurations for each
resource entry to allow deduping of resource entries if:

1. The configuration for the resource entry's value is dominated by
a configuration with an equivalent entry value.

2. All compatible configurations for the entry (those not in conflict
and unrelated by domination with the configuration for the entry's
value) have an equivalent entry value.

Bug: 30051199
Test: make libaapt2_tests && libaapt2_tests
Change-Id: I66468d3014a2d6097a94b039ac1028f9f461c7d3
2016-09-30 18:27:13 -07:00
Adam Lesinski
a0b929d27f AAPT2: Allow <compatible-screens><screen> in AndroidManifest.xml
Change-Id: I1e7c7211be1d9caea4174f7cac067c2565879d04
2016-09-19 09:50:45 -07:00
Adam Lesinski
871f2f5fc2 Merge "AAPT2: Add Inline Complex XML support" 2016-09-02 18:49:46 +00:00
Adam Lesinski
5eeaaddffd AAPT2: Add Inline Complex XML support
See: https://developer.android.com/guide/topics/resources/complex-xml-resources.html

Change-Id: I8274c85e25cabf90423141c228697e873167d136
2016-08-31 18:32:34 -07:00
Adam Lesinski
085f495747 AAPT2: Revert warning when merging packages
A compiled ResourceTable may contain multiple packages.
When referencing a framework attribute, for instance,
the compile phase has no idea if that attribute is a USE
or a DECLARATION, like so:

  <declare-styleable name="Foo">
    <item name="android:id" />
  </declare-styleable>

If this file is compiled with the package 'android', then this
is a declaration. If it is compiled with the package 'com.foo',
this is a reference that must resolve at link time.

Since this is common, warning that the package 'android' is being
ignored during the merge phase is incorrect behaviour.

The warning was antroduced in ag/1363992

Change-Id: I09254d79ac379439face177eb724df882d1d0ce1
2016-08-30 14:25:51 -07:00
Adam Lesinski
5c3464c75f AAPT2: Fix merging of styleables the right way
Styleables should only be merged when processing overlays.
This moves the styleable merging code out of ResourceTable
and into TableMerger.

Change-Id: I3aae05cf4dd875cd25ac2ac744b61194409b2fee
2016-08-26 19:40:50 -07:00
Alexandria Cornwall
a7cc3f1d79 AAPT2: Add support to strip namespaces from XML
The --no-xml-namespaces flag will strip namespace information from
compiled binary XML files in res/* (excluding res/raw/*) and
AndroidManifest.xml. It will also strip URI information from compiled
binary XML files in res/* (excluding res/raw/* and AndroidManifest.xml).

AndroidManifest.xml URI information is retained due to PackageParser, which
requires the Android URI for intent filters.

Bug: 29115919
Change-Id: I90cad6ed39ce02a69776f55314c1d4f38ad1aabe
2016-08-17 11:01:05 -07:00
TreeHugger Robot
e42bc0587f Merge "Fix clang-tidy warnings in aapt and aapt2." 2016-08-15 21:10:23 +00:00
TreeHugger Robot
1d740812e6 Merge "AAPT2: Expose split support to command line" 2016-08-15 20:46:38 +00:00
Chih-Hung Hsieh
470f8fcb5c Fix clang-tidy warnings in aapt and aapt2.
* Add explicit keyword to conversion constructors.
* Add NOLINT(implicit) comments for implicit conversion constructors.
Bug: 28341362
* Use const reference type for read-only parameters.
Bug: 30407689
* Add NOLINT to suppress wrong clang-tidy warnings on macros.
Test: build with WITH_TIDY=1

Change-Id: Ibfafb23d9be463b4072745a51a6d9f1812dcac45
2016-08-15 12:32:51 -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
Alexandria Cornwall
c34027ec3d Merge "AAPT2: Fix resource type id symbol merging" 2016-08-12 19:27:32 +00:00
Chih-Hung Hsieh
9b8528fee4 Fix clang-tidy warnings in aapt and aapt2.
* Add explicit keyword to conversion constructors.
* Add NOLINT(implicit) comments for implicit conversion constructors.
Bug: 28341362
* Use const reference type for read-only parameters.
Bug: 30407689
* Use const reference type to avoid unnecessary copy.
Bug: 30413862
Test: build with WITH_TIDY=1

Change-Id: Id6d21961f313a1ad92b15a37fdaa5be9e8ab48e1
2016-08-11 15:16:41 -07:00
Alexandria Cornwall
6a1f8dbd51 AAPT2: Fix resource type id symbol merging
By the looks of things, AAPT2 should be able to merge public type and entry
symbols iff their types and resource IDs match.

Change-Id: Ie99071418aa89aad56de5e5b96e98b96d0d15d7a
2016-08-11 14:46:27 -07:00
Alexandria Cornwall
8eefa04826 Merge "AAPT2: Reorder link steps" 2016-08-11 18:33:02 +00:00
Alexandria Cornwall
637b4820dc AAPT2: Reorder link steps
AAPT2's link steps were writing the res/* files before optimizations to the
resource table were performed (such as version collapsing). This was causing
unreferenced res/* files to remain in the archive, even though they're no
longer necessary.

Bug: 30705740
Change-Id: I50d7943ef7429b14e46587093855c15d54038299
2016-08-11 09:53:16 -07:00
TreeHugger Robot
b80b6dabcb Merge "AAPT2: Parse coreApp in <manifest> as boolean" 2016-08-10 19:52:24 +00:00
Adam Lesinski
6b17d2cec2 AAPT2: Parse coreApp in <manifest> as boolean
Bug:30751662
Change-Id: I283be5725426ee084944c1921df40d1bd6188028
2016-08-10 11:37:06 -07:00
Alexandria Cornwall
f6762fc22a AAPT2: Merge binary XML file attributes
AAPT2 generates extra versions of XML binaries based on the sdkVersion
that attributes were introduced, up to v21. This should only happen for
sdkVersions that are > minSdkVersion, as everything else can be included
in the main configuration (e.g. "layout" instead of "layout-v4").

This change handles the merging of XML binary sdkVersions that were created
implicitly.

Bug: 30705740
Change-Id: I854843dd6dbaca52896cea0c24c70c900cec3e8e
2016-08-09 13:23:03 -07:00
Adam Lesinski
9756dec248 AAPT2: Add default no-compress extensions
Change-Id: Iff0820993059bcab59208b07601b2c6d8d953c89
2016-08-08 12:41:45 -07:00
Adam Lesinski
bad90c3888 AAPT2: Add missing error statement
Change-Id: I955ba6f151d68db02c3dc16d121994fb553dcea8
2016-08-02 11:39:17 -07:00
Adam Lesinski
bb5a390142 AAPT2: Allow <intent-filter> within <provider> in AndroidManifest.xml
Change-Id: I005120b76679f51039ddc40160c96ead6ab5fa4f
2016-08-01 15:01:08 -07:00
Adam Lesinski
58a20a6482 AAPT2: Change accepted notation for resource names in tests
Previously the way to name resources in tests was to use reference
notation (@[package:][type/]name). Now we use name notation (no @).

Change-Id: I68f0a36562d89cc78c582d128f370d9556c58707
2016-07-25 17:56:58 -07:00
Adam Lesinski
bf0bd0f9ac AAPT2: Add support to specify stable IDs
The --stable-ids flag allows the user to specify a file containing
a list of resource name and resource ID pairs in the form of:

package:type/name = 0xPPTTEEEE

This assigns the given resource the specified ID. It helps ensure
that when adding or removing resources, IDs are assigned in a stable
fashion.

If a package, type, or name is not found, no error or warning is
raised.

Change-Id: Ibc2f4e05cc924be255fedd862d835cb5b18d7584
2016-07-25 16:02:18 -07:00
Adam Lesinski
87675ada47 AAPT2: Erase version qualifiers for resources <= minSdk
When resources share the same configuration, they are much more
clustered in the resulting resources.arsc, which makes for smaller
APKs. Strip version qualifiers for resources <= minSdk so that
they get clustered.

Bug:30050641
Change-Id: I80371b179761501fb7cc41f5f5ac67ffde2fc677
2016-07-15 18:04:56 -07:00
Adam Lesinski
d0f116b619 AAPT2: Remove usage of u16string
For legacy reasons, we kept around the use of UTF-16 internally
in AAPT2. We don't need this and this CL removes all instances of
std::u16string and StringPiece16. The only places still needed
are when interacting with the ResTable APIs that only operate in
UTF16.

Change-Id: I492475b84bb9014fa13bf992cff447ee7a5fe588
2016-07-13 17:45:28 -07:00
Adam Lesinski
71965e898e AAPT2: Fix fully qualified java class verification
Proguard rules would be ignored for components defined
in AndroidManifest.xml for android:name attributes if
they didn't start with '.'.

Change-Id: I029b5a2f224f4daf155b73a2a4dcd940dd43372e
2016-07-07 17:17:55 -07:00
Adam Lesinski
fb6312fe93 AAPT2: Add version collapsing
When an app specifies (or imports) resources with various
configurations for different SDK versions, specifying
a minSdk will make many of those resources unreachable.

Version collapsing will prune out the resources specified
for SDK versions less than the minSdk.

If, however, there is no exact matching resource for the
minSdk version, the next smallest SDK version is kept.

Change-Id: Ic7bcab6c59d65c97c67c8767358abb57cdec60a4
2016-06-29 17:02:19 -07:00
Adam Lesinski
1e21ff00b0 AAPT2: accept argument file list for -R
Bug:29462255
Change-Id: Ia83919a3e7de7fe2056a3f7613621972cccd49cb
2016-06-24 14:57:58 -07:00
Adam Lesinski
5d84ad5487 AAPT2: Allow <meta-data> in <application> tag
Change-Id: Ica3e7d5c1ce587eba58d8171e0f8d5cdb598e7b3
2016-06-23 13:18:16 -07:00
Adam Lesinski
5fcfdab573 Merge "Allow uses-library under <application>" into nyc-mr1-dev am: c878fb0cb8
am: b80680af78

* commit 'b80680af787dfb27e5a4b1b0edae8502373c4935':
  Allow uses-library under <application>

Change-Id: I078857ace29f7f35b9efbee99f4278b7c7ba9c9e
2016-06-03 00:44:51 +00:00
Adam Lesinski
fee32d4d5f Allow uses-library under <application>
Bug:29106952
Change-Id: I2e780323d86e7050038d34426a30e66a4bbfcc23
2016-06-02 23:57:55 +00:00
Chih-Hung Hsieh
d53e3bed1c Fix google-explicit-constructor warnings.
Bug: 28341362
Change-Id: I080090d50f1a368a4e7c1a0732297bb6a295e34f
2016-05-03 10:02:51 -07:00
Adam Lesinski
5fcf5d4fec Merge "AAPT2: Accept a file with arguments when argument list is too long" into nyc-dev am: 28d6c1e493 am: 461be97e30
am: e59d48398f

* commit 'e59d48398f983b822191ea3096499bdd0793840a':
  AAPT2: Accept a file with arguments when argument list is too long

Change-Id: Iad1d2b91109b0d1c78739c3fa3f31da5e0704f12
2016-04-28 20:05:24 +00:00
Adam Lesinski
c51562cf5a AAPT2: Accept a file with arguments when argument list is too long
Bug:22775504
Change-Id: Ife73d4e4611016c9ee7b56264bc6a765c54beba3
2016-04-28 11:14:38 -07:00
Rohit Agrawal
e49bb30dab AAPT2: ProGuard config for components in main dex.
Create an analogue of "aapt2 --proguard" which outputs a proguard
configuration that keeps only components which need to be in the main
dex.

Bug: 27383099

Change-Id: I61d652bfcdfc18e1614e852bd6f7540efd15f780
2016-04-22 14:40:40 -07:00
Adam Lesinski
5ff3ad6312 SettingsLib: Build with AAPT2
Bug:22775504
Change-Id: I2e5015235384d124418d32186daa190f38e1c5b3
2016-04-14 14:45:21 -07:00
Adam Lesinski
c728c3daba AAPT2: Allow <protected-broadcast> and <eat-comment> in AndroidManifest.xml
Change-Id: I38c49a2a31e560dec963d44d94e067035fd59150
2016-04-06 17:40:25 -07:00
Adam Lesinski
cc5609d8e4 AAPT2: Implement XmlActionExecutor to verify manifest
Defines a set of actions to perform on XML elements defined by their
hierarchy, eg: manifest -> application -> activity.

This can be used to easily add rules to check more tags in AndroidManifest.xml

Change-Id: I76c6916a98b6403075a7e56e16230979dc6cbee1
2016-04-06 11:37:05 -07:00
Adam Lesinski
3524a23edb AAPT2: Add option to add JavaDoc annotations to Java classes
Change-Id: I7ee8c20cdd91380927a65c41097ffd3a6ffa2df5
2016-04-04 12:42:05 -07:00
Adam Lesinski
6cbfb1de49 AAPT2: Change how we generate Java classes
Previously we would be writing out the Manifest.java file as we
processed the AndroidManifest.xml. This would lead to empty
Manifest classes if there were no permissions or permission groups
defined in the AndroidManifest.xml.

This would pose problems for processes that checked for public classes
and considered them part of the API (support lib).

Now we collect the structure of the Java class in memory before deciding
if a file should be created.

Change-Id: I6b909f28d74356414c6ef5ad005180d6ea5e44ca
2016-03-31 16:43:04 -07:00
Adam Lesinski
330c57dbd1 Merge "AAPT2: Add descriptions of Attributes in Styleables for R.java" into nyc-dev 2016-03-11 09:16:44 +00:00
Adam Lesinski
7656554f91 AAPT2: Add descriptions of Attributes in Styleables for R.java
Change-Id: I69e7b73cbdfe4baf502348397435c501ae29ff5e
2016-03-11 00:22:52 -08:00
Adam Lesinski
96917c25f0 AAPT2: Fix file::mkdirs when given absolute paths
file::mkdirs would try to extract the first part of the
path '/path' which would be the empty string ''. Mkdir would
fail creating the empty string directory.

Change-Id: Ice8ba92135f145f52f3663499a2c49eebe797328
2016-03-09 13:23:12 -08:00