Commit Graph

21 Commits

Author SHA1 Message Date
Ryan Mitchell
7e5236dc56 Restore Proguard behavior and add minimal flag
We previously changed AAPT2 to correctly only generate keep rules for
the constructors required to inflate the different views. This cause
projects that did not have keep rules for the other constructors that
were accessed through reflection to have runtime crashes. This change
adds a flag to the link stage (--proguard-minimal-keep-rules) that
allows AAPT2 to only keep the constructors required for layout
inflation. If the flag is not present, then AAPT2 will generate less
specific keep rules than keep all constructors.

Bug: 116201243
Test: aapt2_tests
Change-Id: I8bb5cdf8446518ab153ea988e1243ca9494258c7
2018-09-25 15:20:59 -07:00
Jake Wharton
cc65b8dba6 Only keep necessary constructor for custom view nodes
This expands the Context+AttributeSet constructor specificity from only work on <view class=> nodes to <my.Type> nodes.

Bug: 37123156
Test: make aapt2_tests
Change-Id: I8fb950731383f86bee225333bda27baf5a7a34c5
2018-07-20 10:44:11 -04:00
Jake Wharton
98100c3828 Only keep methods with correct signature for more types
- For transition and pathMotion attributes the method must have Context and AttributeSet parameters.
- For actionViewClass and actionProviderClass attributes the constructor must have a single Context parameter.
- For Fragment's class or name attributes the constructor must have zero parameters.

Bug: 37123156
Test: make aapt2_tests
Change-Id: I34017abd182867ba95172835051d114cb2f3b3ac
2018-07-20 10:44:11 -04:00
Jake Wharton
e4bd160284 Add rule emissions for appComponentFactory
This attribute was added in API 28 and is reflectively instantiated from a zero-argument constructor.

Test: make aapt2_tests
Change-Id: Ie9de0764165c6fe6c6fcda6cc38b0cc633f03bbd
2018-07-18 12:09:17 -04:00
Jake Wharton
3001f0311d Only keep methods with correct signature for view/menu click
For View's onClick attribute the method must have a single argument of type android.view.View. For a MenuItem's onClick attribute the method must have a single argument of type android.view.MenuItem. Since these rules match all types and any return type, matching by signature is the only available specificity that can be added.

Bug: 37123156
Test: make aapt2_tests
Change-Id: I4b82f5ef9e62a8ecffaab424e269df627825709e
2018-06-11 17:21:28 -04:00
Jake Wharton
ab660a7fde Only keep default constructor of manifest items
Reflection-based instantiation of manifest-declared types is only done on the default (aka no-argument) constructor. While these types are unlikely to have alternate constructors (unlike the others listed in the bug), there's no reason to generate overly keep-y rules for them.

Bug: 37123156
Test: make aapt2_tests
Change-Id: Ic83a2671a54ea5dd558bfcacf033a60e9568ab8c
2018-06-11 11:33:17 -04:00
Ryan Mitchell
9a2f6e60c6 AAPT2: Add Proguard rules for nav fragments
Adds generation of proguard rules for fragments in res/navigation. All
android:name attributes have keep rules generated for the classes they
reference.

Bug: 69929974
Test: aapt2_tests
Change-Id: I05a87484ab357ea5629b73caad8488182f474e1f
2018-05-24 09:58:27 -07:00
Adam Koski
f85eec8403 Fix conditional keep rules for new semantics
New conditional syntax is a logical AND, not OR. This means if a
resource should be conditionally kept by multiple ids, we need to
generate a separate rule for each condition (which will be interpreted
as OR).

Test: unit tests
Bug: 69341430
Change-Id: I0786c65561d36fbf43d181a2dfd0c7eaf1d96b8c
2017-11-20 14:54:28 -08:00
Adam Lesinski
a693c4a32e AAPT2: Move all file output to FileOutputStream
FileOutputStream is safe to use on Windows, as it opens
files using our compatibility API.

Bug: 68262818
Test: make aapt2_tests
Change-Id: Ib0b27e93edd609b49b1327db7d9867a002198ebb
2017-11-16 12:06:17 -08:00
Adam Koski
09ef94e918 Change conditional keep rule syntax
Google's ProGuard fork is migrating to a new syntax that upstream
ProGuard 6.0 will also support.

Test: unit tests
Bug: 69162105
Change-Id: I3b6d7e82eb99c2e2af6c4d851a4f97ec3e471b55
2017-11-10 11:30:56 -08:00
Adam Koski
dc21dea9b8 AAPT2: Produce Conditional Proguard Keep Rules
Add the option to produce keep rules that conditional keep based on
usage of R identifiers. This allows Proguard to potentially shrink more
code if resources are not used.

Currently only produces conditional rules for classes referenced in
layout resources because they are the most common and has the easiest
transitive usage chain to analyze.

Bug: 63628451
Test: make aapt2_tests and manual testing
Change-Id: I6c1af7affd64af40c80e004d8506a9463444b2c3
2017-10-20 16:25:18 -07:00
Adam Lesinski
6b37299129 AAPT2: Change XmlDom to exclude Namespace as a node
In preparation for exporting an XML proto format for UAM to consume,
this change brings the XML DOM API more in line with other APIs that
do not make the Namespace a separate node.

Treating Namespace declarations as just properties of an Element
node makes the implementation of algorithms much simpler, as
the constraints that Namespace nodes have only one child
are now built in and traversing to find Element nodes
is much simpler.

Also made a bunch of quality of life improvements, like formatting and
comment style.

Test: make aapt2_tests
Change-Id: Ib97ff1c4252b7907e2cc1f13a448dc4ca3b809a4
2017-08-17 17:43:08 +00:00
Adam Lesinski
f762df2575 AAPT2: Emit more proguard keep rules for layouts and menus
<fragment> tags in layouts use the class attribute to determine which
Fragment subclass to load, and fallback on android:name if class is not
set.

AAPT2 only emitted a proguard rule for the class attribute for <fragment>,
when it should emit a proguard rule for the android:name attribute as
well.

AAPT2 didn't handle menu XML, so support for actionViewClass,
actionProviderClass and onClick is added.

Bug: 62216174
Test: make aapt2_tests
Change-Id: Ie8675c2bd899a5b51f3661eb0901ab8c9a16fd70
2017-06-28 11:01:59 -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
Ivan Gavrilovic
f580d91dab Aapt main dex proguard rules - always keep application
Aapt with -D option was not keeping the application and instrumentation
subclasses, which were instead handled by mainDexClasses.rules. Instead,
include them in the aapt -D output.

Change-Id: Ia3b89fc2edd45d379c4d06f0bf674716646fcb3d
2016-07-20 15:38:48 +01: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
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
24b8ff0faf AAPT2: Fix references to private parent
Change-Id: Id4697551b6c8cb6167f562de593006ae3c6158c0
2015-12-17 11:01:55 -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
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