'How to generate Android app bundle for ionic 3 signed apk

I have generated the apk using the command:

ionic cordova build android --prod --release

after that I have generated the key for Play Store using the command:

keytool -genkey -v -keystore myapp-release-key.keystore -alias com.exel.myapp -keyalg RSA -keysize 2048 -validity 10000

later I have signed using jarsigner command:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore myapp-release-key.keystore platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk com.exel.myapp

finally I am bundling using Zipalign with this command:

C:\Users\Exel\AppData\Local\Android\sdk\build-tools\29.0.0\zipalign -v 4 platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk myapp-release-signed.apk

When I am uploading the app to the Play Store it’s giving a warning like unoptimized code “please bundle using an Android app bundle”.

So, I need suggestions and solutions for this problem. I will be very thankful for this forum if I can fix this with your help.

When I am trying to do an Android apk/bundle using an Android Studio 3.4.1 it’s giving me a warning like “Android Gradle Plugin version should be 3.2 or higher”. When I am clicking the update button it’s getting dismissed and continuously showing the same message every time.

“Android Gradle Plugin version should be 3.2 or higher”.



Solution 1:[1]

If you are missing one step, try this. I am using this command to build a release app:

To generate Keystore file:

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

Build android

ionic cordova build android --prod --release

To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name

zipalign -v 4 HelloWorld-release-unsigned.apk HelloWorld.apk

apksigner verify exercisetips.apk

In the above command you are not using this one:

jarsigner -verify -verbose -certs C:\ionic\myapp\platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk

Let me know if it's works for you or not. Hope it helps you :)

Solution 2:[2]

The most straight forward way is always command line scripts... This is the sequence of steps to prepare deploy to production an optimized bundle.

  1. create package
    ionic cordova build android --prod --release
  2. build app bundle (optimization) KEY STEP
    cd [YOUR_PROJECT_FOLDER_PATH]\platforms\android
    gradlew.bat bundle
  3. sign the app bundle
    cd [YOUR_PROJECT_FOLDER_PATH]\platforms\android\app\build\outputs\bundle\release
    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore "[YOUR_certificate-keys.jks_FILE_PATH]" app-release.aab [YOUR_NAME] -storepass [YOUR_CERTIFICATE_PASSWORD]
  4. Just upload your boundle (*.aab) YOUR_PROJECT_FOLDER_PATH\platforms\android\app\build\outputs\bundle\release\app-release.aab

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Market