android studio本地打包后,无法热更,无法执行换包操作,plus.runtime.install没有弹窗

要解决这个问题我们首先要按顺序排查

1.检查安装代码是否正常,下面是一个热更安装进度页面的demo,可以参照一下

javascript 复制代码
<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>

这里是换包代码区域

javascript 复制代码
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中的权限是否添加完整

java 复制代码
<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相关的权限

java 复制代码
 <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 文件

相关推荐
Gary jie几秒前
OpenClaw启动日志详细分析
前端·chrome
择势5 分钟前
macOS App 签名与公证流程详解及一键自动化
前端
英俊潇洒美少年17 分钟前
Vue3 中 watch的 flush 选项(默认无/`post`/`sync`)的区别
前端·javascript·vue.js
闲云一鹤20 分钟前
Python 入门(三)- PyAutoGUI 自动化教程
前端·python·黑客
D_C_tyu22 分钟前
HTML | 结合Canvas开发具有智能寻路功能的贪吃蛇小游戏实战详解
javascript·算法·游戏·html·bfs
Jay-r25 分钟前
樱花雨特效 WebGL实现 短视频同款浪漫视觉效果(附源码下载)
开发语言·javascript·ecmascript·编程·webgl·代码·樱花雨
凤山老林26 分钟前
Js如何实现一个抽奖程序
前端·javascript·vue.js
我命由我1234527 分钟前
React - Switch、路由精准匹配与模糊匹配、Redirect
开发语言·前端·javascript·react.js·前端框架·html·ecmascript
圆粥綠31 分钟前
Android 四大常用布局介绍和示例
android studio
陆枫Larry34 分钟前
用 Git 别名(Alias)简化日常操作
前端