cordova H5打包APK关键几点记录
朋友有个vue开发的h5应用,需要打包一个app
我帮看了几个解决方案,最终采用了cordova进行打包,已经发布了几个版本,效果不错,关键的几个地方在以下做个记录
https://www.zhyd.me/article/76
https://blog.csdn.net/weixin_42325228/article/details/107794469
插件安装
cordova plugin add cordova-plugin-x-toast
cordova plugin add cordova-plugin-splashscreen
兼容多平台图标处理插件,借助这个插件可以根据一个大图生成不图尺寸设备的小图,自己不需要一个个PS图标图片
ionic cordova resources --cordova-res
index.html 加入以下脚本,用于按两次返回退出
<script src=cordova.js></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load //
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
function onBackKeyDown() {
window.plugins.toast.showLongCenter('再按一次退出', function(a){console.log('toast success: ' + a)}, function(b){alert('toast error: ' + b)})
document.removeEventListener("backbutton", onBackKeyDown, false); // 注销返回键
document.addEventListener("backbutton", exitApp, false);//绑定退出事件
// 3秒后重新注册
var intervalID = window.setInterval(function() {
window.clearInterval(intervalID);
document.removeEventListener("backbutton", exitApp, false); // 注销返回键
document.addEventListener("backbutton", onBackKeyDown, false); // 返回键
}, 3000);
}
function exitApp(){
navigator.app.exitApp();
}
</script>
打包
cordova build --release android
cordova build android
签名apk
jarsigner -verbose -keystore name.keystore -signedjar youtui.apk app-release-unsigned.apk name.keystore
高版本权限问题解决,高版本的android机器不能直接http访问接口
https://www.cnblogs.com/muzhe/articles/13213047.html
https://www.cnblogs.com/lyxy/p/6909759.html
https://blog.csdn.net/zhongqinrusi/article/details/89146857