0

I don't have source code only have .apk file and i want to sign and zip-align it to upload on play store. How i can do this?

Sheraz
  • 567
  • 4
  • 22

1 Answers1

2

From official guide

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. 4. 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.

gio
  • 4,950
  • 3
  • 32
  • 46
  • I got this message on step 3. "jarsigner: unable to open jar file: app-3.apk" – Sheraz Dec 25 '14 at 07:07
  • Please make sure that apk exists at provided path, if you run command line from directory where `jarsigner` exists then you need to copy apk there too or provide full path to it – gio Dec 25 '14 at 07:11
  • Ok Thanks. In step 5 i am getting this message. "'zipalign' is not recognized as an internal or external command, operable program or batch file." – Sheraz Dec 25 '14 at 07:26
  • you can find `zipalign` at `{path-to-android-sdk}\build-tools\{version}\`, you can download SDK tools at [link](http://developer.android.com/sdk/index.html), see _Other Download Options_ – gio Dec 25 '14 at 07:30
  • Now while uploading i am getting this error. "Upload failed Your APK cannot be analyzed using aapt. Error output: Failed to run aapt dump badging: ERROR: dump failed because assets could not be loaded" – Sheraz Dec 25 '14 at 09:21
  • maybe http://stackoverflow.com/q/25477592/940720, I guess, there was some problem during creating apk – gio Dec 25 '14 at 09:23