编写expect脚本一条龙完成cordova应用安卓版的发布和签名

平时用cordova发布安卓应用,要运行三条命令,中间还要输一次签名密码,稍有点麻烦,由于测试版的发布很频繁,我决定用刚学的expect写个脚本

原来要手动执行的命令:

//build
$ cordova build --release android

//sign
jarsigner -verbose -keystore com.dpdoctor.keystore -signedjar dianyi_signed.apk -digestalg SHA1 -sigalg MD5withRSA ./platforms/android/build/outputs/apk/android-release-unsigned.apk com.dpdoctor

//中间还要输一次密码

//rename
mv dianyi_signed.apk dianyi-2.0.0.apk

自动化方案一

#!/usr/bin/expect -f
set password "xxxxxx"
set apkver [lindex $argv 0]
set timeout -1
spawn cordova build --release android
expect "]# "
spawn jarsigner -verbose -keystore com.dpdoctor.keystore -signedjar dianyi_signed.apk -digestalg SHA1 -sigalg MD5withRSA ./platforms/android/build/outputs/apk/android-release-unsigned.apk com.dpdoctor
expect "*密码短语*"
send "$password\r"
expect "]# "
spawn mv dianyi_signed.apk dianyi-$apkver.apk
expect eof

保存脚本makeandroid.sh并授以执行权限

以后只需执行makeandroid 版本号即可完成发布+签名+改名

如果你不想把密码写到脚本中,可参考以下方案

自动化方案二

#!/usr/bin/expect -f
set password [lindex $argv 0]
set apkver [lindex $argv 1]
set timeout -1
spawn cordova build --release android
expect "]# "
spawn jarsigner -verbose -keystore com.dpdoctor.keystore -signedjar dianyi_signed.apk -digestalg SHA1 -sigalg MD5withRSA ./platforms/android/build/outputs/apk/android-release-unsigned.apk com.dpdoctor
expect "*密码短语*"
send "$password\r"
expect "]# "
spawn mv dianyi_signed.apk dianyi-$apkver.apk
expect eof

保存脚本makeandroid.sh并授以执行权限

以后只需执行makeandroid 签名密码 版本号即可完成发布+签名+改名

若您觉得我的博文对您有帮助,欢迎点击下方按钮对我打赏
打赏