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

docs: docs about Android App Bundle #1423

Merged
merged 5 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/tooling/publishing/android-abi-split.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ However if you want to improve the performance of your application with the `nat

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.

> Note: The snapshot generation feature is limited to macOS and Linux platforms due to inability to build `mksnapshot` tool running on Windows. Currently, the --env.snapshot flag is ignored on Windows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...) due to inability to build the mksnapshot tool when running on Windows. (...)


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.

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.
Expand Down
82 changes: 82 additions & 0 deletions docs/tooling/publishing/android-app-bundle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
title: Android App Bundle
description: Learn what is Android App Bundle and how to use it.
position: 50
slug: android-app-bundle
---

# Android App Bundle
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend going for something more descriptive here. For example, the Android developer docs have a lot of information on this subject https://developer.android.com/guide/app-bundle/. You can use something like this:

"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"

Alternatively, you can add only the last sentence, so that people who would like to learn more can go there and read the article :)


## Available configurations
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after By default:
By default, the arm-v8a CPU architecture is (...)


```
android {
....
defaultConfig {
....
ndk {
abiFilters.clear()
}
}
....
```

## Additional optimizations
If you want to improve the performance of your application with the `nativescript-dev-webpack` plugin you might want to make some additional changes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this sentence correctly, you should use need to or should instead of might want to. And a comma is missing before you:
(...) application with the nativescript-dev-webpack plugin, you might want to should make some additional changes. (...)


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.

> Note: The snapshot generation feature is limited to macOS and Linux platforms due to inability to build `mksnapshot` tool running on Windows. Currently, the --env.snapshot flag is ignored on Windows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(...) due to inability to build the mksnapshot tool when running on Windows. (...)


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`.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to state that snapshots cannot be generated on windows

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma before you:
(...) For this purpose, you will need to instruct (...)


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

```
if (env.snapshot) {
plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
chunk: "vendor",
projectRoot: __dirname,
webpackConfig: config,
targetArchs: ["arm", "arm64", "ia32"],
useLibs: true,
androidNdkPath: "/Library/android-sdk-macosx/ndk-bundle"
}));
}
```

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).

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

```
sourceSets {
main {
jniLibs.srcDirs = ["$projectDir/libs/jni", "$projectDir/snapshot-build/build/ndk-build/libs"]
}
}
```

## Testing the produced `.aab` file
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.

If you use the `bundletool` you should first generate an `.apks` file that will later be used to deploy on a device.

```
java -jar <toolPath>/bundletool.jar build-apks --bundle=<somePath>/app.aab --output="<somePath>/my_app.apks"
--ks=<path to keystore file>
--ks-pass=pass:<keystore pass>
--ks-key-alias=<key alias>
--key-pass=pass:<key pass>
```

Then you can install the application on a connected device by executing:
```
java -jar <toolPath>/bundletool.jar install-apks --apks="somePath/my_app.apks" --device-id=<deviceId>
```

You can find more information about using Android `bundletool` [here](https://developer.android.com/studio/command-line/bundletool).
10 changes: 10 additions & 0 deletions docs/tooling/publishing/publishing-android-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ You can read more about these stages at ["Set up alpha/beta tests"](https://supp

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

### Android App Bundle
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).

You can perform a full build and produce a signed AAB using the NativeScript CLI:
```
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
```

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).

### Submission automation

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