android studio本地打包后,无法热更,无法执行换包操作,plus.runtime.install没有弹窗
要解决这个问题我们首先要按顺序排查
1.检查安装代码是否正常,下面是一个热更安装进度页面的demo,可以参照一下
<template>
<view>
<view class="progress-box">
<progress :percent="progress" show-info stroke-width="8" activeColor="#10B96F" />
</view>
</view>
</template>
<script>
export default {
data() {
return {
progress:''
}
},
onBackPress(event){
console.log(event)
if(event.from=='backbutton'){
return true
}
},
onLoad(options) {//在这里传入你热更的资源全路径
console.log(options)
const down = uni.downloadFile({
url: options.upurl,
success: (downloadResult) => {
console.log(downloadResult)
if (downloadResult.statusCode === 200) {
plus.runtime.install(downloadResult.tempFilePath, {
force: false
}, function() {
console.log('安装成功');
plus.runtime.restart();
}, function() {
console.error('安装失败');
});
}
}
})
down.onProgressUpdate((res) => {
this.progress = res.progress +'%'
// console.log('已下载' + res.progress +'%');
console.log(this.progress)
});
},
methods: {
}
}
</script>
<style>
.progress-box progress{
width: 70%;
height: 50%;
/* background: #000; */
overflow: auto;
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
</style>
这里是换包代码区域
updata() {
let that = this
console.log(this.apkValue);
// #ifdef APP-PLUS
if (this.apkValue) {
uni.showLoading({
title: '正在下载安装包,请耐心等待',
mask: true,
})
const downloadTask = uni.downloadFile({
url: this.apkValue, //资源包网络路径
success: (result) => {
if (result.statusCode == 200) {
uni.hideLoading();
uni.showToast({
title: '安装包下载成功,即将安装',
icon: 'none',
mask: true,
duration: 1000,
})
plus.runtime.install(result.tempFilePath, {
force: true
}, function(success) {
console.log("success");
that.install = success
plus.runtime.restart();
}, function(e) {
that.install = e.message
console.log("failed: " + e.message);
})
} else {
uni.showToast({
title: '安装包下载失败,请联系管理员',
icon: 'none',
mask: true,
duration: 1000,
})
}
}
})
} else {
uni.showToast({
title: '无法获取安装包',
icon: 'error',
mask: true,
duration: 1000,
})
}
// #endif
},
2.检查manifest.json中的权限是否添加完整
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"/>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.INSTALL_SHORTCUT"/>
3.检查android studio打包配置权限代码是否完整
看AndroidManifest.xml的manifest下面是否有install相关的权限
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
再看build.gradle下是否将targetSdkVersion提升到26
再看simpleDemo中是否含有 install-apk-release.aar 文件