diff options
| author | root <root@dangofactory.local> | 2026-11-23 10:20:49 +0900 |
|---|---|---|
| committer | root <root@dangofactory.local> | 2026-11-23 10:20:49 +0900 |
| commit | a67bdcc65a165d1da57ae6d6fead84a1d2e5b248 (patch) | |
| tree | d0075dacac62d509a09974c1cd2f18ca72cf0e39 /build.ps1 | |
| download | tethering-app-main.tar.gz tethering-app-main.zip | |
Diffstat (limited to 'build.ps1')
| -rw-r--r-- | build.ps1 | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..706303b --- /dev/null +++ b/build.ps1 @@ -0,0 +1,64 @@ +$ErrorActionPreference = 'Stop' + +$sdk = 'C:\Users\forest\AppData\Local\Android\Sdk' +$buildTools = Join-Path $sdk 'build-tools\35.0.0' +$androidJar = Join-Path $sdk 'platforms\android-34\android.jar' +$root = Split-Path -Parent $MyInvocation.MyCommand.Path +$build = Join-Path $root 'build' + +Write-Host '=== clean ===' +if (Test-Path $build) { Remove-Item $build -Recurse -Force } +New-Item -ItemType Directory -Path $build | Out-Null +New-Item -ItemType Directory -Path (Join-Path $build 'classes') | Out-Null +New-Item -ItemType Directory -Path (Join-Path $build 'dex') | Out-Null + +Write-Host '=== javac ===' +$sources = @(Get-ChildItem (Join-Path $root 'src') -Recurse -Filter *.java | ForEach-Object { $_.FullName }) +& javac -encoding UTF-8 -cp $androidJar -d (Join-Path $build 'classes') $sources +if ($LASTEXITCODE -ne 0) { throw 'javac failed' } + +Write-Host '=== d8 ===' +$classes = @(Get-ChildItem (Join-Path $build 'classes') -Recurse -Filter *.class | ForEach-Object { $_.FullName }) +& (Join-Path $buildTools 'd8.bat') --min-api 21 --lib $androidJar --output (Join-Path $build 'dex') $classes +if ($LASTEXITCODE -ne 0) { throw 'd8 failed' } + +Write-Host '=== aapt package ===' +$unsigned = Join-Path $build 'app-unsigned.apk' +& (Join-Path $buildTools 'aapt.exe') package -f -M (Join-Path $root 'AndroidManifest.xml') -S (Join-Path $root 'res') -A (Join-Path $root 'assets') -I $androidJar -F $unsigned +if ($LASTEXITCODE -ne 0) { throw 'aapt package failed' } + +Push-Location (Join-Path $build 'dex') +try { + & (Join-Path $buildTools 'aapt.exe') add $unsigned classes.dex + if ($LASTEXITCODE -ne 0) { throw 'aapt add failed' } +} finally { + Pop-Location +} + +Write-Host '=== zipalign ===' +$aligned = Join-Path $build 'app-aligned.apk' +& (Join-Path $buildTools 'zipalign.exe') -f 4 $unsigned $aligned +if ($LASTEXITCODE -ne 0) { throw 'zipalign failed' } + +Write-Host '=== keystore ===' +$ks = Join-Path $root 'debug.keystore' +if (-not (Test-Path $ks)) { + & keytool -genkeypair -keystore $ks -alias androiddebugkey -storepass android -keypass android ` + -keyalg RSA -keysize 2048 -validity 10000 -dname 'CN=Android Debug,O=Android,C=US' + if ($LASTEXITCODE -ne 0) { throw 'keytool failed' } +} + +Write-Host '=== apksigner ===' +$out = Join-Path $build 'Tethering-debug.apk' +& (Join-Path $buildTools 'apksigner.bat') sign --ks $ks --ks-pass pass:android --key-pass pass:android ` + --out $out $aligned +if ($LASTEXITCODE -ne 0) { throw 'apksigner failed' } + +$asciiOut = 'C:\Users\forest\AppData\Local\Temp\opencode\Tethering-debug.apk' +Copy-Item $out $asciiOut -Force + +Write-Host '' +Write-Host "APK: $out" +Write-Host "Install copy (ASCII path): $asciiOut" +Write-Host " adb install -r `"$asciiOut`"" +Get-Item $out | Select-Object FullName, Length, LastWriteTime |
