Skip to content

Updated Build Commands for Latest Record Builds#1

Open
JakeOJeff wants to merge 1 commit into
Immow:mainfrom
JakeOJeff:main
Open

Updated Build Commands for Latest Record Builds#1
JakeOJeff wants to merge 1 commit into
Immow:mainfrom
JakeOJeff:main

Conversation

@JakeOJeff
Copy link
Copy Markdown

Optimized Remove Code
Made 7zip access safer ( Some devices didn't catch 7z even if it was installed )
Added a buildtype option to choose from ( Debug or Unsigned )

@Immow
Copy link
Copy Markdown
Owner

Immow commented Aug 9, 2025

Wow very cool, I'm a total PS noob so very cool the see someone had interest in this project. I was messing with ChatGPT a bit and since I don't have Android setup on my system could you test this code for me?

# ========================
# Love2D APK Build Script
# ========================

# Paths
$gameSource      = "D:\Documents\Programming\Lua\Dev\Teleprompter\"
$loveAndroidPath = "C:\Dev\love-android"

# --- Detect Gradle Flavors & Build Types ---
Set-Location -Path $loveAndroidPath

Write-Host "Fetching available build variants from Gradle..."
$gradleOutput = ./gradlew tasks --all 2>&1

# Extract "assemble<Flavor><BuildType>" patterns
$variants = ($gradleOutput -split "`n") -match "assemble[A-Z].+" |
    ForEach-Object { ($_ -replace 'assemble', '') } |
    Where-Object { $_ -match '^[A-Z][a-z]+' } |
    Sort-Object -Unique

# Split into flavors & build types
$flavors    = $variants | ForEach-Object { $_ -replace '(Debug|Release)$','' } | Sort-Object -Unique
$buildTypes = $variants | ForEach-Object { if ($_ -match '(Debug|Release)$') { $Matches[1] } } | Sort-Object -Unique

# --- Interactive prompts with defaults ---
$defaultFlavor = $flavors | Select-Object -First 1   # First flavor as default
$defaultType   = "Debug"                             # Debug as default

Write-Host "`nAvailable flavors:"
for ($i = 0; $i -lt $flavors.Count; $i++) {
    if ($flavors[$i] -eq $defaultFlavor) {
        Write-Host "$($i+1)) $($flavors[$i])  (recommended)"
    } else {
        Write-Host "$($i+1)) $($flavors[$i])"
    }
}
$flavorChoice = Read-Host "Enter choice (1-$($flavors.Count)) or press Enter for recommended"
if ([string]::IsNullOrWhiteSpace($flavorChoice)) {
    $flavor = $defaultFlavor
} else {
    $flavor = $flavors[[int]$flavorChoice - 1]
}

Write-Host "`nAvailable build types:"
for ($i = 0; $i -lt $buildTypes.Count; $i++) {
    if ($buildTypes[$i] -eq $defaultType) {
        Write-Host "$($i+1)) $($buildTypes[$i])  (recommended)"
    } else {
        Write-Host "$($i+1)) $($buildTypes[$i])"
    }
}
$typeChoice = Read-Host "Enter choice (1-$($buildTypes.Count)) or press Enter for recommended"
if ([string]::IsNullOrWhiteSpace($typeChoice)) {
    $buildType = $defaultType
} else {
    $buildType = $buildTypes[[int]$typeChoice - 1]
}

Write-Host "`nBuilding $flavor $buildType..."

# --- Detect 7-Zip ---
$possible7zPaths = @(
    "$Env:ProgramFiles\7-Zip\7z.exe",
    "$Env:ProgramFiles(x86)\7-Zip\7z.exe",
    "C:\Program Files\7-Zip\7z.exe",
    "C:\Program Files (x86)\7-Zip\7z.exe"
)
$7zip = $possible7zPaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $7zip) {
    Write-Error "7-Zip executable not found. Please install 7-Zip or add it to PATH."
    exit 1
}

# --- Helper function to remove files quietly ---
function Remove-GameFile {
    param ([string]$Path)
    if (Test-Path -Path $Path -PathType Leaf) {
        Remove-Item $Path -Force
    }
}

# --- Clean old outputs ---
Remove-GameFile "$loveAndroidPath\app\src\main\assets\game.love"
Remove-GameFile "$loveAndroidPath\app\build\outputs\apk\$($flavor.ToLower())\$($buildType.ToLower())\app-$($flavor.ToLower())-$($buildType.ToLower()).apk"

# --- Package game.love ---
& $7zip a "$loveAndroidPath\app\src\main\assets\game.love" "$gameSource\*"

# --- Build APK ---
Set-Location -Path $loveAndroidPath
./gradlew "assemble$flavor$buildType"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants