55 Commits

Author SHA1 Message Date
Adam Lesinski
2427dce820 AAPT2: Fix issue where exported symbols (@+id/*) were not exported
Test: make AaptTestAppOne
Change-Id: If3218c880e83c2cfaf535a099db38504471be676
2017-11-30 16:12:29 -08:00
Adam Lesinski
04465e7f25 AAPT2: Introduce command to run unit tests
This command will execute the aapt2_tests with a parameter
to emit XML test results into the out/dist directory.

Test: manual
Change-Id: I10cf119bb47b7698ddd91b1adf7323e51d169970
2017-11-02 15:33:26 -07:00
Fabien Sanglard
191602091b AAPT2: Convert Android.mk to Android.bp
Change-Id: I6c563993b57e3f04165ca57743f9a2878aba556c
2017-01-13 18:56:55 -05:00
Paulo Casanova
3497b26507 Added Windows support for aapt/JNI.
This includes copying and slightly modifying
libnativehelper's ScopedUtfChars' implementation.

Test: Done in studio-master-dev
Change-Id: I2aacc67b444668478aaa5bb0db991a201c571d1f
2016-11-03 09:39:43 +00: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
Paulo Casanova
255960857d Added JNI interface for aapt2.
Test: None (tests will be made on the Android Studio Tools project)
2016-10-20 12:03:34 +01:00
Elliott Hughes
56f823be9a Merge "Rely on the platform -std default." am: 66f15cc01b am: 5a989a504a am: 39ad1b92fa
am: 437b8c95a8

Change-Id: Idacd1cad6e0e241404c99b680974aae2b8f81926
2016-10-10 17:42:08 +00:00
Elliott Hughes
437b8c95a8 Merge "Rely on the platform -std default." am: 66f15cc01b am: 5a989a504a
am: 39ad1b92fa

Change-Id: Iec4bca8e96c776d61c5da5540a74acc6773c2bce
2016-10-08 22:03:56 +00:00
Elliott Hughes
c08e32e0be Rely on the platform -std default.
Bug: http://b/32019064
Test: builds
Change-Id: I7180f1eb539ff8cbe33832d010775f053a922946
2016-10-07 15:57:17 -07:00
Adam Lesinski
ffa9656223 Merge "AAPT2: Refactor PngCrunching" 2016-10-03 21:22:28 +00: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
21efb6827c AAPT2: Refactor PngCrunching
PngCrunching now has a slightly better heuristic of choosing to encode
an image as a palette or RGB. For small images, RGB compresses much better
than a palette.

The original PNG is used as-is (minus some optional chunks being stripped)
if the resulting crunched PNG is larger than the original.

9-patch handling is abstracted away from PNGs, paving the way
for other 9-patches, like WebP.

TODO: handle PNGs with 9-patch chunks already present, which
should just be passed through. This will allow for 3rd party
tools to generate 9-patches.

TODO: implement cheap transparency: when one color is used to represent
transparent, and all other colors are opaque.

Bug:30053276
Change-Id: I5167f53b91d1efa462d9f03d6b9108d9b541c0c1
2016-09-29 15:28:52 -07:00
Paulo Casanova
c7ca55e27b Added building libaapt2_jni.so.
Change-Id: Ica2769c08b4bb5c6cceebb8052c0dd7817ef4586
2016-09-27 18:34:54 +01: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
Colin Cross
7fd4eb7ff7 Merge "Replace libziparchive-host with libziparchive" am: 611e205bbe am: 8c8bb25089 am: 63dc310e6a
am: e3cd4b394c

Change-Id: Icc088a0cdd6a2ebc2b7bedb719ad7220d947273d
2016-08-31 00:29:35 +00:00
Colin Cross
e3cd4b394c Merge "Replace libziparchive-host with libziparchive" am: 611e205bbe am: 8c8bb25089
am: 63dc310e6a

Change-Id: I645d077dd656f84446f77fd91c169fd7b977e661
2016-08-26 20:40:27 +00:00
Colin Cross
9a1a3bcb16 Replace libziparchive-host with libziparchive
libziparchive-host is no longer necessary, and mixing libziparchive-host
and libziparchive can cause ODR violations.

Change-Id: I623c0c5579e28f26a6e1db7bd953f33ed1ca68cd
2016-08-26 11:15:17 -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
Dan Willemsen
3b16cf057a Rename libprotobuf-cpp-lite_static to libprotobuf-cpp-lite am: 2005edf642 am: 4ee22dd083
am: 77508b9c19

Change-Id: Ifb0fef3c2dfaef7b19e2f03dbbdce41431a51a2f
2016-08-02 02:36:20 +00:00
Dan Willemsen
77508b9c19 Rename libprotobuf-cpp-lite_static to libprotobuf-cpp-lite am: 2005edf642
am: 4ee22dd083

Change-Id: I5a9006361b3ded4eaf03b1362a0dfa2aa36fdb2e
2016-08-01 23:46:15 +00:00
Dan Willemsen
2005edf642 Rename libprotobuf-cpp-lite_static to libprotobuf-cpp-lite
Use the same name for the static and shared libraries so that the module
definitions can be shared.

Change-Id: I1578ee7044689194ae1baea4d71f1b0e8737505f
2016-07-31 22:48:28 -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
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
458b877488 AAPT2: Add diff command
Adds the diff command and various small fixes to issues
discovered when diffing old AAPT built APKs with new AAPT2
built APKS.

Bug:22775504
Change-Id: I682a7fe1cf4b3efa7cbd5d18b333cf2d1046fe1b
2016-04-30 01:36:12 +00:00
Adam Lesinski
803c7c8079 AAPT2: Enable windows build and make sure it builds
Mingw32 4.8 is kind of picky with macros and some complicated template
stuff. Luckily there was another way to represent the
SFINAE code that works on all platforms. Yay!

Change-Id: Idc2e38f47bfdc57b394550bfa0f53cc0b825df25
2016-04-06 16:24:02 -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
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
f4ab612684 AAPT2: statically link protobuf library
Change-Id: I0bce42dfef2f11181c6407839875c97f88445dbd
2016-03-11 07:20:49 +00: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
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
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
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
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
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
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
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
2ae4a877d1 AAPT2: Add Manifest fixing/validation
Change-Id: I7f6d8b74d1c590adc356b4da55cb6cb777cdf1da
2015-11-02 16:56:34 -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
1ab598f46c AAPT2: Separate out the various steps
An early refactor. Some ideas became clearer as
development continued. Now the various phases are much
clearer and more easily reusable.

Also added a ton of tests!

Change-Id: Ic8f0a70c8222370352e63533b329c40457c0903e
2015-10-16 12:13:08 -07:00
Elliott Hughes
51348d2007 aapt: expat exports its header files now.
Change-Id: Iddf0133919d38fc896f97c6796f8228a6decf174
2015-07-21 11:39:21 -07:00
Adam Lesinski
a1ad4a812a AAPT2: Proguard rules generation added.
Change-Id: Ifbe79516cd9a1ade471e211a259301c63b62ac67
2015-06-09 11:14:24 -07:00
Adam Lesinski
8c831ca87b AAPT2: Add manifest merging
Now that AAPT2 is library-aware, it needs to take care of
all library related work, including merging manifests.
The logic was taken from the current Java ManifestMerger.

Change-Id: Id93f713f27ae8617922bf89e325e45be9f863c06
2015-06-04 18:00:33 -07:00
Adam Lesinski
75f3a55cc5 AAPT2: Change xml file parsing to DOM based
We modify the XML of layouts and AndroidManifest enough
that it warrants we operate on the tree in memory.
These files are never very large so this should be fine.

Change-Id: I5d597abdb3fca2a203cf7c0b40fcd926aecb3137
2015-06-04 11:37:05 -07:00
Adam Lesinski
330edcdf13 AAPT2: Support static lib referencing static lib
When a static library A references static library B,
and app C references both A and B, we get the following symbol merging,
symbols from library B get imported twice.

We must only check that symbol references to library B are valid
when building library A. We should only merge all the symbols
when building final app C.

Change-Id: I23cba33b0901dcbb5328d9c9dfaa6a979c073c36
2015-05-12 20:41:31 -07:00
Prerepa Viswanadham
d1808401ca Merge changes from topic 'mwd-merge-050415' into mnc-dev
* changes:
  Merge commit 'b6f59f4' into master_merge
  Merge commit 'f6db0ce' into master_merge
  Merge commit '17455a3' into master_merge
  Merge commit 'b4d5b32' into master_merge
  Merge commit 'a1a2fa7' into master_merge
  Merge commit '8dfdb98' into master_merge
  Merge commit 'eba66c3' into master_merge
2015-05-05 01:06:38 +00:00
Adam Lesinski
24aad163bc Add namespace handling in attribute values
Previously, you could only reference namespace prefixes in attribute names:

<View xmlns:appcompat="http://schemas.android.com/apk/res/android.support.v7.appcompat"
      appcompat:name="hey"
      ...

Now you can also reference them in resource names within an attribute value:

      ...
      android:text="@appcompat:string/confirm"
      ...

Which will be treated as "@android.support.v7.appcompat:string/confirm".

Change-Id: Ib076e867a990c80cf877a704eb77cd1ef0b23b52
2015-05-04 16:43:24 -07:00
Narayan Kamath
231e054dfd Add a libbase static depedency for aapt2.
Required by libziparchive.

Change-Id: Ifa33c9e44ebd583cf58b8a1239061c613fde92bc
2015-04-29 16:32:23 +01:00