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

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
    }
}