android cordova app打包

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

参考: https://www.cnblogs.com/yuaima/p/5677923.html

打debug包

进入工程目录执行

 cordova build android

如果cordova环境配置正确了,会先下载一些安装包

可能会出现如下错误:

* What went wrong:

A problem occurred configuring project ':CordovaLib'.

> You have not accepted the license agreements of the following SDK components:

  [Android SDK Platform 27].

  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.

  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

 

因此尝试装下

Android SDK Build-Tools 27.0.3 (build-tools;27.0.3) 

安装完毕再次执行:

 cordova build android

测试包生成成功!!!

生成debug目录在:

/Users/wecloud/android-workspace/cordova-demo1/platforms/android/app/build/outputs/apk/debug/app-debug.apk

release 安装包:

cordova build android --release

release安装包生成成功

/Users/wecloud/android-workspace/cordova-demo1/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk

 

签名重点来了(前面一篇文章生成了appcan.keystore和对应的别名appcan)

jarsigner -verbose -sigalg SHA1 withRSA -digestalg SHA1 -keystore release-key.keystore /Users/wecloud/android-workspace/cordova-demo1/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk cordova-demo

这一步没有新的文件生成,只是改变了app-release-unsigned.apk内容,因此需要执行下一步,压缩apk

apk对齐处理(压缩和优化)

对签名后的.apk文件进行对齐处理,不进行对齐处理不能发布到Google Market(使用工具zipalign)

zipalign -v 4 /Users/wecloud/android-workspace/cordova-demo1/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk cordova-demo1.apk

如果提示zipalign找不到

因为我电脑里面装了android sdk 2个版本,因此需要指定一个版本的zipalign

/Users/wecloud/Library/Android/sdk/build-tools/27.0.3/zipalign

重新执行压缩命令:

/Users/wecloud/Library/Android/sdk/build-tools/27.0.3/zipalign -v 4 /Users/wecloud/android-workspace/cordova-demo1/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk cordova-demo1.apk

 

 

自动打包(cordova build --release)

 新建文件build.json

内容如下:

 

{
  "android": {
    "release": {
      "keystore": "release-key.keystore",
      "alias": "cordova-demo",
      "storePassword": "217891qqqq",
      "password": "217891qqqq"
    }
  }
}

 

 

 

 

转载于:https://my.oschina.net/thinkive/blog/2876927

你可能感兴趣的:(android cordova app打包)