summaryrefslogtreecommitdiff
path: root/tools/aapt2/java
AgeCommit message (Collapse)Author
2021-04-28Add <macro> tag to aapt2Ryan Mitchell
AAPT2 Macros are compile-time resources definitions that are expanded when referenced during the link phase. A macro must be defined in the res/values.xml directory. A macro definition for a macro named "foo" looks like the following: <macro name="foo">contents</macro> When "@macro/foo" is used in the res/values directory or in a compiled XML file, the contents of the macro replace the macro reference and then the substituted contents are compiled and linked. If the macro contents reference xml namespaces from its original definition, the namespaces of the original macro definition will be used to determine which package is being referenced. Macros can be used anywhere resources can be referenced using the @package:type/entry syntax. Macros are not included in the final resource table or the R.java since they are not actual resources. Bug: 175616308 Test: aapt2_tests Change-Id: I48b29ab6564357b32b4b4e32bff7ef06036382bc
2021-04-21Merge "Aapt2 ValueTransformer" into sc-devRyan Mitchell
2021-04-21Aapt2 ValueTransformerRyan Mitchell
For future macro support, aapt2 must be able to convert Reference values into other Value types. Currently a DescendingValueVisitor is used to visit all of the References in a ResourceTable or a compiled XML file to set their resource ids during the link phase. This was fine since we were only mutating the resource id of the visited Reference. A macro may reference a String, BinaryPrimitive, or any other Item type. During the link phase, we will need to transform references to macros into the values of the macros. The only parameter in the methods of the ValueVisitor interface is a raw pointer to the type being visited. The visitor interface does not support reassigning the visited type to a different type. ValueTransformer is a new interface for consuming a Value type and transforming it into a compatible Value type. This change refactors Value::Clone to use this interface. Bug: 175616308 Test: aapt2_tests Change-Id: Ic1b9d718b932c208764114cd9c74d880e189ccb0
2021-03-31Use staging-public-group in framework SDKRyan Mitchell
To make S finalization easier, this changes the framework SDK so that apps linking against it will be able to continue working as expected after the first phase of SDK finalization. During the first phase of SDK finalization, the resource ids of resources that have not been removed are finalized. staging-public-group tags are converted to staging-public-group-final tags in order to encode into the framework what the staged resource id of a finalized resource was. When an app recompiles, it will use the finalized resource id. Then after all apps recompile, phase 2 of finalization begins, in which the staging-public-group-final tags are removed so apps can no longer use the staged resource ids. Apps that link against the SDK (provided they are using a recent version of aapt) will encode references to staged resources as TYPE_DYNAMIC_REFERENCE and TYPE_DYNAMIC_ATTRIBUTE. The values of R fields for staged resources are defined out-of-line to prevent them from being inlined into apps linking agsint the SDK. This allows the resource ids to change during phase 1 of API finalization. Bug: 183413192 Test: `aapt2 diff` and resource ids stayed the same Test: `aapt2 dump` of framework-res.apk and observe staged resources Change-Id: Ie2275c608297a5f63dde8b1cf795415112cbcc24
2021-03-29Add staging-public-group to aapt2Ryan Mitchell
staging-public-group is a tag for putting resources that have been added during platform development, but have not yet been finalized, into a separate resource id namespace. R.java fields of staged resources are non-final, so when the SDK is finalized, applications using the android R.java will automatically use the new finalized resource id without having to recompile. Staged resources can exist either in the same type id as the type's non-staged counterpart or in a separate type id. Multiple staging-public-group tags each with a different type id can exist simultaneously, which allows for multiple versions of the platform to be developed at once. Bug: 183411093 Test: aapt2_tests Change-Id: Ibb6c84c3626751e33c6097f35a03e306bb85616a
2021-03-29Refactor aapt2 tests ResourceTable changesRyan Mitchell
This changes refactors tests to use the NewResourceBuilder class that makes it easier to construct resource entries. Bug: 183102797 Test: aapt2_tests Change-Id: I851f9fb99a003769f8df8c1876997eee0864822a
2021-03-29Prepare aapt2 for multiple ids per typeRyan Mitchell
For the SDK finalization changes, aapt2 must be able to handle resources of the same type having different type ids. The ResourceTable data structure currently stores package ids and type ids on ResourceTablePackage and ResourceTableType respectively. This prevents resource entries of the same type from having different type ids without having to create another ResourceTableType structure. JavaClassGenerator assumes each type only appears once in the ResourceTable and it would need to dedupe the types to ensure one class containing all the resource types ids is generated. TableFlattener on the other hand needs a separate ResourceTableType for each type/id combination so that the types are flattened into separate ResTable_types. This change simplifies aapt2's ResourceTable data structure: - Resource ids are stored exclusively on ResourceEntry structures meaning multiple entries can have different type ids while being stored in the same ResourceTableType. Classes like JavaClassGenerator can simply iterate over a type to see all the resources of the type regardless of what their type id is. - ResourceTable::GetPartitionedView() retrieves a list of resources sorted and partitioned by package id, type id, and entry id. Classes like TableFlattener can use this view to get separate ResourceTavleTypes for each different type id that a type has. These changes will also make it easy to have a resource span multiple type ids if it exhausts all of the entry ids in one type id. The new NewResourcesBuilder replaces the numerous setter methods on ResourceTable. Bug: 183102797 Test: aapt2_tests Change-Id: I60dbcb24143bb958333899cafa7d41faa226d203
2021-02-24Use R field directly for shared lib styleable attrsRyan Mitchell
If a shared library exposes an attribute and a client uses the attribute in its own styleable, the value of the lib attribute resource id in the client styleable must be fixed with the correct package id at runtime. Since the client will not have an onResourcesLoaded to call, the client should directly reference the attribute resource field in its styleable. Bug: 147674078 Test: aapt2_tests Change-Id: I8e64bb2d3165a7072e2604fe1730b248545978f4
2020-06-23Merge "Don't add API annotations in the internal R.java" into ↵TreeHugger Robot
rvc-dev-plus-aosp am: 7c72b7f45e am: 780aeb116a am: 47d47a8ac5 Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11955280 Change-Id: I602f8515391d93daf1d538f965659dfdca62e550
2020-06-22Don't add API annotations in the internal R.javaMakoto Onuki
I'm trying to enable a check for the following structure: ``` /** @hide */ public class Class1 { /** @hide */ @SystemApi // Invalid because the class is hidden. public void method1() { } } ``` The internal R.java file violates this, which this change is going to fix. Bug: 159162473 Test: build (treehugger) Test: atest aapt2_tests Change-Id: I613e8611ddaf5f8e4761d351d4cd0142d59c7cc9
2020-04-22Reorder styleable attributes in shared librariesClark DuVall
This is a similar fix to https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/base/+/10109386 but deals with styleable attributes instead of style items. Bug: 147674078 Test: JavaClassGeneratorTest.SortsDynamicAttributesAfterFrameworkAttributes Change-Id: Ida6572cf07e2b5987e9d8941cf169a37c43578c4
2020-03-30Merge "aapt2: Preserve annotation parameters for SystemApi." into rvc-dev ↵Narayan Kamath
am: 924069c2aa am: d7bc5846b6 am: 6edf7daeec am: 798ee20e2b Change-Id: I6d95f80ba27bd4c028fc490fe14dacf136ee8a12
2020-03-30Merge "aapt2: Preserve annotation parameters for SystemApi." into rvc-dev ↵Narayan Kamath
am: 924069c2aa Change-Id: Ieb278c96432a0a23d65752a2c89365b02ed936f4
2020-03-26aapt2: Preserve annotation parameters for SystemApi.Narayan Kamath
SystemAPI can now be parameterized. Note that this change preserves the content of the annotation params without attempting to interpret them in any way. This means that references to types outside of java.lang must be fully qualified. Test: atest aapt2_tests Bug: 147581540 Change-Id: I0630fb1c7c7a7f5918ff2dca32fb8e078b367751
2020-03-06Merge "Generate "keep" rules for android:name and class attributes" am: ↵Automerger Merge Worker
a13d7fc861 am: 4da226a984 Change-Id: I4443b84896684ac3249108316487035319b4f52e
2020-03-05Generate "keep" rules for android:name and class attributesJeremy Woods
We should keep classes that are in the android:name or class xml attributes. Test: m -j aapt2_tests Bug: 142601969 Change-Id: Ia67365bd702bae75d38b9572d68e9930e856e0f8
2020-02-12Merge "Fix clang-tidy performance-faster-string-find warnings" am: ↵Automerger Merge Worker
57fb318ca3 am: 7c0f0d3cec am: 40ef6319ca Change-Id: Id9d31a0c5cf41a0bb4a58326faa79511a1d8cc4a
2020-02-11Fix clang-tidy performance-faster-string-find warningsChih-Hung Hsieh
Bug: 30411878 Test: build with WITH_TIDY=1 Change-Id: I7fd815aa401fbcaff97b772f3ba5d6f1d2034011
2019-12-12Merge "Generate "keep" rules for actionProviderClass and actionViewClass"TreeHugger Robot
2019-12-09Merge "Fix aapt2 JavaClassGenerator Maybe#value() call before check"TreeHugger Robot
2019-12-06Fix aapt2 JavaClassGenerator Maybe#value() call before checkRyan Mitchell
Previous refactor accidentally assumed all attributes would have resolvable symbols when generating the R class. Restore previous behavior of calling SkipSymbol before retrieving the attribute comment. Bug: 145685954 Test: m TeleService Change-Id: Ie8e1092556bc0b6a764462ffa0b99a876bcbd70e
2019-12-02Add "no-proguard-location-reference" flag to aapt2Jean-Luc Coelho
This fixes relocatability issues with the code shrinkers. Bug: 144529940 Test: None Change-Id: I65e08e850193e67dcdf4c533d9e66332714f0c8c
2019-11-26Factor out repeated shift instructions to reduce code sizeDonald Chai
R8 has some O(n^3) analysis somewhere, so this should speed up analysis of "onResourcesLoaded" by 1.5^3=3.3x. Bug: 145052564 Change-Id: Ib6ab111511d6bd3afae0c29cd00f743e7128768a Tested: aapt2_tests
2019-11-11Speed up WriteKeepSet when generate_conditional_proguard_rules is off.Brian Duff
The results of CollectLocations() are only used if the --proguard-conditional-keep-rules option is set, but the function is always called when the --proguard option is set. Since this function can be slow on particularly large resource sets, avoid calling it unless --proguard-conditional-keep-rules is set. Change-Id: If259d41cdab16abad8ca62f30d8beb5ebf33575a Bug: 144236322 Test: aapt2_tests
2019-11-08[aapt2] Fix infinite loop in proguard::CollectLocationsDonald Chai
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 (cherry picked from commit 44fa342eb91b90df7998fa2808e21af75aafaf39)
2019-09-10Generate "keep" rules for actionProviderClass and actionViewClassDonald Chai
Apps commonly use the versions of the attributes from AndroidX, which will be unqualified. Bug: 30888677 Change-Id: Id7cb32b28edb1cd1b8113a8c9a7ee29107a1b67e Tested: aapt2_tests
2019-06-03[aapt2] Fix infinite loop in proguard::CollectLocationsDonald Chai
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-03-06Make sure Proguard keeps zygote preload class.Martijn Coenen
Bug: 127262679 Test: atest ProguardRulesTest Change-Id: Ib082404e08d98b25fcecbf680afb4af37fe2786b
2019-01-04Merge "Fix/suppress aapt/aapt2 google-explicit-constructor warnings" am: ↵Chih-Hung Hsieh
cdf6be573f am: d42fe48c93 am: 0bf62f1309 Change-Id: Iffb7e4a145b172a35dd58b9450d4a5184d8b07f7
2019-01-04Fix/suppress aapt/aapt2 google-explicit-constructor warningsChih-Hung Hsieh
* Add explicit to conversion constructors/operators * Use NOLINT or NOLINTNEXTLINE to suppress warnings on intended converters Bug: 28341362 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,google-explicit-constructor Change-Id: Ie02101ea7c422e8add535c111a30a2f21ead0ace
2018-12-17Merge "Fix performance-for-range-copy warnings" am: bc29242288 am: 7adb73f332Chih-Hung Hsieh
am: 2296036a40 Change-Id: Ia99ea6c9633986e68340bc88983d06baa7a1c597
2018-12-17Fix performance-for-range-copy warningsChih-Hung Hsieh
Bug: 30413223 Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance* Change-Id: Ie481e88025a7a1f3abde8ff63420d5ccd8577e52
2018-12-03Add @hide support for styleable attributesRyan Mitchell
AAPT2 generates documentation for styleables. The documentation contains references to the attributes of the styleable. If the attributes are marked @hide, remove the references to the attributes in the generated coments. Bug: 120262117 Test: m -j offline-sdk-docs Change-Id: I541002077b17771d89caead04df2f4ae66c623f0
2018-10-08libandroidfw: move ConfigDescription from aapt2 to libandroidfwMårten Kongstad
This is to allow idmap2 to access ConfigDescription. Test: libandroidfw_tests Test: aapt2_tests Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5 Merged-In: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-08libandroidfw: move ConfigDescription from aapt2 to libandroidfwMårten Kongstad
This is to allow idmap2 to access ConfigDescription. Test: libandroidfw_tests Test: aapt2_tests Change-Id: I54210bbbd8dad5903cb7100807df977efa394ad5
2018-10-03Merge "Restore Proguard behavior and add minimal flag"Ryan Mitchell
2018-10-01Merge "Do not use StringPiece in ExtractJavaIdentifier" am: 20ecc6397b am: ↵Pirama Arumuga Nainar
206ccf1f61 am: 7472303ff4 Change-Id: Idd910ad9fb743093f8e43ddcdf5770722b4393e6
2018-09-25Restore Proguard behavior and add minimal flagRyan Mitchell
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-25Do not use StringPiece in ExtractJavaIdentifierPirama Arumuga Nainar
Bug: http://b/91353691 After assigning the result of TransformToFieldName to 'result', the underlying storage is destroyed after the 'if' statement of the function call. 'result' ends up with garbage if the identifier has a '-'. ManifestClassGeneratorTest.NormalizePermissionNames is broken for this reason in 32-bit Windows when using libc++ and 32-bit Linux. ASAN also reports this failure for both 32-bit and 64-bit linux. Test: Run test on the cases mentioned above and ensure all of them pass. Change-Id: I69163c423c1171b7ac7838f2abe06bdf8058df4c
2018-07-20Merge "Only keep necessary constructor for custom view nodes"TreeHugger Robot
2018-07-20Merge "Only keep methods with correct signature for more types"TreeHugger Robot
2018-07-20Merge "AAPT2: Fix R.java for styleable in different package"Ryan Mitchell
2018-07-20Only keep necessary constructor for custom view nodesJake Wharton
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-20Only keep methods with correct signature for more typesJake Wharton
- 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-18Add rule emissions for appComponentFactoryJake Wharton
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-18Add Application name to manifest test caseJake Wharton
Test: make aapt2_tests Change-Id: I4df26375bdf480b7d09e9cf816b7a9feaa141115
2018-07-13AAPT2: Fix R.java for styleable in different packageRyan Mitchell
When generating the R.java file, attributes of styleables do not always have package names on them. This caused a problem where when an apk that was previously linked and that also contained a declare-styleable is linked again to an AndroidManifest.xml with a different package name, styleable attributes' resource symbols could not be looked up correctly. This change does not rename the resources but makes sure that the java generator finds the attribute symbols correctly. Bug: 110877419 Test: Created a test in aapt2_tests and verified correct behavior of repro example from bug Change-Id: Ib99d84cbe44dadca86603bc610ad3f4e09e3fb11
2018-06-11Only keep methods with correct signature for view/menu clickJake Wharton
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-11Improve tests for ProGuard rules, add transition testsJake Wharton
Test: make aapt2_tests Change-Id: If3300a9f82ad90189b74aab03c0d7f649e74e3f3
2018-06-11Only keep default constructor of manifest itemsJake Wharton
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