简体   繁体   English

通过命令行将密钥库密码传递给Cordova Android

[英]Passing keystore password to Cordova Android through the command line

I have a Cordova project which I am trying to build for Android. 我有一个Cordova项目,我正在尝试为Android构建。 I am using Cordova 5.3.3 and cordova-android 5.0.0. 我正在使用Cordova 5.3.3和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. 根据此处找到的Cordova Android文档,为了使cordova对其生成的发行版apk进行签名,我需要将签名配置(包括密钥库密码和密钥密码)传递给它。 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. 当我在build.json中包含此配置时(通过--buildConfig属性将其传递给我的cordova build命令),一切都会按预期进行。 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. 但是,由于build.json已提交给Git,并且我希望密钥库和密钥密码不存在于每个人都可以阅读的地方,因此,我试图找到另一种方式来传递Cordova这些密码。 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: 这使我相信我可以运行以下build命令以在命令行中传递密码,而不是将其包含在build.json中:

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

This however fails with the following error: 但是,此操作失败,并显示以下错误:

Unknown platforms: myPassword 未知平台:myPassword

Am I misreading something in the documentation or is this an issue with the version of cordova-android that I'm using? 我是不是在阅读文档中的内容,或者这是我使用的cordova-android版本的问题?

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) 如果您将项目更新到cordova android 5.1.0并用此代码替换platform / android / cordova / lib / build.js,它将正常工作(它可能在cordova android 5.0.0上有效,但未测试)

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 另一个选择是不提交build.json或不设置密码,如果您未在build.json上提供密码,则系统会提示您手动输入密码

You are missing a double dash, should be: 您缺少双破折号,应为:

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

See https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#signing-an-app 参见https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#signing-an-app

Note: You should use double -- to indicate that these are platform-specific arguments, for example: 注意:您应该使用double-表示这些是特定于平台的参数,例如:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM