Hello to all,
** Read this message below, because App Builder incorporates now visual tools to do this! **
This thread want to explain how to sign our APK files in order to be published in the Google Play Store. This post is based in the official Google documentation and uses the appropiate keytool and jarsigner programs, included by the Java JDK installation, as well the zipalign program, included by the Android SDK installation.
Step 1/4 - Prepare our release APK file
App Builder can creates three BAT files to prepare our application to be build with Apache Cordova. This three BATH files are "cordova_android_debug.bat", "cordova_android_run.bat" and "cordova_android_release.bat" file.
We normally use the first one or the second one in order to try our application's APK in our Android device, but, when we are ready to publish our application, we must use the third BAT file, in order to get an APK (yet unsigned) ready to be upload to the Google Play Store.
Once we execute the "cordova_android_release.bat" file we get our APK in the directory "MyApp_Compiled\platforms\android\build\outputs\apk\".
Step 2/4 - Prepare our "keys"
In order to sign our APK file, we need to create a couple of public/private keys for our own use. This step must be made at least one time, that is, once we prepare our "keys" file, we can use such file to sign various APK files.
We use the "keytool" to create our keys. The "keytool" is included by the Java JDK, something we have already installed (because it's required to installing Apache Cordova). The command we must use is the below one:
The above command creates our keys in the file "D:\MyKeys.keystore". Of course you can specify another path and file name. However, take care about such path, because we use later when sign the APK files. Also, you must replace this information with your own one:
Common Name = Your name, for example, David Esperalta
Organization Unit = Your organization unit, for example, AndroidSoft
Organization Name = Your organization name, for example, David Esperalta Soft
Locality Name = Your locality name, for example, Madrid
State Name = Your state name, for example, Madrid
Country 2 Digit Code = Your country 2 digit code, for example, ES (for Spain)
Note we need to replace the "MyAlias" too. Just choose an alias to be used later when sign our APK files. You also need to replace the "MyPassword" in the above command with your own password. I think we can use (for simplicity) the same password for both "keypass" and "storepass". Later we need to use this password when sign our APK files, so remember it.
If the above command is well executed, then the "D:\MyKeys.keystore" is created, and we can use in the below step.
Step 3/4 - Sign our APKs
Once we have created our "keys" we can use it in order to sign our APKs. This is does using the "jarsigner" tool, which is also included with the Java JDK installation. The command we can use is the below one:
The above command finally sign our APK file. Note we specify "MyPassword" in both "storepass" and "keypass". This password must be the same that we used above in the step 2. Also we use "MyAlias", that, again, must be the same we used above in the step 2.
On the other hand, as you can see, we specify in the above command the path for our "MyKeys.keystore" file and of course the path of our unsigned "MyApp.apk" file. Of course you must replace this paths by your own ones.
And that's all! Finally we can check (optionally) if our APK file has been correctly signed by this command:
Note we specify the path for our APK file.
Step 4/4 - "Align" our APK file
I am not completely sure if this step is really needed. Anyway, apparently we can use the "zipalign" tool (this time included by the Android SDK installation) in order to "provides important optimization to Android application (.apk) files.", as we can read here in the official documentation.
Anyway, using the "zipalign" tool is not too much complicated, just the below command:
As you can see, we indicate our signed APK file and must to provide an ouput file, different to the first one, in this case "MyApp_Aligned.apk", to save the aligned APK file. Is this final "D:\MyApp_Aligned.apk" the file that we must use to upload into our Google Play Store account, in order to publish our APK.
That's all! I hope this post can help to all. Fell free to post any question here.