Christina Christina - 1 year ago 119
Android Question

Passing keystore password to Cordova Android through the command line

I have a Cordova project which I am trying to build for Android. I am using Cordova 5.3.3 and cordova-android 5.0.0. According to the documentation of Cordova Android found here in order for cordova to sign the release apk that it produces I need to pass to it the signing configuration, including the keystore password and key password. When I include this configuration in by build.json (which I pass to my cordova build command through the --buildConfig attribute) everything works as expected. Since however the build.json is committed to Git, and I would like for the keystore and key passwords to not be in there for everyone to read, I am trying to find another way to pass cordova these passwords. The documentation states that:

These parameters can be specified using the command line arguments
above to build or run scripts.

which leads me to believe that I could run the following build command to pass the password in the command line instead of including it in the build.json:

cordova build android --release --buildConfig cordova-config/build.json --password myPassword

This however fails with the following error:

Unknown platforms: myPassword

Am I misreading something in the documentation or is this an issue with the version of cordova-android that I'm using?

Answer Source

This is the command:

 cordova build android --release --keystore=pathToKeystore --storePassword=kspassword --alias=aliasName --password=aliasPassword

But there is a bug and it doesn't work

If you update the project to cordova android 5.1.0 and replace the platforms/android/cordova/lib/build.js with this code it will work (It might work with cordova android 5.0.0, but didn't test)

Another options are not to commit the build.json, or don't set the passwords, if you don't provide passwords on the build.json you will be promted to enter them manually

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download