[Windows][Android] Rework flutter build helpers
This commit is contained in:
@@ -1,26 +1,97 @@
|
||||
$buildType = if ($args[0]) { $args[0] } else { "release" }
|
||||
$buildName = if ($args[1]) { $args[1] } else { "0.0.0" }
|
||||
$buildNumber = "$buildName-$(Get-Date -Format 'yyyyMMddHHmmss')"
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Builds a Flutter APK with versioning support.
|
||||
|
||||
.DESCRIPTION
|
||||
This script builds a Flutter APK, manages build numbers, and renames output files.
|
||||
|
||||
.PARAMETER buildType
|
||||
The build type (release or debug). Default is "release".
|
||||
|
||||
.PARAMETER buildName
|
||||
The build name (version). Default is "0.0.0".
|
||||
|
||||
.EXAMPLE
|
||||
.\flutter-build-apk.ps1 -buildType debug -buildName 1.0.0
|
||||
Builds a debug APK with version 1.0.0.
|
||||
|
||||
.EXAMPLE
|
||||
.\flutter-build-apk.ps1 -Help
|
||||
Displays this help message.
|
||||
#>
|
||||
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string]$buildType = "release", # Default value is "release"
|
||||
[string]$buildName = "0.0.0" # Default value is "0.0.0"
|
||||
)
|
||||
|
||||
$buildsRef = "builds.json"
|
||||
|
||||
# Check if the file exists
|
||||
if (-not (Test-Path -Path $buildsRef)) {
|
||||
# Create the file if it doesn't exist
|
||||
New-Item -Path $buildsRef -ItemType File
|
||||
$buildsMap = @{
|
||||
$buildName = 0
|
||||
}
|
||||
$buildsMap | ConvertTo-Json | Out-File $buildsRef
|
||||
Write-Output "File created: $buildsRef"
|
||||
} else {
|
||||
Write-Output "File already exists: $buildsRef"
|
||||
}
|
||||
|
||||
# Read the JSON file and convert it to a hashtable
|
||||
$jsonContent = Get-Content $buildsRef -Raw | ConvertFrom-Json
|
||||
$buildsMap = @{}
|
||||
$jsonContent.PSObject.Properties | ForEach-Object {
|
||||
$buildsMap[$_.Name] = $_.Value
|
||||
}
|
||||
|
||||
if ($buildsMap.ContainsKey($buildName)) {
|
||||
Write-Output "Build exists: $buildName"
|
||||
$buildNumber = $buildsMap[$buildName]
|
||||
$buildNumber++
|
||||
Write-Output "Next build number for ${buildName}: $buildNumber"
|
||||
$buildsMap[$buildName] = $buildNumber
|
||||
}
|
||||
else {
|
||||
$buildsMap[$buildName] = 1
|
||||
}
|
||||
|
||||
$buildsMap | ConvertTo-Json | Out-File $buildsRef
|
||||
|
||||
|
||||
$apkDir = "..\build\app\outputs\flutter-apk"
|
||||
$baseName = "org.igox.apps.android.busylight-buddy"
|
||||
|
||||
flutter build apk --$buildType --build-name=${buildName} --build-number ${buildNumber} --target-platform android-arm,android-arm64,android-x64
|
||||
# Build APK using an array for arguments
|
||||
$flutterArgs = @(
|
||||
"--$buildType",
|
||||
"--build-name=$buildName",
|
||||
"--build-number=$buildNumber",
|
||||
"--target-platform=android-arm,android-arm64,android-x64"
|
||||
)
|
||||
|
||||
Write-Output "Building APK with arguments: $($flutterArgs -join ' ')"
|
||||
|
||||
& flutter build apk @flutterArgs
|
||||
|
||||
# Rename APK
|
||||
$oldApk = "$apkDir\app-$buildType.apk"
|
||||
$newApk = "$apkDir\$baseName-$buildType.apk"
|
||||
$oldApk = "$apkDir\app-${buildType}.apk"
|
||||
$newApk = "$apkDir\$baseName-${buildType}.apk"
|
||||
if (Test-Path $oldApk) {
|
||||
if (Test-Path $newApk) { Remove-Item $newApk -Force }
|
||||
Rename-Item -Path $oldApk -NewName "$baseName-$buildType.apk"
|
||||
Write-Host "APK renamed to: $baseName-$buildType.apk"
|
||||
Rename-Item -Path $oldApk -NewName "$baseName-${buildType}.apk"
|
||||
Write-Host "APK renamed to: $baseName-${buildType}.apk"
|
||||
}
|
||||
|
||||
# Rename SHA1 (if exists)
|
||||
$oldSha1 = "$apkDir\app-$buildType.apk.sha1"
|
||||
$newSha1 = "$apkDir\$baseName-$buildType.apk.sha1"
|
||||
$oldSha1 = "$apkDir\app-${buildType}.apk.sha1"
|
||||
$newSha1 = "$apkDir\$baseName-${buildType}.apk.sha1"
|
||||
if (Test-Path $oldSha1) {
|
||||
if (Test-Path $newSha1) { Remove-Item $newSha1 -Force }
|
||||
Rename-Item -Path $oldSha1 -NewName "$baseName-$buildType.apk.sha1"
|
||||
Write-Host "SHA1 renamed to: $baseName-$buildType.apk.sha1"
|
||||
Rename-Item -Path $oldSha1 -NewName "$baseName-${buildType}.apk.sha1"
|
||||
Write-Host "SHA1 renamed to: $baseName-${buildType}.apk.sha1"
|
||||
}
|
||||
@@ -1,28 +1,90 @@
|
||||
#!/bin/bash
|
||||
BUILD_TYPE=${1:-release}
|
||||
BUILD_NAME=${2:-0.0.0}
|
||||
BUILD_NUMBER="$BUILD_NAME-$(date +%Y%m%d%H%M%S)"
|
||||
|
||||
# Default values
|
||||
buildType="release"
|
||||
buildName="0.0.0"
|
||||
buildsRef="builds.json"
|
||||
|
||||
APK_DIR="../build/app/outputs/flutter-apk"
|
||||
BASE_NAME="org.igox.apps.android.busylight-buddy"
|
||||
# Help message
|
||||
show_help() {
|
||||
echo "Usage: $0 [-t buildType] [-n buildName]"
|
||||
echo "Builds a Flutter APK with versioning support."
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -t, --buildType Build type (release or debug). Default: release"
|
||||
echo " -n, --buildName Build name (version). Default: 0.0.0"
|
||||
echo " -h, --help Show this help message"
|
||||
exit 0
|
||||
}
|
||||
|
||||
flutter build apk --$BUILD_TYPE --build-name=$BUILD_NAME --build-number=$BUILD_NUMBER --target-platform android-arm,android-arm64,android-x64
|
||||
# Parse command-line arguments
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
case $1 in
|
||||
-t|--buildType) buildType="$2"; shift ;;
|
||||
-n|--buildName) buildName="$2"; shift ;;
|
||||
-h|--help) show_help ;;
|
||||
*) echo "Unknown parameter: $1"; show_help; exit 1 ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Check if builds.json exists
|
||||
if [ ! -f "$buildsRef" ]; then
|
||||
echo "File created: $buildsRef"
|
||||
echo "{\"$buildName\": 0}" > "$buildsRef"
|
||||
else
|
||||
echo "File already exists: $buildsRef"
|
||||
fi
|
||||
|
||||
# Read the JSON file
|
||||
buildsMap=$(cat "$buildsRef")
|
||||
|
||||
# Check if buildName exists in the JSON
|
||||
if jq -e --arg key "$buildName" 'has($key)' <<< "$buildsMap" > /dev/null; then
|
||||
echo "Build exists: $buildName"
|
||||
buildNumber=$(jq --arg key "$buildName" '.[$key]' <<< "$buildsMap")
|
||||
buildNumber=$((buildNumber + 1))
|
||||
echo "Next build number for $buildName: $buildNumber"
|
||||
buildsMap=$(jq --arg key "$buildName" --argjson value "$buildNumber" '.[$key] = $value' <<< "$buildsMap")
|
||||
else
|
||||
echo "New build: $buildName, starting at build number: 1"
|
||||
buildNumber=1
|
||||
buildsMap=$(jq --arg key "$buildName" --argjson value "$buildNumber" '.[$key] = $value' <<< "$buildsMap")
|
||||
fi
|
||||
|
||||
# Save the updated JSON back to the file
|
||||
echo "$buildsMap" > "$buildsRef"
|
||||
|
||||
# Define paths
|
||||
apkDir="../build/app/outputs/flutter-apk"
|
||||
baseName="org.igox.apps.android.busylight-buddy"
|
||||
|
||||
# Build APK
|
||||
echo "Building APK with arguments: --$buildType --build-name=$buildName --build-number=$buildNumber --target-platform=android-arm,android-arm64,android-x64"
|
||||
flutter build apk --"$buildType" --build-name="$buildName" --build-number="$buildNumber" --target-platform=android-arm,android-arm64,android-x64
|
||||
|
||||
# Rename APK
|
||||
OLD_APK="$APK_DIR/app-$BUILD_TYPE.apk"
|
||||
NEW_APK="$APK_DIR/$BASE_NAME-$BUILD_TYPE.apk"
|
||||
if [ -f "$OLD_APK" ]; then
|
||||
[ -f "$NEW_APK" ] && rm -f "$NEW_APK"
|
||||
mv "$OLD_APK" "$NEW_APK"
|
||||
echo "APK renamed to: $BASE_NAME-$BUILD_TYPE.apk"
|
||||
oldApk="$apkDir/app-$buildType.apk"
|
||||
newApk="$apkDir/$baseName-$buildType.apk"
|
||||
if [ -f "$oldApk" ]; then
|
||||
if [ -f "$newApk" ]; then
|
||||
rm -f "$newApk"
|
||||
fi
|
||||
mv "$oldApk" "$newApk"
|
||||
echo "APK renamed to: $baseName-$buildType.apk"
|
||||
else
|
||||
echo "Warning: APK not found at $oldApk"
|
||||
fi
|
||||
|
||||
# Rename SHA1 (if exists)
|
||||
OLD_SHA1="$APK_DIR/app-$BUILD_TYPE.apk.sha1"
|
||||
NEW_SHA1="$APK_DIR/$BASE_NAME-$BUILD_TYPE.apk.sha1"
|
||||
if [ -f "$OLD_SHA1" ]; then
|
||||
[ -f "$NEW_SHA1" ] && rm -f "$NEW_SHA1"
|
||||
mv "$OLD_SHA1" "$NEW_SHA1"
|
||||
echo "SHA1 renamed to: $BASE_NAME-$BUILD_TYPE.apk.sha1"
|
||||
oldSha1="$apkDir/app-$buildType.apk.sha1"
|
||||
newSha1="$apkDir/$baseName-$buildType.apk.sha1"
|
||||
if [ -f "$oldSha1" ]; then
|
||||
if [ -f "$newSha1" ]; then
|
||||
rm -f "$newSha1"
|
||||
fi
|
||||
mv "$oldSha1" "$newSha1"
|
||||
echo "SHA1 renamed to: $baseName-$buildType.apk.sha1"
|
||||
else
|
||||
echo "Warning: SHA1 not found at $oldSha1"
|
||||
fi
|
||||
Reference in New Issue
Block a user