rokevin
移动
前端
语言
  • 基础

    • Linux
    • 实施
    • 版本构建
  • 应用

    • WEB服务器
    • 数据库
  • 资讯

    • 工具
    • 部署
开放平台
产品设计
  • 人工智能
  • 云计算
计算机
其它
GitHub
移动
前端
语言
  • 基础

    • Linux
    • 实施
    • 版本构建
  • 应用

    • WEB服务器
    • 数据库
  • 资讯

    • 工具
    • 部署
开放平台
产品设计
  • 人工智能
  • 云计算
计算机
其它
GitHub
  • app打包脚本

app打包脚本

编译、打包、签名、上传到fir的脚本

脚本

 #!/bin/sh
 # -------------------------------------------------------------------------------
 # Description: 打包apk并上传fir的脚本
 # -------------------------------------------------------------------------------
 # buildType: release|test|dev
 # 使用说明:
 # 正式环境:./build_upload_apk.sh release -m "xx"
 # 测试环境:./build_upload_apk.sh test -m "xx"
 # 开发环境:./build_upload_apk.sh dev -m "xx"
 # -------------------------------------------------------------------------------
 
 # 当前目录
 current_dir=$(pwd)
 echo "当前目录:" + ${current_dir}
 
 # 环境 默认为dev
 build_type=$1
 shift
 	while getopts "m:" opt
 	do
 	  case $opt in
 	  m)
 	     message="2. "$OPTARG;
 	  esac
 	done
 
 if [ ! -n "$1" ] ;then
     build_type="dev"
 fi
 
 # Gradle版本
 gradle_version() {
 	echo "------------------------------------------------------------"
 	echo "Gradlew Version"
 	echo "------------------------------------------------------------"
 	./gradlew -v
 }
 
 # Gradle清空缓存
 clean_project() {
 	echo "------------------------------------------------------------"
 	echo "Gradlew Clean Project"
 	echo "------------------------------------------------------------"
 	./gradlew clean
 }
 
 # 开始打包
 build() {
 	echo "------------------------------------------------------------"
 	echo "Gradlew Build Project"
 	echo "------------------------------------------------------------"
 	if [[ ${build_type} == "release" ]]; then
 		# 正式环境
 		unsigned_apk_file=${current_dir}/app/build/outputs/apk/app-release-unsigned.apk
         signed_apk_file=${current_dir}/app/build/outputs/apk/app-release-signed.apk
 		./gradlew assembleRelease
 	elif [[ ${build_type} == "test" ]]; then
 		# 测试环境
 		unsigned_apk_file=${current_dir}/app/build/outputs/apk/app-beta-unsigned.apk
         signed_apk_file=${current_dir}/app/build/outputs/apk/app-beta-signed.apk
 		./gradlew assembleBeta
 	else
 		# 开发环境
 		unsigned_apk_file=${current_dir}/app/build/outputs/apk/app-debug.apk
         signed_apk_file=${current_dir}/app/build/outputs/apk/app-debug-signed.apk
 		./gradlew assembleDebug
 	fi
 
 	if [ $? -ne 0 ];
 		then
 		echo "编译失败"
 		exit 1
 	fi
 }
 
 # 签名
 sign() {
 	echo "------------------------------------------------------------"
 	echo "开始签名"
 	echo "------------------------------------------------------------"
 	keystore_file=${current_dir}/******.jks
 	keystore_pwd="******"
 	key_alias="******"
 	key_pwd=${keystore_pwd}
 	echo "Keystore File Path: " + ${keystore_file}
 	echo "Signed Apk File Path: " + ${signed_apk_file}
 	echo "Unsigned Apk File Path: " + ${unsigned_apk_file}
 	jarsigner -verbose -keystore ${keystore_file} -signedjar ${signed_apk_file} ${unsigned_apk_file} ${key_alias} -keypass ${key_pwd} -storepass ${keystore_pwd} -tsa http://sha256timestamp.ws.symantec.com/sha256/timestamp
 
 	if [ $? -ne 0 ];
 		then
 		echo "签名失败"
 		exit 1
 	fi
 }
 
 # 上传
 upload() {
 
 	if [[ ${build_type} == "release" ]]; then
 		# 正式环境
 		apk_file_path=${signed_apk_file}
 		evn="1. 正式环境<br>"
 	elif [[ ${build_type} == "test" ]]; then
 		# 测试环境
 		apk_file_path=${signed_apk_file}
 		evn="1. 测试环境<br>"
 	else
 		# 开发环境
 		apk_file_path=${signed_apk_file}
 		evn="1. 开发环境<br>"
 	fi
 
     # 如果要换行参数中加入\n
     commit_message=${evn}${message}
 
     echo "\n"
     echo "更新信息:\n"
     echo ${commit_message}\n
     echo "\n"
 
 	echo "------------------------------------------------------------"
 	echo ${apk_file_path}
 	echo "开始上传"
 	echo "------------------------------------------------------------"
 	fir publish ${apk_file_path} -c ${commit_message} -T "8e37afbf033f523daf8376d50c******"
 }
 
 # 输出Gradle版本号
 gradle_version
 
 # clean
 clean_project
 
 # 打包
 build
 
 # test和release都签名
 #if [[ ${build_type} != "dev" ]]; then
 #	sign
 #fi
 
 # 签名
 sign
 
 # 上传fir
 upload
最近更新:: 2025/10/22 15:36
Contributors: luokaiwen