Signing the Android Apk

Apk file for Android protected by LIAPP must do signing and zipalign.

The App file that the signing is not done cannot be installed on the device, and the App file that zipalign is not done may not be registered in the market.

Sign the files by using jarsigner or apksinger depending on the APK Signature Scheme version used to build apk files.

You can use jarsigner for an apk file to which v1 is applied but you should use apksigner for an apk file to which v2 is applied and targetSdkVersion=30 or higher.

You can check the Signature Scheme version of the apk file as below.

  1. Check Android Studio
  • Go to the Generate Signed Bundle or APK option and check if V2 (Full APK Signature) is ticked.
    ANDROID STUDIO
  1. Check command
    • Excute command
      java -jar [apksigner.jar Path] verify -v --print-certs [The path of apk before applying LIAPP]

    • Check Verified using v2 scheme (APK Signature Scheme v2): true
      CHECK APKSIGNER

    • The apksinger file is located in the build-tools of the path where Android SDK is installed

When you use a jarsinger, you should signing first and then zipalign the file. However, when you use apksinger, you should zipalign first before signing.

Signing and zipalign command using jarsigner
  1. jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 –keystore [keystore file Path] [APP path for signing] [alias_name of the user you created when the key is generated]

  2. Enter your password (your input is not shown on the screen)

  3. zipalign -f -v 4 4 [APP path for zipalign] [APP Path that zipalign is done]
      

Example of signing and zipalign using jarsigner

C:\>jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore C:\my-release-key.keystore LIAPP_with_APP.apk LOCKINCOMPANY
Enter Passphrase for keystore : password
C:\>zipalign -f -v 4 LIAPP_with_APP.apk LIAPP_with_APP_zipaligned.apk

Zipalign and signing command using apksigner
  1. zipalign -f -v 4 [APP path for zipalign] [APP Path that zipalign is done]

  2. java -jar [apksigner.jar Path] sign –ks [keystore file Path] –ks-key-alias [alias_name of the user you created when the key is generated] [APP path for signing]

  3. Enter your password (your input is not shown on the screen)
      

Example of signing and zipalign using apksigner

C:\>zipalign -f -v 4 LIAPP_with_APP.apk LIAPP_with_APP_zipaligned.apk 
C:\>java -jar D:\android\sdk\build-tools\30.0.0\lib\apksigner.jar sign --ks C:\my-release-key.jks --ks-key-alias LOCKINCOMPANY LIAPP_with_APP_zipaligned.apk
Keystore password for signer #1: password