2

I am trying to build signed app from cordova in my mac. Whenever I run cordova build android --release it release unsigned apk.

I have created the account on Play store. Also I checked multiple links to get this working.

How to create a signed APK file using Cordova command line interface?

http://cordova.apache.org/docs/en/6.x/guide/platforms/android/index.html#signing-an-app

I have few concern regarding key file.

As per Cordova documentation we can use build.json or Gradle to build the signed apk.

{
    "android": {
        "debug": {
            "keystore": "../android.keystore",
            "storePassword": "android",
            "alias": "mykey1",
            "password" : "password",
            "keystoreType": ""
        },
        "release": {
            "keystore": "../android.keystore",
            "storePassword": "",
            "alias": "mykey2",
            "password" : "password",
            "keystoreType": ""
        }
    }
}

Above code from Cordova site but I am not able to find build.json file.

Here is the code from gradle.

You can also specify signing properties by including a .properties file and pointing to it with the cdvReleaseSigningPropertiesFile and cdvDebugSigningPropertiesFile Gradle properties (see Setting Gradle Properties). The file should look like this:

storeFile=relative/path/to/keystore.p12
storePassword=SECRET1
storeType=pkcs12
keyAlias=DebugSigningKey
keyPassword=SECRET2
storePassword and keyPassword are optional, and will be prompted for if omitted.

But I am not sure from where I will get the details like storePassword KeyPassword DebugSigningKey.

I am using latest version of Cordova, 7.0.1.

halfer
  • 19,824
  • 17
  • 99
  • 186
Roxx
  • 3,738
  • 20
  • 92
  • 155

1 Answers1

3

You are only getting an unsigned APK since gradle cannot find your keystore which is used to sign your app.

To solve the issue, you need to do the following (this is like you you do in Windows, should be the same on Mac):

  1. Create keystore via console using something like keytool -genkey -v -keystore C:\mykeystore\CordovaRelease.keystore -alias CordovaRelease -keyalg RSA -keysize 2048 -validity 10000 Please make sure you have JRE installed.
  2. You will be asked for CN, OU,... and a password to be set, choose one.
  3. If you want to use different keystores for Debug/Release you can create another keystore
  4. Create build.json file in your Cordova project folder and reference the keystore like

    "android": {
        "debug": {
            "keystore": "..\mykeystore\CordovaDebug.keystore",
            "storePassword": "secretpassword",
            "alias": "CordovaDebug",
            "password" : "secretpassword",
            "keystoreType": ""
        },
        "release": {
            "keystore": "..\mykeystore\CordovaRelease.keystore",
            "storePassword": "",
            "alias": "CordovaRelease",
            "password" : "secretpassword",
            "keystoreType": ""
        }
    }
    

    The relative path goes from your Cordova project folder to the keystore folder.

  5. Run Cordova build from console like cordova build android --release, gradle will now take the build.json file and finds your keystore.

Hope this helps.

Shebuka
  • 3,148
  • 1
  • 26
  • 43
Nils
  • 94
  • 1
  • 5
  • Thanks for your answer. – Roxx Jun 24 '17 at 09:25
  • do i need to provide secretpassword and other details in json file or i need to use the above code without changing it. – Roxx Jun 24 '17 at 09:46
  • you can also use jar signer and then zip align it .. while using jar signer it will prompt you to enter your keyphrase. after that you will have to align it – Surya Krishy Jun 24 '17 at 11:31
  • i did that and added details in build.json but still when i build the app. it is unsigned. – Roxx Jun 24 '17 at 16:37
  • You need to change the details in your JSON file, at least password as chosen during keystore creation process and also the path to the keystore. – Nils Jun 25 '17 at 11:31