Hbuild 打包apk遇到的坑

377 阅读1分钟

新建项目

网上的大多数资料都hbuild,现在官方版本是HbuildX。先新建一个H5+的项目

image

生成后的目录结构

  1. unpackage是用来放图片的
  2. inex 是vue的页面
  3. mainfest.json是关于打包的一些配置

image

关于mainfest.json的配置

可以看这个博主写的 很详情: www.cnblogs.com/taohuaya/p/…

点击按钮自动更新软件

// 将这行代码放到index.html中,放在vue的mouted和created中会报错。有大神弄好可以告诉下
## inde.html
<script>
    // 用来做安卓版本更新
    document.addEventListener(
      "plusready",
      function() {
        console.log(JSON.stringify("121212"));
      },
      false
    );
  </script>
// 点击升级按钮

// 运行的时候plus 一定要ready不然会报错
## home.vue
 versionUP() {
      let  ver ='1.0.1';
      plus.runtime.getProperty(plus.runtime.appid, function(inf) {
        // hbuild自带的全局弹窗方法
        plus.nativeUI.showWaiting("下载中...");
        if (
          +inf.version.slice(".").replace(/\./g, "") < +ver.replace(/\./g, "")
        ) {
          // plus.nativeUI.toast("正在准备环境,请稍后!");
          var dtask = plus.downloader.createDownload(
            "https://files.sumi.io/grid-diary-china-latest.apk",
            {},
            function(d, status) {
              plus.nativeUI.closeWaiting();
              if (status == 200) {
                var path = d.filename; //下载apk
                plus.runtime.install(path); // 自动安装apk文件
              } else {
                plus.nativeUI.alert("版本更新失败:" + status);
              }
            }
          );
          dtask.start();
        }
      });
    },

H5+:的文档 www.dcloud.io/docs/api/

遇到的坑

  1. console.log(JSON.stringify("121212"));打印的时候一定要这样,不要问我怎么知道的都是坑
  2. 遇到打包后白屏:
  • 需要将配置文件中 / 改为 ./image.png
  1. 将模式router模式改为hash

调试

image.png