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