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

Commit 9f7d0a4

Browse files
authored
Merge pull request #1423 from NativeScript/kddimitrov/android-application-bundle
docs: docs about Android App Bundle
2 parents f481c21 + 6a61988 commit 9f7d0a4

File tree

3 files changed

+97
-3
lines changed

3 files changed

+97
-3
lines changed

docs/tooling/publishing/android-abi-split.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ android {
3434
## ABI split with snapshots
3535
However if you want to improve the performance of your application with the `nativescript-dev-webpack` plugin you will need to make some additional changes.
3636

37-
The default file format that the `nativescript-dev-webpack` plugin produce when you execute `tns build android --bundle --env.uglify --env.snapshot` is a `.blob` file.
37+
The default file format that the `nativescript-dev-webpack` plugin produces when you execute `tns build android --bundle --env.uglify --env.snapshot` is a `.blob` file.
38+
39+
> Note: The snapshot generation feature is limited to macOS and Linux platforms due to inability to build the `mksnapshot` tool when running on Windows. Currently, the --env.snapshot flag is ignored on Windows.
3840
3941
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 ABI splits and you will find a corresponding `blob` for each architecture in the resulting .apk split file. I suppose this is the behavior you are currently experiencing.
4042

41-
If you want to take advantage of ABI splits 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.
43+
If you want to take advantage of ABI splits 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.
4244

4345
And here are the necessary changes that you need to do in your `webpack.config.js` in order to enable `.so` snapshot file generation:
4446

@@ -55,7 +57,7 @@ if (env.snapshot) {
5557
}
5658
```
5759

58-
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).
60+
The two 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).
5961

6062
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`:
6163

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
An Android App Bundle is a new publishing format that contains all the compiled code and resources of your app, but leaves the actual APK generation and signing to Google Play. The store then uses the app bundle to generate and serve optimized APKs based on the device configuration of the specific user. In general, the benefit of using Android App Bundles is that you no longer have to build, sign, and manage multiple APKs to support different devices, and users get smaller, more optimized downloads. For more information about the Android App Bundle, see the About Android App Bundles article in the official [Android Developer documentation](https://developer.android.com/guide/app-bundle/).
10+
11+
## Available configurations
12+
By default, the '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+
The performance and size of the application can be improved even further by configuring the `nativescript-dev-webpack` plugin.
28+
29+
The default file format that the `nativescript-dev-webpack` plugin produces when you execute `tns build android --bundle --env.uglify --env.snapshot --aab` is a `.blob` file.
30+
31+
> Note: The snapshot generation feature is limited to macOS and Linux platforms due to inability to build the `mksnapshot` tool when running on Windows. Currently, the --env.snapshot flag is ignored on Windows.
32+
33+
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`.
34+
35+
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.
36+
37+
And here are the necessary changes that you need to do in your `webpack.config.js` in order to enable `.so` snapshot file generation:
38+
39+
```
40+
if (env.snapshot) {
41+
plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
42+
chunk: "vendor",
43+
projectRoot: __dirname,
44+
webpackConfig: config,
45+
targetArchs: ["arm", "arm64", "ia32"],
46+
useLibs: true,
47+
androidNdkPath: "/Library/android-sdk-macosx/ndk-bundle"
48+
}));
49+
}
50+
```
51+
52+
The two 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).
53+
54+
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`:
55+
56+
```
57+
sourceSets {
58+
main {
59+
jniLibs.srcDirs = ["$projectDir/libs/jni", "$projectDir/snapshot-build/build/ndk-build/libs"]
60+
}
61+
}
62+
```
63+
64+
## Testing the produced `.aab` file
65+
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.
66+
67+
If you use the `bundletool` you should first generate an `.apks` file that will later be used to deploy on a device.
68+
69+
```
70+
java -jar <toolPath>/bundletool.jar build-apks --bundle=<somePath>/app.aab --output="<somePath>/my_app.apks"
71+
--ks=<path to keystore file>
72+
--ks-pass=pass:<keystore pass>
73+
--ks-key-alias=<key alias>
74+
--key-pass=pass:<key pass>
75+
```
76+
77+
Then you can install the application on a connected device by executing:
78+
```
79+
java -jar <toolPath>/bundletool.jar install-apks --apks="somePath/my_app.apks" --device-id=<deviceId>
80+
```
81+
82+
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
@@ -169,6 +169,16 @@ You can read more about these stages at ["Set up alpha/beta tests"](https://supp
169169

170170
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*.
171171

172+
### Android App Bundle
173+
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).
174+
175+
You can perform a full build and produce a signed AAB using the NativeScript CLI:
176+
```
177+
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
178+
```
179+
180+
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).
181+
172182
### Submission automation
173183

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

0 commit comments

Comments
 (0)