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

相关推荐
美酒没故事°31 分钟前
vue3拖拽+粘贴的综合上传器
前端·javascript·typescript
jingling5552 小时前
css进阶 | 实现罐子中的水流搅拌效果
前端·css
悟能不能悟3 小时前
前端上载文件时,上载多个文件,但是一个一个调用接口,怎么实现
前端
可问春风_ren4 小时前
前端文件上传详细解析
前端·ecmascript·reactjs·js
羊小猪~~4 小时前
【QT】--文件操作
前端·数据库·c++·后端·qt·qt6.3
晚风资源组5 小时前
CSS文字和图片在容器内垂直居中的简单方法
前端·css·css3
Miketutu6 小时前
Flutter学习 - 组件通信与网络请求Dio
开发语言·前端·javascript
摘星编程6 小时前
React Native for OpenHarmony 实战:Swiper 滑动组件详解
javascript·react native·react.js
鸣弦artha6 小时前
Flutter框架跨平台鸿蒙开发——Build流程深度解析
开发语言·javascript·flutter
光影少年7 小时前
前端如何调用gpu渲染,提升gpu渲染
前端·aigc·web·ai编程