Uni-app upgrade APP, including apk whole package upgrade and wgt application resource upgrade

Only Android applications are mentioned here, and the software package is placed on its own server.

Three ways

  • The apk package is updated for the whole package, all files must be downloaded including permission module dependencies, etc., the size is 20M+
  • Wgt package application resource update, only update the code written by yourself, according to the size of your code is about 600k
  • The wgtu application resource difference upgrade, only update the small part of the code that I wrote about 100k (the implementation is a bit complicated, not discussed here)

Scene description

If you change the App module configuration, permission configuration and other things in the mainifest.json, then you need to upgrade the whole package of the apk package. If you only change a bug in a certain place in the code, or add or remove modules, then only You need to update the application resource pack.

apk packaging

  • 1. After the code modification
  • 2. Modify the application version name and application version number in manifest.json
  • 3. Issue
  • 4. Cloud packaging

wgt packaging

  • 1. After the code modification
  • 2. Modify the application version name and application version number in manifest.json
  • 3. Issue
  • 4. Make application wgt package

Code

mdLoading is a prompt written by myself

// 获取最新版本信息
		getVersion() {
    
    
			let that = this;
			// #ifdef APP-PLUS
			uni.showLoading({
    
    
				title: '正在获取最新版本信息...'
			});
			//这里用setTimeout模拟请求
			setTimeout(() => {
    
    
				uni.hideLoading();
				let onLineVersion = 105;
				//这里通过请求接口判断版本
				// onLineVersion > plus.runtime.versionCode
				if (true) {
    
    
					uni.showModal({
    
    
						title: '发现新版本是否升级?',
						content: `
							1、新增个人信息模块
							2、新增版本信息模块
						`,
						success(res) {
    
    
							if (res.confirm) {
    
    
								that.content = '下载中...'
								that.$refs.mdLoading.show()
								let downloadTask = uni.downloadFile({
    
    
									// url: 'http://xxxxxx:8081/xxxxxx.wgt',
									//这个地址是请求后台接口返回的
									url:'http://xxxxxxxx:8081/xxxxxx.apk',
									success(downloadResult) {
    
    
										
										if (downloadResult.statusCode === 200) {
    
    
											that.content = '下载完成,安装中...'
											plus.runtime.install(
												downloadResult.tempFilePath,
												{
    
    
													force: true
												},
												function() {
    
    
													that.content = '应用更新完成稍后将重启应用'
													setTimeout(() => {
    
    
														that.$refs.mdLoading.hide()
														plus.runtime.restart();
													}, 1000);
												},
												function(e) {
    
    
													uni.showToast({
    
    
														icon: 'none',
														title: e
													});
												}
											);
										}else{
    
    
											that.content = '应用下载失败'
											that.$refs.mdLoading.hide()
										}
									},
									fail(e){
    
    
										that.content = e
										setTimeout(()=>{
    
    
											that.$refs.mdLoading.hide()
										},1000)
									}
								});
								
								// 监听下载进度
								downloadTask.onProgressUpdate((e)=>{
    
    
									that.content = '下载中...'+ e.progress + ' %';
								})
							}
						}
					});
				} else {
    
    
					uni.showToast({
    
    
						icon: 'none',
						title: '当前已经是最新版本'
					});
				}
			}, 1000);
			// #endif
		}

mdLoading file

<template>
	<view>
		<view v-show="visible" class="fy-loading flex justify-center">
			<view class="box flex flex-column align-center">
				<view class="loading">
					<image  src="/static/loading.gif"></image>
				</view>
				<view class="content">{
   
   {content}}</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	export default{
     
     
		name:'fy-loading',
		props:{
     
     
			content:{
     
     
				type:String,
				default:''
			}
		},
		data() {
     
     
			return {
     
     
				visible: false
			}
		},
		methods:{
     
     
			show(){
     
     
				this.visible = true;
			},
			hide(){
     
     
				this.visible = false;
			}
		}
	}
</script>

<style scoped lang="scss">
	.fy-loading{
     
     
		position: fixed;
		left:0;
		top:0;
		right:0;
		bottom:0;
		width:100vw;
		height: 100vh;
		z-index:100;
		background: rgba(0,0,0,0.6);
		overflow: hidden;
	}
	.box{
     
     
		width:100px;
		height: 70px;
		margin-top:30vh;
	}
	.content{
     
     
		color:#fff;
		font-size:14px;
		text-align:center;
		margin-top:10px;
	}
	.loading{
     
     
		width:40px;
		height: 40px;
	}
	.loading image{
     
     
		width:100%;
		height: 100%;
	}
</style>

Guess you like

Origin blog.csdn.net/weixin_35958891/article/details/108119852