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 文件

相关推荐
RainbowSea21 分钟前
NVM 切换 Node 版本工具的超详细安装说明
java·前端
读书点滴26 分钟前
笨方法学python -练习14
java·前端·python
Mintopia33 分钟前
四叉树:二维空间的 “智能分区管理员”
前端·javascript·计算机图形学
慌糖37 分钟前
RabbitMQ:消息队列的轻量级王者
开发语言·javascript·ecmascript
Mintopia43 分钟前
Three.js 深度冲突:当像素在 Z 轴上玩起 "挤地铁" 游戏
前端·javascript·three.js
Penk是个码农1 小时前
web前端面试-- MVC、MVP、MVVM 架构模式对比
前端·面试·mvc
MrSkye1 小时前
🔥JavaScript 入门必知:代码如何运行、变量提升与 let/const🔥
前端·javascript·面试
白瓷梅子汤1 小时前
跟着官方示例学习 @tanStack-form --- Linked Fields
前端·react.js
爱学习的茄子1 小时前
深入理解JavaScript闭包:从入门到精通的实战指南
前端·javascript·面试
zhanshuo2 小时前
不依赖框架,如何用 JS 实现一个完整的前端路由系统
前端·javascript·html