• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

dex_builder_test/23-Mar-2024-541387

Android.bpD23-Mar-20242.4 KiB108101

OWNERSD23-Mar-202437 32

README.mdD23-Mar-20242.4 KiB5440

TEST_MAPPINGD23-Mar-2024302 2019

apk_layout_compiler.ccD23-Mar-20245.9 KiB175138

apk_layout_compiler.hD23-Mar-20241.1 KiB3512

dex_builder.ccD23-Mar-202424.2 KiB705551

dex_builder.hD23-Mar-202421.7 KiB627382

dex_layout_compiler.ccD23-Mar-20248.4 KiB209147

dex_layout_compiler.hD23-Mar-20243.5 KiB12480

dex_testcase_generator.ccD23-Mar-202414.5 KiB354245

java_lang_builder.ccD23-Mar-20244.6 KiB11690

java_lang_builder.hD23-Mar-20242 KiB6627

layout_validation.ccD23-Mar-20241.2 KiB4222

layout_validation.hD23-Mar-20241.4 KiB4719

layout_validation_test.ccD23-Mar-20245.9 KiB164131

main.ccD23-Mar-20245.2 KiB173127

tinyxml_layout_parser.ccD23-Mar-20241 KiB3513

tinyxml_layout_parser.hD23-Mar-20241.9 KiB6636

util.ccD23-Mar-20241.1 KiB3916

util.hD23-Mar-2024887 309

util_test.ccD23-Mar-20241.1 KiB3513

README.md

1# View Compiler
2
3This directory contains an experimental compiler for layout files.
4
5It will take a layout XML file and produce a CompiledLayout.java file with a
6specialized layout inflation function.
7
8To use it, let's assume you had a layout in `my_layout.xml` and your app was in
9the Java language package `com.example.myapp`. Run the following command:
10
11    viewcompiler my_layout.xml --package com.example.myapp --out CompiledView.java
12
13This will produce a `CompiledView.java`, which can then be compiled into your
14Android app. Then to use it, in places where you would have inflated
15`R.layouts.my_layout`, instead call `CompiledView.inflate`.
16
17Precompiling views like this generally improves the time needed to inflate them.
18
19This tool is still in its early stages and has a number of limitations.
20* Currently only one layout can be compiled at a time.
21* `merge` and `include` nodes are not supported.
22* View compilation is a manual process that requires code changes in the
23  application.
24* This only works for apps that do not use a custom layout inflater.
25* Other limitations yet to be discovered.
26
27## DexBuilder Tests
28
29The DexBuilder has several low-level end to end tests to verify generated DEX
30code validates, runs, and has the correct behavior. There are, unfortunately, a
31number of pieces that must be added to generate new tests. Here are the
32components:
33
34* `dex_testcase_generator` - Written in C++ using `DexBuilder`. This runs as a
35  build step produce the DEX files that will be tested on device. See the
36  `genrule` named `generate_dex_testcases` in `Android.bp`. These files are then
37  copied over to the device by TradeFed when running tests.
38* `DexBuilderTest` - This is a Java Language test harness that loads the
39  generated DEX files and exercises methods in the file.
40
41To add a new DEX file test, follow these steps:
421. Modify `dex_testcase_generator` to produce the DEX file.
432. Add the filename to the `out` list of the `generate_dex_testcases` rule in
44   `Android.bp`.
453. Add a new `push` option to `AndroidTest.xml` to copy the DEX file to the
46   device.
474. Modify `DexBuilderTest.java` to load and exercise the new test.
48
49In each case, you should be able to cargo-cult the existing test cases.
50
51In general, you can probably get by without adding a new generated DEX file, and
52instead add more methods to the files that are already generated. In this case,
53you can skip all of steps 2 and 3 above, and simplify steps 1 and 4.
54