Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit 49efbd5

Browse files
committed
docs: docs about Android App Bundle
1 parent 969c161 commit 49efbd5

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: Android App Bundle
3+
description: Learn what is Android App Bundle and how to use it.
4+
position: 50
5+
slug: android-app-bundle
6+
---
7+
8+
# Android App Bundle
9+
Android App Bundle is a new publishing format which makes it easier to reduce the size of application download from Google Play Store, without uploading multiple `.apk` files.
10+
11+
## Available configurations
12+
By default 'arm64-v8a' CPU architecture is excluded from the build of NativeScript application. The following configuration will enable it, but there is a chance that on older devices with this architecture this might affect the startup times.
13+
14+
```
15+
android {
16+
....
17+
defaultConfig {
18+
....
19+
ndk {
20+
abiFilters.clear()
21+
}
22+
}
23+
....
24+
```
25+
26+
## Additional optimizations
27+
If you want to improve the performance of your application with the `nativescript-dev-webpack` plugin you might want to make some additional changes.
28+
29+
The default file format that the `nativescript-dev-webpack` plugin produce when you execute `tns build android --bundle --env.uglify --env.snapshot --aab` is a `.blob` file.
30+
31+
For each of the architectures that you specify in your `webpack.config.js`, the plugin will produce a `snapshot.blob` file inside `assets/snapshots/${target_arch}/snapshot.blob`. Those files are **not** subject to Android App Bundle and you will find a corresponding `blob` for each architecture in the resulting .apks. This will increase the size of the resulting .apks.
32+
33+
If you want to take advantage of Android App Bundle you will need to instruct the `nativescript-dev-webpack` plugin to produce a `.so` snapshot. For this purpose you will need to have the Android NDK installed on your system. It is strongly recommended that the same version of the NDK is used to produce the snapshot file as the one used to compile the {N} runtime itself. Currently we use NDK r16b.
34+
35+
And here are the necessary changes that you need to do in your `webpack.config.js` in order to enable `.so` snapshot file generation:
36+
37+
```
38+
if (env.snapshot) {
39+
plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
40+
chunk: "vendor",
41+
projectRoot: __dirname,
42+
webpackConfig: config,
43+
targetArchs: ["arm", "arm64", "ia32"],
44+
useLibs: true,
45+
androidNdkPath: "/Library/android-sdk-macosx/ndk-bundle"
46+
}));
47+
}
48+
```
49+
50+
The 2 important switches to note here are `useLibs: true` (which instructs the plugin to produce a `.so` file) and `androidNdkPath` (make sure you point this to a folder containing Android NDK r12b).
51+
52+
One final thing before building the application is to instruct gradle to actually include the resulting snapshot into the final apk. This can be done in your `App_Resources/Android/app.gradle`:
53+
54+
```
55+
sourceSets {
56+
main {
57+
jniLibs.srcDirs = ["$projectDir/libs/jni", "$projectDir/snapshot-build/build/ndk-build/libs"]
58+
}
59+
}
60+
```
61+
62+
## Testing the produced `.aab` file
63+
In order to test the `apk` files that Google Play will produce from the `.aab` for a specific device you will need to use the Android `bundletool` or upload to Google Play and use a test track.
64+
65+
If you use the `bundletool` you should first generate an `.apks` file that will later be used to deploy on a device.
66+
67+
```
68+
java -jar <toolPath>/bundletool.jar build-apks --bundle=<somePath>/app.aab --output="<somePath>/my_app.apks"
69+
--ks=<path to keystore file>
70+
--ks-pass=pass:<keystore pass>
71+
--ks-key-alias=<key alias>
72+
--key-pass=pass:<key pass>
73+
```
74+
75+
Then you can install the application on a connected device by executing:
76+
```
77+
java -jar <toolPath>/bundletool.jar install-apks --apks="somePath/my_app.apks" --device-id=<deviceId>
78+
```
79+
80+
You can find more information about using Android `bundletool` [here](https://developer.android.com/studio/command-line/bundletool).

docs/tooling/publishing/publishing-android-apps.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ You can read more about these stages at ["Set up alpha/beta tests"](https://supp
168168

169169
Once you upload your APK, it will go through a review. When approved, you can move it to production to make it available on *Google Play*.
170170

171+
### Android App Bundle
172+
If you want to reduce the size of the application download from Google Play Store you can check how to achieve this in [Android App Bundle article](http://docs.nativescript.org/publishing/android-app-bundle.html).
173+
174+
You can perform a full build and produce a signed AAB using the NativeScript CLI:
175+
```
176+
tns build android --release --key-store-path <path-to-your-keystore> --key-store-password <your-key-store-password> --key-store-alias <your-alias-name> --key-store-alias-password <your-alias-password> --aab --copy-to <aab-location>.aab
177+
```
178+
179+
Then you can use the produced file to upload it to Google Play Developer Console following the steps described in [Google Android Developer Documentation](https://developer.android.com/studio/publish/upload-bundle).
180+
171181
### Submission automation
172182

173183
Some tools allow the submission process to be automated - [MIT Licensed one: fastlane](https://github.com/fastlane/fastlane).

0 commit comments

Comments
 (0)