From 49efbd5e5f65b2a80b2ec2b4562b932f661992b3 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Fri, 2 Nov 2018 19:39:27 +0200 Subject: [PATCH 1/5] docs: docs about Android App Bundle --- docs/tooling/publishing/android-app-bundle.md | 80 +++++++++++++++++++ .../publishing/publishing-android-apps.md | 10 +++ 2 files changed, 90 insertions(+) create mode 100644 docs/tooling/publishing/android-app-bundle.md diff --git a/docs/tooling/publishing/android-app-bundle.md b/docs/tooling/publishing/android-app-bundle.md new file mode 100644 index 000000000..c8b9ccad6 --- /dev/null +++ b/docs/tooling/publishing/android-app-bundle.md @@ -0,0 +1,80 @@ +--- +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. + +## 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. + +``` +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. + +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. + +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. + +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 /bundletool.jar build-apks --bundle=/app.aab --output="/my_app.apks" +--ks= +--ks-pass=pass: +--ks-key-alias= +--key-pass=pass: +``` + +Then you can install the application on a connected device by executing: +``` +java -jar /bundletool.jar install-apks --apks="somePath/my_app.apks" --device-id= +``` + +You can find more information about using Android `bundletool` [here](https://developer.android.com/studio/command-line/bundletool). \ No newline at end of file diff --git a/docs/tooling/publishing/publishing-android-apps.md b/docs/tooling/publishing/publishing-android-apps.md index 7dc67a13e..0063c3058 100644 --- a/docs/tooling/publishing/publishing-android-apps.md +++ b/docs/tooling/publishing/publishing-android-apps.md @@ -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 --key-store-password --key-store-alias --key-store-alias-password --aab --copy-to .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). From e4400991b9ddfa8f5125c3a14df6785941eff949 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Tue, 6 Nov 2018 14:41:29 +0200 Subject: [PATCH 2/5] chore: add note that snapshot generation is not supported on Windows --- docs/tooling/publishing/android-abi-split.md | 2 ++ docs/tooling/publishing/android-app-bundle.md | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/tooling/publishing/android-abi-split.md b/docs/tooling/publishing/android-abi-split.md index d96217ae6..6c010fce3 100644 --- a/docs/tooling/publishing/android-abi-split.md +++ b/docs/tooling/publishing/android-abi-split.md @@ -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. + 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. diff --git a/docs/tooling/publishing/android-app-bundle.md b/docs/tooling/publishing/android-app-bundle.md index c8b9ccad6..9ff079fab 100644 --- a/docs/tooling/publishing/android-app-bundle.md +++ b/docs/tooling/publishing/android-app-bundle.md @@ -28,7 +28,9 @@ If you want to improve the performance of your application with the `nativescrip 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. -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. +> 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. + +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. From dbc4f67603cf81c734286ea33775f9b7ea421d51 Mon Sep 17 00:00:00 2001 From: Emil Tabakov Date: Tue, 6 Nov 2018 18:59:36 +0200 Subject: [PATCH 3/5] Update docs/tooling/publishing/android-app-bundle.md Co-Authored-By: KristianDD --- docs/tooling/publishing/android-app-bundle.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tooling/publishing/android-app-bundle.md b/docs/tooling/publishing/android-app-bundle.md index 9ff079fab..372d109f9 100644 --- a/docs/tooling/publishing/android-app-bundle.md +++ b/docs/tooling/publishing/android-app-bundle.md @@ -26,7 +26,7 @@ android { ## 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. -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. +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. > 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. @@ -79,4 +79,4 @@ Then you can install the application on a connected device by executing: java -jar /bundletool.jar install-apks --apks="somePath/my_app.apks" --device-id= ``` -You can find more information about using Android `bundletool` [here](https://developer.android.com/studio/command-line/bundletool). \ No newline at end of file +You can find more information about using Android `bundletool` [here](https://developer.android.com/studio/command-line/bundletool). From 7eba404b15eadc120af3a44d5b693e49f88fff3d Mon Sep 17 00:00:00 2001 From: Emil Tabakov Date: Tue, 6 Nov 2018 18:59:41 +0200 Subject: [PATCH 4/5] Update docs/tooling/publishing/android-app-bundle.md Co-Authored-By: KristianDD --- docs/tooling/publishing/android-app-bundle.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tooling/publishing/android-app-bundle.md b/docs/tooling/publishing/android-app-bundle.md index 372d109f9..b0b910634 100644 --- a/docs/tooling/publishing/android-app-bundle.md +++ b/docs/tooling/publishing/android-app-bundle.md @@ -49,7 +49,7 @@ if (env.snapshot) { } ``` -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). +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). 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`: From 6a61988cfb48430d31824b727cefeabe875f9bd0 Mon Sep 17 00:00:00 2001 From: Kristian Dimitrov Date: Wed, 7 Nov 2018 18:22:26 +0200 Subject: [PATCH 5/5] chore: fix comments on aab article --- docs/tooling/publishing/android-abi-split.md | 8 ++++---- docs/tooling/publishing/android-app-bundle.md | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/tooling/publishing/android-abi-split.md b/docs/tooling/publishing/android-abi-split.md index 6c010fce3..177ecb066 100644 --- a/docs/tooling/publishing/android-abi-split.md +++ b/docs/tooling/publishing/android-abi-split.md @@ -34,13 +34,13 @@ android { ## ABI split with snapshots 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. -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. +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. -> 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. +> 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. 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. +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. And here are the necessary changes that you need to do in your `webpack.config.js` in order to enable `.so` snapshot file generation: @@ -57,7 +57,7 @@ if (env.snapshot) { } ``` -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). +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). 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`: diff --git a/docs/tooling/publishing/android-app-bundle.md b/docs/tooling/publishing/android-app-bundle.md index b0b910634..f5e85bb61 100644 --- a/docs/tooling/publishing/android-app-bundle.md +++ b/docs/tooling/publishing/android-app-bundle.md @@ -6,10 +6,10 @@ 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. +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/). ## 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. +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. ``` android { @@ -24,15 +24,15 @@ android { ``` ## 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. +The performance and size of the application can be improved even further by configuring the `nativescript-dev-webpack` plugin. 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. -> 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. +> 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. 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. +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. And here are the necessary changes that you need to do in your `webpack.config.js` in order to enable `.so` snapshot file generation: