#!/bin/bash

#当前执行目录
current_dir=$(pwd)
channelPath="$current_dir/build/app/outputs/apk/dev"
mkdir -p "$channelPath"
rm -rf "$channelPath"/*
#定义环境变量和 Android 设备品牌
declare -a APP_CHANNELS=("dev")

# 遍历每个环境配置并执行构建
for index in "${APP_CHANNELS[@]}"; do
    ENV=${APP_CHANNELS[$index]}
    flutter build apk -Penv=dev -Pchannel=$ENV --dart-define=ENV=dev
    # 检查构建是否成功
    if [ $? -ne 0 ]; then
        echo "Build failed for ENV=$ENV"
        exit 1
    fi
   apkFile=$(find $(pwd)/build/app/outputs/apk/release/ -name "*.apk" -print -quit)
   # 获取 .apk 文件的文件名
   apkFileName=$(basename "$apkFile")
   mv $apkFile "$channelPath/$apkFileName"
done

echo "All builds completed successfully."
