Home Tutorials How to create signed android apk with Apache Cordova

How to create signed android apk with Apache Cordova

53
0

Steps to create a signed release android apk with Apache Cordova.

To upload an app to the Google Play Store, you need to sign it first. We are going to learn about how to sign android apk with Cordova environment. I assumed you have Cordova, android environment available on your machine and you already added an android platform for your project.

Method 1:-

#1. Create keystore file to sign apk.

Go to the root path of your project and run below command.

$ keytool -genkey -v -keystore appreleasedemo.keystore -alias appreleasedemoalias
-validity 10000

Above command create keystore file at root level i.e appreleasedemo.keystore (the binary file which can hold a set of a key). validity flag is used to set the expiration of your signature.(You can change keystore file name and alias name)

#2. Create properties file.

Create file having file extension *.properties at a root level. ~release-signing.propertiesAdd these attributes to release-signing.properties file.

storeFile=/appreleasedemo.keystore
storeType=jks
keyAlias =appreleasedemoalias
[email protected]%^@[email protected]
[email protected]%^@[email protected]

Here-

storeFile: Path to a binary file which can hold a set of keys

storeType: extensionEither pkcs12 or jks

keyAlias: The id specifying the private key used for signing

storePassword: Password to the keystore

keyPassword: Password for the private key specified

storePassword and keyPassword are optional.

#3. Move above two files to (1.appreleasedemo.keystore 2.release-signing.properties) location ~/platforms/android

#4. Set version release and version code and package name.

Open root config.xml file from root level and edit widget tag having below attributes:-

  1. android-versionCode=”50″ 
  2. id=”com.demo.apprelease”
  3. version=”0.2.3″
<widget android-versionCode="50" id="com.demo.apprelease" version="0.2.3" …..>

id – is a package name of our app. If keystore file changed then need to change package name also because apk with existing package name with new signing key not accepted by google play console.

android-versionCode –

Not shown to users. Used for internal calculation(google play store) to protect against downgrades by android system. Used to calculate one version is more recent than another. A higher number means recent version. You cannot upload an APK to the Play Store with previous version code.

Version –

Used as shown to users. Version format <major>.<minor>.<point>string.

#5.Build android release

$ cordova build android --release

Release apk created on path ~/platforms/android/build/outputs/apk/android-release.apk

#6. Upload to Google play store console.

Sign up for a Google Play Developer account select option edit release and choose apk file to upload.

Method 2:-

If, you don’t want to use *.properties file then use below command to create release apk.

I think method 1 is better than below command. In this method you need to mention keystore path, passwords etc. in command each time. *.properties file is maintainable in compare to below command.

$cordova build android --release -- --keystore=/appreleasedemo.keystore --[email protected]%^@[email protected] --alias=appreleasedemoalias --[email protected]%^@[email protected]

Method 3:-

Alternatively, Instead of *.properties file, you could use build.json file. Specify all configuration in JSON format. Use the –buildConfig flag to the same commands.

$ cordova build android --release --buildConfig

Create build.json file:

{
    "android": {
        "debug": {
            "keystore": "/appreleasedemo.keystore",
            "storePassword": "[email protected]%^@[email protected]$",
            "alias": "appreleasedemoalias",
            "password" : "[email protected]%^@[email protected]$",
            "keystoreType": "jks"
        },
        "release": {
            "keystore": "/appreleasedemo.keystore",
            "storePassword": "[email protected]%^@[email protected]$",
            "alias": "appreleasedemoalias",
            "password" : "[email protected]%^@[email protected]$",
            "keystoreType": "jks"
        }
    }
}


LEAVE A REPLY

Please enter your comment!
Please enter your name here