Skip to content

Build Android App

Before we start the build App process, please make sure you have the following settings ready:

Note

It is highly recommended that you build Android and iOS App in seperate project folders.

Preparing a release Android APP bundle

The Android App Bundle is Android's new, official publishing format. Follow these steps to prepare a release APP Bundle for the Google Play Store.

Steps

  1. Open your terminal and cd to the project root.

    cd hamv_mobile
    
  2. Generate a release keystore.

    keytool -genkey -v -keystore <keystoreName>.keystore -alias <keystoreAlias> -keyalg RSA -keysize 2048 -validity <keystoreValidityTime> 
    

    Note

    keystoreName can be any words. e.g., release

    keystoreAlias is similar to keystoreName

    keystoreValidityTime is validity number of days. e.g., 365

  3. (Optional) Generate a key hash for Facebook Login.

    keytool -exportcert -alias <keystoreAlias> -keystore <keystoreName>.keystore | openssl sha1 -binary | openssl base64
    
  4. (Optional) Put your release key hash to Facebook developer:

    • Go to Facebook for Developers website
    • Select your app
    • Go to the page Settings/Basic https://developers.facebook.com/apps/<your APP Id>/settings/
    • Find the block "Android"
    • Put the key hash that you just generated into the field "Key Hashes"
    • Click "Save Changes"
  5. Prepare a production release config.

    • Copy and paste your release.keystore file to <project_root>/keystores folder.
    • If you have not applied env.sh in previous chapter, please create a json file called build.json under project root. Add the release information block to android scope. Edit storePassword, alias and password values.

    Here is an example of a build configuration file:

    {
        "android": {
            "debug": {
                "keystore": "./keystores/debug.keystore",
                "storePassword": "android",
                "alias": "androiddebugkey",
                "password" : "android",
                "keystoreType": ""
            },
            "release": {
                "keystore": "./keystores/release.keystore",
                "storePassword": "<release_keystore_password>",
                "alias": "<keystoreAlias>",
                "password" : "<release_password>",
                "keystoreType": ""
            }
        }
    }
    
  6. Build Docker image.

    docker-compose build
    
  7. Start a Docker container based on the built image.

    docker-compose run app sh
    
  8. Run build by using either method (a) or method (b)

    (a) Use env.sh for project configuration

    If you have applied your app settings in env.sh file, please execute the following commands to install build environment dependencies under /work $:

    ./customer/hamv_mobile_android.sh
    

    (b) Manually set project configuration

    If you did not apply the env.sh file but modified app configurations in package.json, config.xml, and app.config.ts, please run build by the following steps:

    (1) Run the following commands one by one under /work $.

    npm i app-engine-3.0.0.tgz
    
    npm i
    
    ionic cordova resources android --icon
    
    ionic cordova platform add android@13.0.0
    
    ionic cordova prepare android
    

    (2) Build the debug/release version by the following commands:

    Build debug version (apk):

    ionic cordova build android --device --prod --debug
    
    Build release version (aab):
    ionic cordova build android --device --prod --release
    
    Build release version (apk):
    cordova build android --prod --release "--" --packageType=apk  --verbose
    

  9. You should be able to see the “BUILD SUCCESSFUL” message.

    Note

    If the build failed, please remove the build materials by using this command in Docker container (under /work $) and repeat step 8 again.

    rm -rf node_modules/ plugins/ platforms/ .angular/
    

  10. After building process is done, you can find your android-release.aab under <project_root>/platforms/android/app/build/outputs/bundle/release folder. Or android-release.apk under <project_root>/platforms/android/app/build/outputs/apk/debug > apk folder.

Now you have your final release binary and you can release this to Google Play Store. See next chapter to publish your app on Google Play Store.


Have more questions? Submit a request