Skip to content

Instantly share code, notes, and snippets.

@l2dy
Created March 28, 2016 09:19
Show Gist options
  • Save l2dy/99c386b814b894943c27 to your computer and use it in GitHub Desktop.
Save l2dy/99c386b814b894943c27 to your computer and use it in GitHub Desktop.

Signing Your App Manually

You do not need Android Studio to sign your app. You can sign your app from the command line using standard tools from the Android SDK and the JDK. To sign an app in release mode from the command line:

  1. Generate a private key using keytool. For example:

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

This example prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app.

  1. Compile your app in release mode to obtain an unsigned APK.

  2. Sign your app with your private key using jarsigner:

$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_application.apk alias_name

This example prompts you for passwords for the keystore and key. It then modifies the APK in-place to sign it. Note that you can sign an APK multiple times with different keys.

  1. Verify that your APK is signed. For example:

$ jarsigner -verify -verbose -certs my_application.apk

  1. Align the final APK package using zipalign.

$ zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk

zipalign ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which reduces the amount of RAM consumed by an app.

@l2dy
Copy link
Author

l2dy commented Jun 13, 2016

zip -rD9 ../bili.apk .
keytool -genkey -v -keystore release-key.keystore -alias bili -keyalg EC -keysize 256 -validity 10000 -dname CN=bili
jarsigner -verbose -keystore release-key.keystore bili.apk bili
zipalign -v 4 bili.apk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment