summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceValues.cpp
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-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
2019-12-19Recognize dynamic res ids as validRyan Mitchell
Shared libraries are assigned package id 0. Resource ids that start with 0x00 are not invalid. This change changes is_valid to accept dynamic resource ids and adds an is_valid_static method for when an id must have a non-zero package id. This also fixes an issue that made layouts in shared libraries that use internal attributes exclude compiled resource ids from the binay xml output. Bug: 146491000 Test: Build a shared library with a layout that uses app attributes as well as android attribute and verify that all attributes have assigned resource ids using `aapt2 dump xmltree` Change-Id: Ibc0407c610ffc98d7aaf233c37c065912ab0d516
2018-04-26Allow using reserved package IDsTodd Kennedy
Pre-O, the platform treats negative resource IDs [those with a package ID of 0x80 or higher] as invalid. In order to work around this limitation, we allow the use of traditionally reserved resource IDs [those between 0x02 and 0x7E]. Bug: 78041707 Test: ./out/host/linux-x86/nativetest64/aapt2_tests/aapt2_tests Test: ./out/host/linux-x86/nativetest/libandroidfw_tests/libandroidfw_tests Test: Manual. Create a feature split with a package ID of 0x7E and see it runs and can reference base resources. Change-Id: I3d9782cc05d3a55e1a2467bf39566788847e1160
2018-02-15AAPT2: Ensure output formats of files are correctly setAdam Lesinski
When compiling straight to proto from source, the file types were not set correctly (binary XML or proto XML). Bug: 73406447 Test: manual Change-Id: I68c1881a00a2ec1ad58f7ec485af2543d262d076
2018-01-11AAPT2: Allow compatible duplicate AttributesAdam Lesinski
If a resource XML file defines two compatible Attributes, they should be merged without throwing an error. Ex: <declare-styleable> <attr name="conflict" format="string" /> </declare-styleable> <declare-styleable> <attr name="conflict" format="string|reference" /> </declare-styleable> In this case, string|reference and string are the same, so these should merge correctly. Bug: 65699599 Test: make aapt2_tests Test: make AaptBasicTest Change-Id: I7b0f956d2332f7f0b458acd59ca0a606b2cfdf95
2017-11-09AAPT2: Workaround for feature splits without namespacingAdam Lesinski
Android Instant Apps in its current iteration does not use namespaces, but due to limitations on the Android resource runtime, needs to make it look like it does. This is due to a bug that treats any package ID that's not 0x01 or 0x7F as a shared library. Shared libraries require unique package names. As a workaround, and since Android Instant Apps can not have a feature depend on another feature, we can alter the resource package name of a feature split just before writing it out to disk. This avoids using a unique package name while linking, thereby avoiding namespace issues. Bug: 68820737 Test: manual Change-Id: Ic553ed42656436bbb949393d0248ee7bb9d37860
2017-11-07AAPT2: Better debugging outputAdam Lesinski
Test: make aapt2_tests Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
2017-10-20Merge changes I1a4b3ce5,Id7216e5bAdam Lesinski
* changes: AAPT2: Enable building proto artifacts AAPT2: Define and Implement AAPT Container Format
2017-10-19Merge "AAPT2: Ensure strings are sorted by configuration" into oc-mr1-dev ↵Adam Lesinski
am: 8da74b1bfd am: 5fae742a1e Change-Id: I7dfb1a020b1c3da9e0af5a7096fda0775751eab3
2017-10-19AAPT2: Define and Implement AAPT Container FormatAdam Lesinski
AAPT Container Format (.apc) is a simple container that enumerates the various intermediate files that AAPT2 generates during the compile phase. The format is defined in formats.md. For now, continue using the .flat extension for the container file, and keep making use of the .flata zip for storing multiple files. This will allow easier integration with existing build systems and allow the evolution of the APC format to better handle arbitrarily large files. Test: make aapt2_tests Change-Id: Id7216e5b76316bdd683f0fa4eaf2d2da273ba815
2017-10-18AAPT2: Ensure strings are sorted by configurationAdam Lesinski
Keep strings sorted by configuration so that strings likely to be selected (all match the same locale, for instance) are close together. Bug: 67958501 Test: make aapt2_tests Change-Id: Id17d93bf2e03ce408a6f619d3ea6dc313e393b76
2017-09-28AAPT2: Cleanup Visitors for XML and ValuesAdam Lesinski
Test: make aapt2_tests Change-Id: Ib61f64c155a380115610edeaf2d65e60258a2426
2017-09-14AAPT2: Define intermediate compiled XML protoAdam Lesinski
This proto format is meant to encapsulate more information that is specific to Android and allows for easier validation and manipulation across tools. Test: make aapt2_tests Bug: 65645766 Change-Id: I13bc34a460671fc0a36246be0d287a3d37d244d6 Merged-In: I13bc34a460671fc0a36246be0d287a3d37d244d6
2017-08-23AAPT2: Define intermediate compiled XML protoAdam Lesinski
This proto format is meant to encapsulate more information that is specific to Android and allows for easier validation and manipulation across tools. Test: make aapt2_tests Change-Id: I13bc34a460671fc0a36246be0d287a3d37d244d6
2017-08-04AAPT2: Ensure style strings are always first in StringPoolAdam Lesinski
Move the styled strings to a separate section of the StringPool so that sorting can never mess up the order of Styles. Bug: 63570514 Test: make aapt2_tests Change-Id: Id2ce1355b92be1bb31ce0daa7e54ae9b5b6c2ffe
2017-07-31AAPT2: Ensure style strings are always first in StringPoolAdam Lesinski
Move the styled strings to a separate section of the StringPool so that sorting can never mess up the order of Styles. Bug: 63570514 Test: make aapt2_tests Change-Id: Id2ce1355b92be1bb31ce0daa7e54ae9b5b6c2ffe
2017-06-15AAPT2: Fix issue with enums and integer attributesAdam Lesinski
When an attribute had the format "enum|integer", and a max or min allowed value set, any value set for this attribute would have its enum symbol's value checked against the valid integer range. This would lead to the following: android:numColumns="autofit" being interpreted as an integer value of -1, which violated the minimum expected value for numColumns, which was 0. Bug: 62358540 Test: make aapt2_tests Change-Id: I3150410448a533d3595a08ac6b2966264db874d8
2017-06-02AAPT2: Allow undefined resources (placeholders)Adam Lesinski
A resource defined like so: <item type="drawable" name="foo" /> should be assigned the value @null. The only exception is for <string> resources, which are given the empty string value (since <string></string> is ambiguous). The decision to use "" is based off the fact that old AAPT used to assign "" to all undefined resources, even non-string ones. Bug: 38425050 Test: make aapt2_tests Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9
2017-05-31AAPT2: Allow merging of Style attributes from overlaysAdam Lesinski
Previously style overlays would completely override an existing style. To be compatible with AAPT, styles now merge with the overlay, allowing the overlay's attributes and parent to take precedence. Bug: 38355988 Test: make aapt2_tests Change-Id: Id25c7240050a43e6a4a177c6e3d51e048d0cceb5
2017-05-24AAPT2: Implement attribute compat versioningAdam Lesinski
This change defines some hardcoded rules to degrade attributes in newer SDKs to specific older attributes. An attribute with a degrade rule will generate a new XML for the API in which the attribute resulting from the degradation was introduced. Since API 22 (Lollipop MR1), attributes are correctly ignored and do not need to be versioned. In XML files defined for APIs 22+, the original and degraded attributes coexist in the same XML file. One such example is paddingHorizontal, introduced in API 26. paddingHorizontal degrades to paddingLeft and paddingRight, which were both introduced in API 1. Bug: 35763493 Test: make aapt2_tests Change-Id: I4aa8755a9ee2c0cc5afdc55c3d30093fd3a47f3d
2017-03-02AAPT2: Fix Plural::Equals() methodAdam Lesinski
Test: make aapt2_tests Bug: 35902437 Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24
2017-02-22AAPT2: Few tweaks to get shared-libraries workingAdam Lesinski
Test: manual (building shared support library demo) Change-Id: I4730645aa92ba1893baf67ffe35fbd4aac0f8e46
2017-02-08AAPT2: Fix pseudolocalization to respect <xliff:g>Adam Lesinski
The XLIFF 'g' tag specifies content that should NOT be translated. AAPT2's pseudolocalization process should respect it. Bug:34064599 Test: make libandroidfw_tests Change-Id: Ice437d7f0ff246730ee04896fd035e2d846148fb
2016-10-26AAPT2: Rename to match new styleAdam Lesinski
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-19Use Google3 style guide with .clang-formatAdam Lesinski
Test: style change only, builds ok Change-Id: I885180e24cb2e7b58cfb4967c3bcb40058ce4078
2016-08-26AAPT2: Fix merging of styleables the right wayAdam Lesinski
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-19AAPT2: Merge Styleables instead of overriding themAdam Lesinski
Styleables merge in AAPT. Preserve this behavior. Bug:30970091 Change-Id: Ie68ca675aeecd873c0648682182e2fc574e329a0
2016-08-15AAPT2: Expose split support to command lineAdam Lesinski
Bug:30445078 Change-Id: If4b8530dba71b9059b8e62c04757da99c1119d22
2016-06-29AAPT2: Improve diff commandAdam Lesinski
Change-Id: Ia1e2f8482c7192ef50126b61bed7975297332767
2016-04-30AAPT2: Add diff commandAdam Lesinski
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-02-17AAPT2: Implement density stripping and initial Split supportAdam Lesinski
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-09AAPT2: Switch to protobuf for intermediate formatAdam Lesinski
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-01-06AAPT2: Port AAPT pseudolocalization to AAPT2Adam Lesinski
Pseudolocalization happens at the compile phase. Pseudolocalized values are weak, such that manually specified values will take precedence. Change-Id: I5e064ce0d270c9f4f9022f75aecedab9d45bc980
2015-12-17AAPT2: Fix references to private parentAdam Lesinski
Change-Id: Id4697551b6c8cb6167f562de593006ae3c6158c0
2015-11-23AAPT2: Verify min/max attr fieldsAdam Lesinski
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-19AAPT2: Fail compiling when private symbols are referencedAdam Lesinski
Also moved some XML specific stuff into its own directory, and refactored ReferenceLinker a bit. Change-Id: I912247a82023c1bbf72dc191fbdaf62858cbec0c
2015-11-06AAPT2: Fix inclusion of comments in R.java javadocAdam Lesinski
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-10-22AAPT2: Move comments and source into ValueAdam Lesinski
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-16AAPT2: Separate out the various stepsAdam Lesinski
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-05-12AAPT2: inferred style parent processingAdam Lesinski
Change-Id: I8fbc4feef16b6039cf4c526fcfb767dc75a9c131
2015-05-12AAPT2: Support static lib referencing static libAdam Lesinski
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-04AAPT2: Record public status in a more robust wayAdam Lesinski
This allows us to store the source and comments of a resource's public declaration and avoids issues where there is no default configuration for a publicly declared resource (like with drawables of various densities) and AAPT2 mistakenly took this as an error. Change-Id: I07a2fe9f551daefcce842f205fb219d2fa453ebc
2015-04-15AAPT2: Add library supportAdam Lesinski
Change-Id: I307f56d9631784ab29ee4156d94886f9b2f25b30
2015-04-02AAPT2Adam Lesinski
First checking of AAPT2. The individual phases of AAPT2 work, but there are some missing pieces. For early testing we are missing: - Need to properly mark file references and include them in package - Need to package into zip Final AAPT for apps we are missing: - Need to crush PNGs - Need to parse 9-patches - Need to validate all of AndroidManifest.xml - Need to write align method to align resource tables for splits. Final AAPT for apps + system we are missing: - Need to handle overlays - Need to store comments for R file - Need to handle --shared-lib (dynamic references too). New AAPT features coming: - Need to import compiled libraries - Name mangling - R file generation for library code Change-Id: I95f8a63581b81a1f424ae6fb2c373c883b72c18d