Monday, 15 June 2020

How to build an Android app for production using Native-script?

How to Build an Android App Using NativeScript

If you’re building Android apps with NativeScript, one of the important steps is preparing your app for production. This includes signing the app, generating a release build, and choosing the right file type for distribution.

Here’s a complete guide to help you through the process.


🔑 Step 1: Create a .jks Keystore File

Before you can publish your app, you’ll need a Java Keystore (.jks) file. This file is used to sign your app and is required every time you release an update.

👉 Important:

  • Store your .jks file in a safe location.

  • You must use the same .jks file for every update.

  • If you lose it, you’ll be forced to create a new .jks file and publish your app under a new package name.

📖 Official guide: Android App Signing


📦 Step 2: Build the Release Version

NativeScript gives you three options for building a production-ready Android app.


1) Generate an APK file

This is the traditional Android app package format.

tns build android --release \
--key-store-path [path-to-your.jks] \
--key-store-password [your-key-password] \
--key-store-alias [your-alias] \
--key-store-alias-password [your-alias-password]

The .apk file can then be uploaded directly to the Play Store or shared with users.


2) Generate an AAB file (Recommended)

Google now recommends the Android App Bundle (AAB) format because it reduces app size by delivering only the required resources for each device.

tns run android --release \
--key-store-path [path-to-your.jks] \
--key-store-password [your-key-password] \
--key-store-alias [your-alias] \
--key-store-alias-password [your-alias-password] \
--aab

3) Generate a Customized AAB file

You can optimize your app further with flags like --bundle, --env.uglify, --env.aot, and --env.snapshot. These options reduce size and improve performance.

tns run android --bundle --env.uglify --env.aot --env.snapshot \
--release \
--key-store-path [path-to-your.jks] \
--key-store-password [your-key-password] \
--key-store-alias [your-alias] \
--key-store-alias-password [your-alias-password] \
--aab --copy-to app1.aab

This will create an optimized .aab file named app1.aab.


⚠️ Note on App Size

A blank NativeScript project for Android is typically around 12MB. This is because it includes three versions of the NativeScript runtime to support different Android CPU architectures.

 Final Thoughts 

Always use the same .jks file for updates.

  • Prefer AAB over APK for smaller, more efficient app delivery.

  • Use build optimization flags for production-ready performance.

With these steps, you’re ready to publish your NativeScript Android app to the Play Store! 🎉


No comments:

Post a Comment