yijianlianUI/bzy_build.sh

35 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 定义变量
PROJECT_DIR=$(pwd) # 当前项目根目录
OUTPUT_DIR="/Users/cyh/Documents/buildApp" # 自定义输出目录
FLAVORS=("11111" "182222" "182223" "182224" "182226" "182227" "182250" "182251" "182253" "182256" "182257" "182258") # 渠道列表
#FLAVORS=("11111" ) # 渠道列表
BUILD_TYPE="Release" # 构建类型Debug 或 Release
# 清理旧的构建产物
echo "清理旧的构建产物..."
./gradlew clean
# 创建输出目录
mkdir -p "${OUTPUT_DIR}"
# 遍历渠道列表并打包
for FLAVOR in "${FLAVORS[@]}"
do
echo "正在打包渠道: ${FLAVOR} (${BUILD_TYPE})..."
./gradlew assemble${FLAVOR}${BUILD_TYPE}
# 查找生成的 APK
FLAVOR_LOWER=$(echo "${FLAVOR}" | tr '[:upper:]' '[:lower:]')
BUILD_TYPE_LOWER=$(echo "${BUILD_TYPE}" | tr '[:upper:]' '[:lower:]')
APK_PATH=$(find "${PROJECT_DIR}/app/build/outputs/apk/${FLAVOR_LOWER}/${BUILD_TYPE_LOWER}" -name "*.apk" | head -n 1)
# 检查是否成功生成 APK
if [ -f "${APK_PATH}" ]; then
# 定义自定义输出文件名
cp "${APK_PATH}" "${OUTPUT_DIR}/"
else
echo "❌ 渠道 ${FLAVOR} 打包失败,未找到 APK 文件。"
fi
done
echo "所有渠道打包完成APK 文件存储在: ${OUTPUT_DIR}"