I made a sample application named checkStatus
. Now I want to create a signed APK file. So I can install it in different devices for my testing.
For this, I Googled and found this documentation.
As per the document, I switched to my project directory and ran the following command:
keytool -genkey -v -keystore key-name.keystore -alias alias-name -keyalg RSA -keysize 2048 -validity 10000
After I ran the above command, I got a file named key-name.keystore
at projectRoot/key-name.keystore
.
And then I copy-pasted that file into projectRoot/platforms/android/key-name.keystore
.
After that, I created a file named ant.properties
and saved it in projectRoot/platforms/android
.
I wrote the following code inside the file:
key.store=projectRoot/key-name.keystore
key.alias=myApp
After that, I ran the following command to release
Cordova builds android --release
It's throwing the following error:
/home/projectRoot/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: ant with args: release,-f,/home/projectRoot/platforms/android/build.xml,-Dout.dir=ant-build,-Dgen.absolute.dir=ant-gen
Error: /home/projectRoot/platforms/android/cordova/build: Command failed with exit code 8
at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)
So this time, I modified key.store
value in ant.properties
file like in the following way.
key.store=/home/projectRoot/platforms/android/key-name.keystore
Again, I ran the cordova build android --release
command. It throws the same error.
Can anyone tell me what I've done wrong?
An update to @malcubierre for Cordova 4 (and later)-
Create a file called
release-signing.properties
and put inAPPFOLDER\platforms\android
folderContents of the file: edit after = for all except 2nd line
Then this command should build a release version:
In the current documentation we can specify a build.json with the keystore:
And then, execute the commando with --buildConfig argumente, this way:
In cordova 6.2.0, it has an easy way to create release build. refer to other steps here Steps 1, 2 and 4
Step 1:
add the
--save
so that it removes the plugin from theconfig.xml
file.Step 2:
To generate a release build for Android, we first need to make a small change to the
AndroidManifest.xml
file found in platforms/android. Edit the file and change the line:and change
android:debuggable
tofalse
:As of cordova 6.2.0 remove the android:debuggable tag completely. Here is the explanation from cordova:
If on the other hand you specify a specific value in the manifest file, then the tools will always use it. This can lead to accidentally publishing your app with debug information.
Step 3:
Now we can tell cordova to generate our release build:
Then, we can find our unsigned APK file in
platforms/android/ant-build
. In our example, the file wasplatforms/android/ant-build/Example-release-unsigned.apk
Step 4:
Note : We have our keystore
keystoreNAME-mobileapps.keystore
in this Git Repo, if you want to create another, please proceed with the following steps.Key Generation:
Syntax:
Egs:
Then the Key store has been generated with name as NAME-mobileapps.keystore
Step 5:
Place the generated keystore in
old version cordova
New version cordova
To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:
Syntax:
Egs:
OR
This signs the apk in place.
Step 6:
Finally, we need to run the zip align tool to optimize the APK:
OR
OR
Now we have our final release binary called example.apk and we can release this on the Google Play Store.