Skip to content

Commit 3a5b55b

Browse files
author
agiuglia
committed
Add bundletool script samples
Change-Id: I3625feb040f9a1aa36846e62c93e43e184039d74
1 parent e7abfa7 commit 3a5b55b

7 files changed

Lines changed: 1979 additions & 0 deletions

File tree

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Asset Pack packaging scripts
2+
3+
## Setup
4+
5+
1. Set up virtualenv (Optional, recommended)
6+
7+
```
8+
$ virtualenv -p python3 venv
9+
$ . ./venv/bin/activate
10+
```
11+
12+
2. Install required packages
13+
14+
```
15+
(venv) $ pip install -r requirements.txt
16+
```
17+
18+
## Usage
19+
20+
### Generating Asset Packs
21+
22+
```
23+
$ generate_asset_pack.py \
24+
--packagename APP_PACKAGE_NAME \
25+
--deliverymode [install-time, fast-follow, on-demand] \
26+
--assetsdir ASSETS_DIR \
27+
--outdir OUTPUT_DIR \
28+
--assetpackname MY_PACK
29+
```
30+
31+
### Adding Asset Packs into an App Bundle
32+
33+
```
34+
$ add_packs.py \
35+
--androidsdk ANDROID_SDK_PATH \
36+
--sdkver SDK_VERSION \
37+
--buildtoolsver BUILD_TOOLS_VERSION \
38+
--bundletool BUNDLETOOL_JAR \
39+
--inputbundle APP.AAB \
40+
--packdir PACK_DIR \
41+
--packnames MY_PACK_1.ZIP,MY_PACK_2.ZIP \
42+
--output OUTPUT_APP.AAB \
43+
[--overwrite] \
44+
[--striptcfsuffixes] \
45+
[--prelollipop] \
46+
[--compressinstalltimeassets] \
47+
```
48+
49+
Please note that the last flag (compressinstalltimeassets) is an EAP feature, and
50+
availability is restricted to allowed titles only.
51+
52+
#### Making texture targeted asset packs
53+
54+
Generate your asset files in multiple formats (ASTC, ETC2, ETC1, etc...), and
55+
put them in directories suffixed by `#tcf_xxx` (see values for `xxx` below). For
56+
example:
57+
58+
```
59+
my_asset_pack
60+
├── some_common_file
61+
├── some_common_directory
62+
│   └── ....
63+
├── textures
64+
│   └── some_file
65+
├── textures#tcf_astc
66+
│   └── some_file
67+
├── textures#tcf_dxt1
68+
│   └── some_file
69+
├── textures#tcf_etc2
70+
│   └── some_file
71+
└── textures#tcf_pvrtc
72+
└── some_file
73+
```
74+
75+
Generate your asset packs as usual (with `generate_asset_pack.py`) and,
76+
optionally, generate your AAB with the `--striptcfsuffixes` option. The Android
77+
App Bundle that will be built when using this asset pack will have **a variant
78+
of the asset pack for each texture format**.
79+
80+
If you specified `--striptcfsuffixes`, the `#tcf_xxx` suffixes will be removed
81+
from the folder names in each variant of the asset packs. This means that a
82+
folder named `my_asset_pack/textures#tcf_etc2` will be renamed to
83+
`my_asset_pack/textures` in the ETC2 asset pack.
84+
85+
You can build the apks with bundletool and inspect the content to verify this:
86+
87+
```bash
88+
bundletool build-apks --bundle=out/appbundle_with_tcf_asset_packs.aab --output=out/appbundle_with_tcf_asset_packs.apks
89+
zipinfo out/appbundle_with_tcf_asset_packs.apks
90+
# Note the variants for my_asset_pack:
91+
# -rw---- 1.0 fat 6469 bx stor 70-Jan-01 01:00 asset-slices/my_asset_pack-other_tcf.apk
92+
# -rw---- 1.0 fat 6448 bx stor 70-Jan-01 01:00 asset-slices/my_asset_pack-astc.apk
93+
# -rw---- 1.0 fat 6461 bx stor 70-Jan-01 01:00 asset-slices/my_asset_pack-etc2.apk
94+
# -rw---- 1.0 fat 6467 bx stor 70-Jan-01 01:00 asset-slices/my_asset_pack-dxt1.apk
95+
# -rw---- 1.0 fat 6619 bx stor 70-Jan-01 01:00 asset-slices/my_asset_pack-master.apk
96+
# -rw---- 1.0 fat 6473 bx stor 70-Jan-01 01:00 asset-slices/my_asset_pack-pvrtc.apk
97+
# ...
98+
```
99+
100+
Each asset pack variant contains only the common directories, and the
101+
directories for one texture format.
102+
103+
The targeting is done as such:
104+
105+
- All supported formats are: `astc, pvrtc, s3tc, dxt1, latc, atc, 3dc, etc2,
106+
etc1, paletted`.
107+
108+
- Google Play delivers the first format, in this order, that is supported
109+
by the device.
110+
111+
- If a folder has no suffix and has sibling(s) with the same base name but
112+
suffixed (like `textures` in this example), it will be considered as a
113+
"fallback". In this directory, place the default format of your texture
114+
assets.
115+
116+
- If none of the texture formats in the App Bundle are supported by the
117+
device, Google Play delivers the "fallback" asset pack.
118+
119+
### Example
120+
121+
```
122+
$ generate_asset_pack.py \
123+
--packagename com.karahan.ibrahim.dynamic.assetpacksapp \
124+
--assetpackname myassets \
125+
--deliverymode on-demand \
126+
--assetsdir ~/assets/myassets/ \
127+
--outdir ~/assets/asset_packs
128+
```
129+
130+
```
131+
$ add_packs.py \
132+
--androidsdk ~/Android/Sdk \
133+
--sdkver 28 \
134+
--buildtoolsver 28.0.3 \
135+
--bundletool ~/bundletool-all-0.10.3.jar \
136+
--inputbundle ~/src/app/release/app.aab \
137+
--packdir ~/assets/asset_packs \
138+
--packnames=myassets.zip \
139+
--output ~/aug.aab
140+
```
141+
142+
## Misc
143+
144+
### Python Source File for App Bundle Config Proto
145+
146+
The file `config_pb2.py` is generated from `config.proto` in
147+
[Bundletool source](https://github.com/google/bundletool/blob/master/src/main/proto/config.proto)
148+
using protobuf compiler (`protoc`). The compiler is installed together with the
149+
protobuf C++ runtime which is available on
150+
[GitHub](https://github.com/protocolbuffers/protobuf).
151+
152+
It can be installed on Debian-like systems with: `$ sudo apt install
153+
protobuf-compiler` and on macOS with [Macports](https://www.macports.org/) with:
154+
`$ sudo /opt/local/bin/port install protobuf3-cpp`
155+
156+
Use the following command to regenerate `config_pb2.py` if required: `$ protoc
157+
--python_out . config.proto`

PlayAssetDelivery/BundletoolScriptSample/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)