cordova android通过更新链接下载安装新版本的app之后,打开安装的新包闪退?

cordova android通过更新链接下载安装新版本的app之后,打开闪退。但是在手机应用清除了数据之后,闪退的APP就可以正常打开,是什么问题呢?是否和config.xml 的配置有关?

js下载安装包逻辑,

const successCallback = (entry: any) => {
  cordova.plugins.fileOpener2.open(entry.toURL(), 'application/vnd.android.package-archive', {
    error: () => {
      showToast(`打开失败,文件路径:${entry.toURL()}`);
    },
    success: () => {
      entryToUrl.value = entry.toURL();
    }
  });
};

// 更新按钮点击
const downloadNewAppVersion = () => {
  const uri = encodeURI(props.versionInfo.downloadLink); // 下载链接
  if (isIOS) return openInappBrowser(uri, '_system'); // ios跳转appStore
  if (!window.FileTransfer) return;
  // 如果下载过了,再次下载直接打开
  if (entryToUrl.value) {
    successCallback({ toURL: () => entryToUrl.value });
    return;
  }

  fileTransfer.value = new window.FileTransfer();
  const fileURL = 'cdvfile://localhost/temporary/update.apk';
  fileTransfer.value.onprogress = (e: any) => {
    if (e.lengthComputable) {
      const progress = Math.ceil((e.loaded / e.total) * 100);
      percentage.value = progress;
    }
  };

  fileTransfer.value.download(uri, fileURL, successCallback, errorCallback);
};

cordova config.xml 配置

<?xml version='1.0' encoding='utf-8'?>
<widget id="xx.xx.xx.xx" version="1.3.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name short="App">App</name>
    <description>描述信息</description>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="tel:*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-navigation href="*" />
    <allow-navigation href="http://*/*" />
    <allow-navigation href="https://*/*" />
    <allow-navigation href="data:*" />
    <platform name="android">
        <allow-intent href="market:*"/>
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
        <preference name="StatusBarOverlaysWebView" value="false" />
        <preference name="StatusBarStyle" value="lightcontent" />
        <preference name="SplashDialogHide" value="true" />
        <preference name="StatusBarLightMode" value="true" />
        <preference name="SplashScreenHide" value="false" />
    </platform>
    <preference name="AppendUserAgent" value="lapp" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000"/>
    <preference name="SplashMaintainAspectRatio" value="true" /> 
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="AutoHideSplashScreen" value="false" />
    <preference name="FadeSplashScreen" value="false" />
    <preference name="FadeSplashScreenDuration" value="1000"/>
</widget>

cordova requirements android

image.png
android版本是cordova-android@8.0.0

package.json 相关依赖版本

{
    "devDependencies": {
        "cordova-android": "^8.0.0",
        "cordova-plugin-file": "^6.0.2",
        "cordova-plugin-file-opener2": "^3.0.5",
        "cordova-plugin-file-transfer": "^1.7.1",
    }
}

由于不太懂安卓缓存和本地数据的问题,希望大神不吝赐教。

虽然安装新的apk之后,会闪退。但是在手机设置-应用-应用详情-清除存储数据之后就可以正常打开闪退的app。可能和缓存数据之类的问题有关,但无从下手。

阅读 335
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏