3

I am finding it extremely difficult to get my heard around signing my app under the new cordova 5.0 guideline

this is what i have done

(bongoapp)project root
 ->build.json
 ->phistoKey.keystore
 ->www

this is what i have inside my build.json file

{
 "android": {
     "release": {
         "keystore": "phistoKey.keystore",
         "storePassword": "",
         "alias": "phistoKey",
         "password" : "",
         "keystoreType": ""
     }
 }

}

when i try

cordova build --release

or

cordova build android --release

I get error stating

Keystore file does not exist: C:\wamp\www\towncrier\platforms\android\..\..\phistoKey.keystore

I will be glad if anyone can help cos I am on a deadline TODAY. thank you

David Addoteye
  • 1,587
  • 1
  • 19
  • 31
  • 1
    You need to generate the keystore file first and place that into the root directoroy of your Cordova project. – Android Noob Jun 30 '15 at 18:21
  • Possible duplicate of [how to create signed APK file using cordova command line interface](http://stackoverflow.com/questions/26449512/how-to-create-signed-apk-file-using-cordova-command-line-interface) – Midhun KM Aug 01 '16 at 04:16

3 Answers3

5

The way I do it in new Cordova CLI (with gradle) is using the options that cordova give us for doing it without make our own script or doing it manually in different steps. In my case, I have created a file in platforms/android directory, with the name release-signing.properties. The content of this should be the configuration for signing your apk, something like:

key.store=/PATH/TO/YOUR/KEYSTORE
key.alias=your_alias
key.store.password=key_store_pass
key.alias.password=key_store_alias

With this file created, you just need to run the standard command, cordova build android --release, and it will generate new release APK in your output directory (platforms/android/outputs/apk/yourapp-release.apk)

Juan Miguel S.
  • 591
  • 2
  • 11
  • 1
    your answer is about creating a file inside the /android folder, which is not recommended – Sartheris Stormhammer Mar 15 '17 at 08:32
  • What is in your opinion the best way for automating apk signing? I think it is the most simple and standard way (as the `release-signing.properties` is referenced in the `build.gradle` from [cordova lib](https://github.com/apache/cordova-android/blob/master/bin/templates/project/build.gradle). You can make a hook for putting this file from outside in android folder, for instance, if you don't want to modify directly this folder – Juan Miguel S. Mar 16 '17 at 10:32
  • because according to here - https://cordova.apache.org/docs/en/latest/guide/platforms/android/#setting-gradle-properties "The latter two options both involve including an extra file in your Android platform folder. In general, it is discouraged that you edit the contents of this folder because it is easy for those changes to be lost or overwritten." – Sartheris Stormhammer Mar 16 '17 at 13:59
  • I agree, _in general_. For us it is absolutely more confortable and faster to put this file inside android platform directory (without modifying any file from cordova, so it is not a problem unless you do `cordova platform rm android`; and allow us to avoid put in every release compilation the route via command line. From my point of view, if you don't feel confortable modifying anything inside `platforms/`, the best options is to create a hook for copying this file; as it describes [few lines after](https://cordova.apache.org/docs/en/latest/guide/platforms/android/#extending-buildgradle) – Juan Miguel S. Mar 21 '17 at 16:09
1

In cordova 6.2.0

cd cordova/ #change to root cordova folder
platforms/android/cordova/clean #clean if you want
cordova build android --release -- --keystore="/path/to/keystore" --storePassword=password --alias=alias_name #password will be prompted if you have any
Midhun KM
  • 1,647
  • 1
  • 21
  • 31
0

I do the following in a shell script to build and sign an APK. This assumes that the app is named "bongoapp" and that your Cordova project and keystore file (phistoKey.keystore) are located in the same folder as the shell script.

# Run this script in the bongoapp folder to build and sign a release APK.
# Hint: the password is "bongoapp"

# Build the release APK
echo "Building Android release APK"
cordova build android --release

# Sign the APK
echo "Signing Android release APK"
jarsigner -verbose -certs -sigalg SHA1withRSA -digestalg SHA1 -keystore phistoKey.keystore platforms/android/ant-build/MainActivity-release-unsigned.apk bongoapp_alias
jarsigner -verbose -certs -verify platforms/android/ant-build/MainActivity-release-unsigned.apk
zipalign -v 4 platforms/android/ant-build/MainActivity-release-unsigned.apk platforms/android/ant-build/bongoapp.apk

echo "Done, output file is located here -> platforms/android/ant-build/bongoapp.apk"
Mike Dailor
  • 1,226
  • 8
  • 16
  • thank you, to be honest i dont even know what shell is. I will be glade if you can break it down for me. thank you – David Addoteye Jun 25 '15 at 22:54
  • Ah, ok. Well, you could enter each of those commands individually on the command line every time you want to build a release APK, or you could put them in a file (a "shell script") and just invoke the script. Like running a batch file or a Powershell script, right? So put all of that in a file named "buildapk.sh", and then at the command prompt type "sh buildapk.sh". – Mike Dailor Jun 25 '15 at 23:35