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

..--

dex_builder_test/23-Nov-2023-541387

Android.bpD23-Nov-20232.4 KiB108101

OWNERSD22-Nov-202337 32

README.mdD22-Nov-20232.4 KiB5440

TEST_MAPPINGD22-Nov-2023302 2019

apk_layout_compiler.ccD23-Nov-20236 KiB176139

apk_layout_compiler.hD22-Nov-20231.1 KiB3512

dex_builder.ccD23-Nov-202324.2 KiB705551

dex_builder.hD23-Nov-202321.7 KiB627382

dex_layout_compiler.ccD23-Nov-20238.4 KiB209147

dex_layout_compiler.hD23-Nov-20233.5 KiB12480

dex_testcase_generator.ccD23-Nov-202314.5 KiB354245

java_lang_builder.ccD22-Nov-20234.6 KiB11690

java_lang_builder.hD22-Nov-20232 KiB6627

layout_validation.ccD22-Nov-20231.2 KiB4222

layout_validation.hD22-Nov-20231.4 KiB4719

layout_validation_test.ccD22-Nov-20235.9 KiB164131

main.ccD22-Nov-20235.2 KiB173127

tinyxml_layout_parser.ccD22-Nov-20231 KiB3513

tinyxml_layout_parser.hD22-Nov-20231.9 KiB6636

util.ccD23-Nov-20231.1 KiB3916

util.hD22-Nov-2023887 309

util_test.ccD22-Nov-20231.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