82 Commits

Author SHA1 Message Date
Adam Lesinski
74605cd402 AAPT2: Emit proper doclava comments in R.java
Bug:25958912
Change-Id: I663f2eb5bd54e3c3288ce9bc186c928f0a014f93
2016-03-04 20:06:05 -08:00
Adam Lesinski
626a69f345 AAPT2: Support --no-version-vectors
Change-Id: I8029b2f9e2f7ab8e37a49565f95210f47a7be609
2016-03-04 17:02:42 -08:00
Adam Lesinski
64587af817 AAPT2: Support building, linking, and merging static libraries
Android static libraries are like APKs but they contain much more debugging
and source information. We need to treat them differently in 3 ways:

1) When building a static library, we skip things like ID assignment and
   product/config stripping. Source information is emitted as well.
2) When building a static library and linking against another
   static library, we don't want to merge, we want to simply reference.
3) When building an app that uses static libraries, we want to merge
   the static library under the same package with or without mangling.

Bug:25958912
Change-Id: I425e032857936a3e83173c1edc2a6cdc6020b842
2016-03-04 14:39:01 -08:00
Roozbeh Pournader
7960898f6f Fix script-related parts of locale resource matching
Previously, a bit was kept to find if the script of a locale was
explicitly "provided" in a resource. This was not backward
compatible, and failed in some edge cases when the package was
created with older versions of AAPT that did not set the bit.

The cases would happen when the old resource had an explicit script
specified in its locale, but since the "provided" bit was not set in
the package, we would assume that the script was computed by us.

This CL replaces the "provided" bit with a "computed" bit, so the
default value of the bit (set to "false" for old packages) would be
correct.

Bug: 27156990
Change-Id: I99e7f1ad8f70c90e25ab3640ed34cc1a6f8d1d64
2016-03-03 15:19:37 -08:00
Adam Lesinski
144c5eabe5 AAPT2: Fix segfault when showing error in 9-patch
Change-Id: I8f457212efc27480758a7157455d98b5e316f772
2016-03-01 09:05:11 -08:00
Adam Lesinski
355f285ffd AAPT2: Implement density stripping and initial Split support
When a preferred density is supplied, the closest matching densities
will be selected, the rest stripped from the APK.

Split support will be enabled in a later CL. Command line support is still
needed, but the foundation is ready.

Bug:25958912
Change-Id: I56d599806b4ec4ffa24e17aad48d47130ca05c08
2016-02-17 18:17:25 -08:00
Adam Lesinski
5f7c461be6 AAPT2: Fix source output when error occurs in style
We were serializing the wrong Source when writing to protobuf

Change-Id: Ib65e962ebc1244ddf4af0e5666aaaebe5f7864a8
2016-02-12 23:38:08 -08:00
Adam Lesinski
e4bb9eb5af AAPT2: Introduce notion of 'product' to ResourceTable
This allows us to preserve the various product definitions during the compile
phase, and allows us to select the product in the link phase.

This allows compiled files to remain product-independent, so that they do not need
to be recompiled when switching targets.

Bug:25958912
Change-Id: Iaa7eed25c834b67a39cdc9be43613e8b5ab6cdd7
2016-02-12 22:21:48 -08:00
Adam Lesinski
59e04c6f92 AAPT2: Switch to protobuf for intermediate format
Without needing to conform to the runtime data format,
it is much easier to add new features such as debugging symbols
and carrying over product data to link time.

This also simplifies the runtime format parser and serializer,
which will change much less frequently than the protobuf intermediate
format.

Change-Id: I209787bbf087db0a58a534cb8511c51d21133e00
2016-02-09 19:59:17 +00:00
Adam Lesinski
6a008170cb AAPT2: Support -c configuration filtering
Change-Id: I1e5855ca73440bdc30c21bcbc1dfdd31a9842363
2016-02-02 17:02:58 -08:00
Adam Lesinski
8900aa8b44 AAPT2: Add -x and -z flags to minimize changes in build scripts
The -z flag will be supported soon anyway and -x is legacy.

Change-Id: I710467d35066d267dea8dfe7c521737fc768ede9
2016-01-25 22:48:15 -08:00
Adam Lesinski
ac7c606c90 Merge "AAPT2: Allow specifying non-final IDS when building 'legacy' style libraries" 2016-01-22 22:12:01 +00:00
Adam Lesinski
ef9c50120d AAPT2: Allow specifying non-final IDS when building 'legacy' style libraries
Real libraries will be built correctly, but since we are not doing that
yet, support the old way and allow a flag --non-final-ids to remove
the final modifier from R.java.

Change-Id: Iad55fb9140e55dbb0f41d0d55f2e2bd958294c8e
2016-01-22 14:09:53 -08:00
Roozbeh Pournader
2d05094209 Merge "Implement smarter locale resource selection" 2016-01-21 22:17:31 +00:00
Roozbeh Pournader
b927c559e1 Implement smarter locale resource selection
* Add support for determining script from language and region.
* Add support for determining special parents of locales.
* Add support for smart comparison of locales with only a difference
  in region, using the locale parentage tree.
* Fix LocaleData.matchScore() to not fallback to old locale matching
  behavior if we can't determine a script.
* Allow four-character variant codes. (Previously, only five- to
  eight-character variant codes were allowed.)

Bug: 7296673
Bug: 26589793
Change-Id: Ibde0a48c0564ff383b41068095a5cbacfe7b94bc
2016-01-21 13:47:22 -08:00
Adam Lesinski
c446a733b8 AAPT2: Accept empty zip files
The libziparchive returns an error on empty zip files.
Work around this by checking for that error condition and
returning an empty ZipFileCollection.

Change-Id: I9edaf2e089456b6ccb4bb099b20ede10331bd352
2016-01-21 11:04:46 -08:00
Adam Lesinski
656a577a34 AAPT2: Accept zip, jack, jar, and flata extensions as archives
Change-Id: I3a4db129998e2351e8221f9d72a4b40d2c7a8cf9
2016-01-14 15:17:41 -08:00
Adam Lesinski
52364f7ae3 AAPT2: Variety of small fixes to get the build working
- Add option to rename package in AndroidManifest.xml
- Support default versionName and versionCode
- Accept True and False as valid booleans

Change-Id: I400e350b9dcd0fd1c197d1929144299c7823617d
2016-01-13 18:48:24 -08:00
Adam Lesinski
979ccb2e6f AAPT2: Warn when positional arguments exist and --legacy is on
This is normally an error, but old AAPT didn't check for it correctly,
so many projects violate this. With --legacy, this becomes a warning.

Change-Id: I23647e029930e11b719591cd38609e1b43247e20
2016-01-11 10:42:19 -08:00
Adam Lesinski
7751afc796 AAPT2: Fix product support
Previously the default product wasn't tried if 'default' wasn't specified on the command line.
Also adds support for multiple products.

Change-Id: I1e4872b34bb8d609b6444841a4e7e4dbb3bbb76b
2016-01-06 16:18:40 -08:00
Adam Lesinski
198ce1a5e6 Merge "AAPT2: Port AAPT pseudolocalization to AAPT2" 2016-01-06 23:55:06 +00:00
Adam Lesinski
f68f066cdf Merge "AAPT2: Fix references to private parent" 2016-01-06 23:50:50 +00:00
Adam Lesinski
457a7e74be Merge "AAPT2: Respect format attribute of <item> tag" 2016-01-06 23:50:10 +00:00
Adam Lesinski
393b5f0d61 AAPT2: Port AAPT pseudolocalization to AAPT2
Pseudolocalization happens at the compile phase. Pseudolocalized
values are weak, such that manually specified values will take precedence.

Change-Id: I5e064ce0d270c9f4f9022f75aecedab9d45bc980
2016-01-06 12:05:41 -08:00
Dan Willemsen
1b1f1b14ee AAPT2: Fix compiler error in 32-bit host test
We now default host native tests to build both 32-bit and 64-bit
versions.

The 32-bit version of libaapt2_test was broken because it was comparing
an unsigned int to the result from std::count(std::vector), which is a
signed int. The 64-bit version compiled fine, since
std::count(std::vector) returns a long.

Change-Id: I786fcd8a54d9f78b76b19ef82ab8dda6f5c42197
2015-12-22 13:44:56 -08:00
Adam Lesinski
24b8ff0faf AAPT2: Fix references to private parent
Change-Id: Id4697551b6c8cb6167f562de593006ae3c6158c0
2015-12-17 11:01:55 -08:00
Adam Lesinski
7ff3ee19f4 AAPT2: Respect format attribute of <item> tag
An <item> is a general tag that can override certain behavior. For
instance, this is allowed:

    <item name="foo" type="integer" format="float">0.4</item>

Even though without the format attribute, this would be illegal.

Change-Id: I8133ce59e14719a70d7476a1464c3f564c435289
2015-12-17 11:01:55 -08:00
Adam Lesinski
a6fe345be9 AAPT2: Fix overlay support
Supports the <add-resource> tag and mimics old AAPT behavior of
not allowing new resources defined unless <add-resource> was used
or --auto-add-overlay was specified.

Change-Id: I9b461137357617ade37fd7045b418b8e6450b9c4
2015-12-10 16:24:15 -08:00
Elliott Hughes
e7d2cc308e Track rename of base/ to android-base/.
Change-Id: If08a94025fc12433f7e248b7787cee3c14843097
2015-12-08 08:57:14 -08:00
Adam Lesinski
a40e972fda AAPT2: Support compiling a res/ directory and output to zip
This allows us to compile an entire directory and output to a single
file. This is important to support generated resources in the make
build, since we may not know what resources get generated.

The link step will accept the zip and read the contents of it as if they
were passed in on the command line.

Change-Id: If1a51b0abe772350c24074353eb4989953c2e0cb
2015-11-30 11:14:01 -08:00
Adam Lesinski
28cacf091a AAPT2: Record source/comments for compound values' children
Values like styles or arrays have children which need to have
their source and comments preserved.

Change-Id: I6fc713ba36627e6d66c7930b4080cc1403bac207
2015-11-23 14:22:47 -08:00
Adam Lesinski
a587065721 AAPT2: Verify min/max attr fields
Integers are now checked to see if they fall in the range
of min/max for the attribute they are assigned.

Change-Id: I42c435b15fd3f0bd23691c83efccce4ad5973276
2015-11-23 12:01:15 -08:00
Adam Lesinski
467f171315 AAPT2: Fail compiling when private symbols are referenced
Also moved some XML specific stuff into its own directory,
and refactored ReferenceLinker a bit.

Change-Id: I912247a82023c1bbf72dc191fbdaf62858cbec0c
2015-11-19 14:46:53 -08:00
Adam Lesinski
abf83cbe4f AAPT2: Prevent duplicate enums/flags
Change-Id: I998cba12ac194000e9c778cb620ed7ab33003e7d
2015-11-16 15:59:10 -08:00
Adam Lesinski
cf95a58014 AAPT2: Fix tokenizer to deal with the separator as last char
When the separator was the last character, the tokenizer would skip
the empty string, which is wrong.

Change-Id: I64ceb4e8d4ac48ee41d40781ab5785a3bc61b24d
2015-11-16 15:44:08 -08:00
Adam Lesinski
fc9570e6b0 AAPT2: Fix a bug where files would only show up for one config
The set of files to build was only comparing resource name and
not configuration.

Also support --extra-packages as a colon separated list of packages.

Change-Id: I36b65cd15299cdc722b785a7891a24ca1bc4fb45
2015-11-16 15:09:15 -08:00
Adam Lesinski
7298bc9c85 AAPT2: Be more strict parsing references
Change-Id: I3d54a519687fff1e66acb8e395ef99ba01a1b845
2015-11-16 12:31:52 -08:00
Adam Lesinski
e352b990e1 AAPT2: Minor fixes to SymbolTable and diagnostic output
The SymbolTable lookup relied on the configuration, which we NEVER
want. Now we rely solely on the symbols defined in the ResTable
and no specific configuration or value of that symbol.

Also added some better source logging.

Change-Id: I983855c283493e924b2e92a9fd8e4cb841769349
2015-11-16 11:59:14 -08:00
Adam Lesinski
fb48d292d9 AAPT2: Add support for overlays when merging resources
Change-Id: Iea9e41123cf89e3cfba7eb6bea89def56dee8093
2015-11-12 14:26:29 -08:00
Adam Lesinski
fa10505cea AAPT2: Accept aliases defined for external resource types
Resource types that are typically stored outside of the resource table
(like layout, xml, drawable) can only have aliases (reference to another
resource).

Change-Id: Idb768801f02bb142e5be5e438904f221499bd756
2015-11-07 13:34:39 -08:00
Adam Lesinski
83f2255f69 AAPT2: Disambiguate merging of resources
Merging local app resources is slightly different than merging
resources from a static library.

Local app resources may not have a package name set, but we do take interest in the
ID set for the package (should be 0x0 or match the ID of the app we're building).

Static library resources have an explicit package name defined for them, so we
only merge resources from that package.

Change-Id: I95e559ae94cc1df6972e77a347b1b37a93674c4d
2015-11-07 11:51:23 -08:00
Adam Lesinski
27afb9e889 AAPT2: Add support for clearer in-progress public attributes
Before, the ID assigned to a public resource without an explicitly set id
was more difficult to figure out. It would be the next available ID.

AAPT2 introduces a new way to specify public attributes in progress.

<public-group type="attr" first-id="0x0101047f">
  <public name="foo" />
  <public name="bar" />
  ...
</public-group>

The IDs assigned to each resource is auto-incremented starting from `first-id`.
This also keeps resource's with the same type grouped together so that
the auto-incrementing nature is evident.

Also, due to how AAPT2 was implemented, this is required :P

Change-Id: I95ea92ad0405e87ed0b1766879bb2f1d9d0b636e
2015-11-06 18:25:04 -08:00
Adam Lesinski
b274e35abf AAPT2: Fix inclusion of comments in R.java javadoc
Comments weren't being copied when merged from the various
resource tables.

Also refactored the JavaClassGenerator to omit a class
if no entries exist for it.

Change-Id: I6eaa89b7b3715bc05403635a2baf0d1db3efd142
2015-11-06 16:37:57 -08:00
Adam Lesinski
9f22204c3a AAPT2: Fix small issue with detecting translatable resources
Change-Id: Idd21b5de4d20be06c6f8c8eb5a22ccd68afc4927
2015-11-05 10:56:32 -08:00
Adam Lesinski
6425497f41 AAPT2: Add round qualifer support
Change-Id: Id5a1331198e01be7ca4d87b8833900e51f82ece5
2015-11-03 16:16:17 -08:00
Adam Lesinski
b23f1e077b AAPT2: Verify positional Java String format arguments in strings
Change-Id: Id415969035a0d5712857c0e11e140155566a960c
2015-11-03 12:58:12 -08:00
Adam Lesinski
2ae4a877d1 AAPT2: Add Manifest fixing/validation
Change-Id: I7f6d8b74d1c590adc356b4da55cb6cb777cdf1da
2015-11-02 16:56:34 -08:00
Adam Lesinski
3b4cd94034 AAPT2: Add support for comments in R.java
Change-Id: Iaa5f3b75bf7de9dbf458fa5c452f7312989f4c4f
2015-11-02 11:53:47 -08:00
Adam Lesinski
ca5638fd85 AAPT2: Support generating Manifest.java
This includes comments from AndroidManifest.xml.

Change-Id: I412d9ecb12bad20a49a683d6b3bea4a0be1235ae
2015-10-30 13:51:11 -07:00
Adam Lesinski
e78fd617ec AAPT2: Move comments and source into Value
Values are closely related to where they were defined, so
this information should live inside the Value.

This also enables comments to be attached to nested Values.

Change-Id: Ic7481b5a5f26d0ef248d638e2e29252f88154581
2015-10-22 16:35:47 -07:00