srbhakta
srbhakta

Reputation: 75

Sign apk using certificate.pem and key.pk8 in Android Studio by using gradle

how to use below commands in Android Studio? java -jar signapk.jar certificate.pem key.pk8 file.apk file-signed.apk

Upvotes: 6

Views: 12045

Answers (4)

S. Ber Rosenberg
S. Ber Rosenberg

Reputation: 107

Try adding the following to a .cmd file

    set /P apk="What is the path of the APK?" 
"C:\Users\<your user name>\AppData\Local\Android\Sdk\build-tools\<any folder>\apksigner.bat" sign --key "C:\Users\<your user name>\Documents\platform.pk8" --cert "C:\Users\<your user name>\Documents\platform.x509.pem" %apk%

Upvotes: 0

Elad
Elad

Reputation: 1655

  1. Copy APK and Key Files to the following folder: C:\Users%USERNAME%\AppData\Local\Android\Sdk\build-tools* (Any of the subfolders will do; for example: 27.0.3)

  2. Sign the APK with the following command: apksigner.bat sign --key .pk8 --cert .x509.pem APKFILE.apk

Upvotes: 1

The Good Giant
The Good Giant

Reputation: 1780

My reply comes probably too late for the question itself, but could be useful to someone else.

In order to sign an apk with Android studio you need to provide a .keystore file. Now, following this tutorial I found this tool that allows you to create a keystore file starting from your .pk8 and .pem files. All you have to do is:

  1. Download keytool (from the link I gave you)
  2. Generate your keystore file keytool-importkeypair -k ~/.android/key.keystore -p android -pk8 platform.pk8 -cert platform.x509.pem -alias platform
  3. Use it to sign your app, either clicking on 'Build--> Generate Signed Bundle / APK' or using singingConfig in your app's .gradle:
signingConfigs {
    config {
        storeFile file("key.keystore")
        storePassword 'password'
        keyAlias 'alias'
        keyPassword 'password'
        }
}

buildTypes {
    release {
        signingConfig signingConfigs.config
    }
}

Upvotes: 14

x.iva
x.iva

Reputation: 74

  1. Generate unsigned apk
  2. Download signapk.jar (I found one here: https://github.com/appium/sign - link to .jar: https://github.com/appium/sign/raw/master/dist/signapk.jar)
  3. Place it under your app folder
  4. Locate your certificate and key (certificate.pem, key.pk8)
  5. Open terminal in Android Studio and type java -jar signapk.jar <path_to_certificate>/certificate.pem <path_to_key>/key.pk8 <path_to_your_apk>/yourapp-unsigned.apk yourapp-signed.apk
  6. If succeeded, locat your yourapp-signed.apk under your app folder

Upvotes: 1

Related Questions