问题:Android原生集成Uni小程序更新wgt包后首次打開小程序出现无法打开的页面 如图:
产生原因: 具体原因不详,可能是因为小程序manifest.json文件有一个hashCode对应,当修改manifest.json文件中version.code 后 对应的hasCodde值没有来得及改变 找不到对应的文件。所以报错。
解决方法 再App 启动的时候判断是否更新小程序,如果更新了 将packagename/files/apps/__UNI__C0AADD1 目录及文件全部删除。
代码如下:
private void handleUniAppUpgrade() throws IOException {
Context context = this;
Gson gson = new Gson();
String uniAppManifestContent = IOUtils.toString( context.getAssets().open("apps/__UNI__C0AADD1/www/manifest.json"));
JsonObject uniAppManifestJsonObject = gson.fromJson(uniAppManifestContent, JsonObject.class);
JsonObject version = uniAppManifestJsonObject.get("version").getAsJsonObject();
String currentName= version.get("name").getAsString();
String currentCode= version.get("code").getAsString();
String spName = SPUtils.getInstance().getString("uni_app_version_name");
String spCode = SPUtils.getInstance().getString("uni_app_version_code");
if (spName.equals(currentName) && spCode.equals(currentCode)) {
return;
}
SPUtils.getInstance().put("uni_app_version_name",currentName);
SPUtils.getInstance().put("uni_app_version_code",currentCode);
File uniAppCacheDir = new File(new File(context.getFilesDir(), "apps"), BuildConfig.UNI_APP_ID);
FileUtils.deleteDirectory(uniAppCacheDir);
}