메인 PC를 새로 설치해 노트북과 같은 제작 환경이 필요해졌다. 관리자 터미널에서 setup-dev.ps1 한 줄을 실행하면 Git과 JDK 21 및 Android Studio와 Python 3.14 및 Node.js LTS를 winget으로 설치하고 SDK 36과 Build Tools 36.0.0 및 가상 기기와 소스를 준비한 뒤 확인용 빌드까지 돌린다. 기존 배포 서명 키는 인증서가 같을 때만 복사하고 확인용 빌드는 시험 키로 서명해 배포 키 자리에 새 키가 생기지 않게 했다. duty-app.bat는 실행 정책을 바꾸지 않고 check와 key 및 release와 audit 및 가상 기기 명령을 제공한다. 배포 검사의 --java에는 java 실행 파일을 넘긴다. 검사: PowerShell 7.4 구문 분석 오류 0건. PSScriptAnalyzer 1.23.0 Windows PowerShell 5.1 호환 검사에서 오래된 Server 2016의 Add-AppxPackage 인수 1건만 나와 예외 처리로 두었다. keytool 실제 출력으로 SHA-256 지문 읽기를 확인했다. Windows 실기 실행은 아직 하지 않았다.
355 lines
23 KiB
PowerShell
355 lines
23 KiB
PowerShell
# 당직근무 앱 제작용 Windows PC 준비 · 블리어 (이창현) · 2026-11-24
|
|
#
|
|
# 관리자 권한 터미널(시작 버튼 오른쪽 클릭 > 터미널(관리자))에 아래 한 줄을 붙여 넣는다.
|
|
# irm https://gitea.itosm.co.kr/syskiller/duty-calendar/raw/branch/main/tools/windows/setup-dev.ps1 | iex
|
|
#
|
|
# 이미 된 단계는 건너뛰므로 여러 번 실행해도 된다. 재부팅 뒤 다시 실행하면 남은 단계만 한다.
|
|
# 1. Git, Microsoft OpenJDK 21, Android Studio, Python 3.14, Node.js LTS 설치(winget)
|
|
# 2. Android SDK 명령줄 도구 23.0과 SDK 36, Build Tools 36.0.0, Platform Tools, Emulator, API 36 시스템 이미지
|
|
# 3. 가상 기기 가속용 Windows 하이퍼바이저 플랫폼 켜기(처음 켤 때 재부팅 필요)
|
|
# 4. 소스 받기와 local.properties, Android Studio의 Gradle JDK(JAVA_HOME = JDK 21) 설정
|
|
# 5. 기존 배포 서명 키(debug.keystore)를 바탕 화면, 다운로드, USB에서 찾아 인증서가 배포 인증서와 같을 때만
|
|
# %USERPROFILE%\.android 로 복사한다. 이미 있던 다른 키는 지우지 않고 이름을 바꿔 둔다.
|
|
# 6. API 36 가상 기기 duty36 만들기, 확인용 빌드와 단위 및 정적 검사
|
|
#
|
|
# 이 스크립트는 서명 키나 비밀번호를 만들거나 밖으로 보내지 않는다. 확인용 빌드는 별도 시험 키로 서명한다.
|
|
# 사용자 폴더 이름에 한글이나 빈칸이 있으면 Android 도구가 실패할 수 있어 C:\duty-dev 아래를 쓴다.
|
|
# 관리자 권한으로 만든 파일은 마지막에 소유자를 현재 사용자로 돌려 Git이 저장소를 거부하지 않게 한다.
|
|
|
|
& {
|
|
$ErrorActionPreference = 'Continue'
|
|
$ProgressPreference = 'SilentlyContinue' # Windows PowerShell 5.1은 진행 막대를 그리느라 내려받기가 매우 느려진다
|
|
try { [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 } catch { }
|
|
|
|
$RepoUrl = 'https://gitea.itosm.co.kr/syskiller/duty-calendar.git'
|
|
$ToolsZip = 'commandlinetools-win-16111833_latest.zip' # Android SDK Command-line Tools 23.0
|
|
$ToolsSha1 = '57d04f2d75eb8e8fffc5000a987e5de4b5a63e9d' # Google 저장소 목록(repository2-3.xml)의 값
|
|
$AvdName = 'duty36'
|
|
$Programs = @(
|
|
@{ Id = 'Git.Git'; Name = 'Git' },
|
|
@{ Id = 'Microsoft.OpenJDK.21'; Name = 'JDK 21' },
|
|
@{ Id = 'Google.AndroidStudio'; Name = 'Android Studio' },
|
|
@{ Id = 'Python.Python.3.14'; Name = 'Python 3.14' },
|
|
@{ Id = 'OpenJS.NodeJS.LTS'; Name = 'Node.js LTS' }
|
|
)
|
|
$Summary = New-Object System.Collections.Generic.List[string]
|
|
|
|
function Say([string]$Text) { Write-Host ''; Write-Host ('== ' + $Text) -ForegroundColor Cyan }
|
|
function Note([string]$Text) { Write-Host (' ' + $Text) }
|
|
function Good([string]$Text) { Write-Host (' ' + $Text) -ForegroundColor Green }
|
|
function Warn([string]$Text) { Write-Host (' ' + $Text) -ForegroundColor Yellow }
|
|
|
|
function Update-PathEnv {
|
|
$parts = @([Environment]::GetEnvironmentVariable('Path', 'Machine'), [Environment]::GetEnvironmentVariable('Path', 'User')) | Where-Object { $_ }
|
|
$env:Path = $parts -join ';'
|
|
}
|
|
|
|
function Set-UserEnv([string]$Name, [string]$Value) {
|
|
if ([Environment]::GetEnvironmentVariable($Name, 'User') -ne $Value) { [Environment]::SetEnvironmentVariable($Name, $Value, 'User') }
|
|
Set-Item -Path ('Env:' + $Name) -Value $Value
|
|
}
|
|
|
|
function Add-UserPath([string]$Dir) {
|
|
$now = [Environment]::GetEnvironmentVariable('Path', 'User')
|
|
$parts = @()
|
|
if ($now) { $parts = @($now -split ';' | Where-Object { $_ }) }
|
|
if ($parts -notcontains $Dir) { [Environment]::SetEnvironmentVariable('Path', (($parts + $Dir) -join ';'), 'User') }
|
|
if (($env:Path -split ';') -notcontains $Dir) { $env:Path = $env:Path + ';' + $Dir }
|
|
}
|
|
|
|
function Find-Jdk21 {
|
|
$list = New-Object System.Collections.Generic.List[string]
|
|
foreach ($scope in 'Process', 'User', 'Machine') {
|
|
$value = [Environment]::GetEnvironmentVariable('JAVA_HOME', $scope)
|
|
if ($value) { $list.Add($value) }
|
|
}
|
|
$roots = @((Join-Path $env:ProgramFiles 'Microsoft'), (Join-Path $env:ProgramFiles 'Android\openjdk'), (Join-Path $env:ProgramFiles 'Eclipse Adoptium'), (Join-Path $env:ProgramFiles 'Java'))
|
|
foreach ($root in $roots) {
|
|
if (Test-Path $root) {
|
|
Get-ChildItem -Path $root -Directory -Filter 'jdk-21*' -ErrorAction SilentlyContinue | Sort-Object Name -Descending | ForEach-Object { $list.Add($_.FullName) }
|
|
}
|
|
}
|
|
foreach ($dir in $list) {
|
|
$release = Join-Path $dir 'release'
|
|
if ((Test-Path (Join-Path $dir 'bin\javac.exe')) -and (Test-Path $release) -and ((Get-Content $release -Raw) -match 'JAVA_VERSION="21')) { return $dir }
|
|
}
|
|
return $null
|
|
}
|
|
|
|
# keytool 안내문은 Windows 언어를 따라 바뀌므로 영어로 고정하고 SHA256 지문만 읽는다.
|
|
function Get-KeyCert([string]$Keytool, [string]$File) {
|
|
$text = (& $Keytool -J-Duser.language=en -J-Duser.country=US -list -v -keystore $File -storepass android -alias androiddebugkey 2>&1 | ForEach-Object { "$_" }) -join "`n"
|
|
if ($text -match 'SHA256:\s*([0-9A-Fa-f]{2}(?::[0-9A-Fa-f]{2}){31})') { return ($Matches[1] -replace ':', '').ToLower() }
|
|
return $null
|
|
}
|
|
|
|
function Install-Program($Program) {
|
|
& winget list --id $Program.Id -e --accept-source-agreements | Out-Null
|
|
if ($LASTEXITCODE -eq 0) { Note ($Program.Name + ': 이미 설치돼 있습니다.'); return $true }
|
|
Note ($Program.Name + ' 설치 중...')
|
|
& winget install --id $Program.Id -e --source winget --silent --accept-package-agreements --accept-source-agreements | Out-Host
|
|
$code = $LASTEXITCODE
|
|
# 0: 설치됨, 0x8A15002B: 새 버전 없음, 0x8A150061: 이미 설치됨, 0x8A150109: 재부팅 뒤 마무리
|
|
if ($code -eq 0 -or $code -eq 0x8A15002B -or $code -eq 0x8A150061 -or $code -eq 0x8A150109) { Good ($Program.Name + ' 설치 완료'); return $true }
|
|
Warn ('{0} 설치 실패 (winget 코드 0x{1:X8})' -f $Program.Name, $code)
|
|
return $false
|
|
}
|
|
|
|
# ---------------------------------------------------------------- 시작 전 확인
|
|
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
|
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
|
Warn '관리자 권한이 필요합니다. 시작 버튼을 오른쪽 클릭 > 터미널(관리자)을 열고 같은 줄을 다시 붙여 넣으세요.'
|
|
return
|
|
}
|
|
|
|
$plainHome = ($env:USERPROFILE -notmatch '[^\u0021-\u007E]')
|
|
$sdkFromEnv = [Environment]::GetEnvironmentVariable('ANDROID_HOME', 'User')
|
|
if ($plainHome) {
|
|
$Base = Join-Path $env:LOCALAPPDATA 'Android'
|
|
$Sdk = Join-Path $Base 'Sdk'
|
|
$Src = Join-Path $env:USERPROFILE 'duty-calendar'
|
|
$AvdHome = Join-Path $env:USERPROFILE '.android\avd'
|
|
$GradleHome = $null
|
|
} else {
|
|
$Base = 'C:\duty-dev\Android'
|
|
$Sdk = Join-Path $Base 'Sdk'
|
|
$Src = 'C:\duty-dev\duty-calendar'
|
|
$AvdHome = Join-Path $Base 'avd'
|
|
$GradleHome = 'C:\duty-dev\gradle'
|
|
}
|
|
if ($sdkFromEnv -and (Test-Path (Join-Path $sdkFromEnv 'platforms')) -and ($sdkFromEnv -notmatch '[^\u0021-\u007E]')) { $Sdk = $sdkFromEnv }
|
|
$Work = Join-Path $Base 'setup-tmp'
|
|
$TestHome = Join-Path $Base 'test-user-home'
|
|
$Image = 'system-images;android-36;default;x86_64'
|
|
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { $Image = 'system-images;android-36;default;arm64-v8a' }
|
|
|
|
New-Item -ItemType Directory -Force -Path $Base | Out-Null
|
|
$Log = Join-Path $Base ('setup-log-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '.txt')
|
|
try { Start-Transcript -Path $Log | Out-Null } catch { }
|
|
try {
|
|
Write-Host ''
|
|
Write-Host '당직근무 앱 제작 PC 준비' -ForegroundColor Cyan
|
|
Note ('소스: ' + $Src)
|
|
Note ('Android SDK: ' + $Sdk)
|
|
$drive = Get-PSDrive -Name ($Sdk.Substring(0, 1)) -ErrorAction SilentlyContinue
|
|
if ($drive -and $drive.Free -lt 30GB) { Warn ('{0} 드라이브 남은 공간이 {1:N0}GB입니다. 30GB 정도가 필요합니다.' -f $drive.Name, ($drive.Free / 1GB)) }
|
|
Note '설치: Git, Microsoft OpenJDK 21, Android Studio, Python 3.14, Node.js LTS'
|
|
Note ' Android SDK 36, Build Tools 36.0.0, Platform Tools, Emulator, API 36 시스템 이미지'
|
|
Note '각 프로그램의 사용 약관과 Android SDK 약관(https://developer.android.com/studio/terms)에 동의해야 설치됩니다.'
|
|
$answer = Read-Host ' 동의하고 설치하려면 y 를 입력하고 Enter'
|
|
if ($answer -notmatch '^\s*(y|yes|예|네)\s*$') { Warn '설치를 취소했습니다.'; return }
|
|
|
|
if (-not (Get-Command winget.exe -ErrorAction SilentlyContinue)) {
|
|
try { Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe -ErrorAction Stop } catch { }
|
|
Update-PathEnv
|
|
}
|
|
if (-not (Get-Command winget.exe -ErrorAction SilentlyContinue)) {
|
|
Warn 'winget(앱 설치 관리자)이 없습니다. 열리는 Microsoft Store 화면에서 앱 설치 관리자를 설치하거나 업데이트한 뒤 다시 실행하세요.'
|
|
Start-Process 'ms-windows-store://pdp/?productid=9NBLGGH4NNS1'
|
|
return
|
|
}
|
|
New-Item -ItemType Directory -Force -Path $Work | Out-Null
|
|
|
|
# ---------------------------------------------------------------- 1. 프로그램
|
|
Say '1/6 프로그램 설치'
|
|
$failed = @()
|
|
foreach ($program in $Programs) { if (-not (Install-Program $program)) { $failed += $program.Name } }
|
|
Update-PathEnv
|
|
$git = $null
|
|
$gitCommand = Get-Command git.exe -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
if ($gitCommand) { $git = $gitCommand.Path } elseif (Test-Path (Join-Path $env:ProgramFiles 'Git\cmd\git.exe')) { $git = Join-Path $env:ProgramFiles 'Git\cmd\git.exe' }
|
|
$jdk = Find-Jdk21
|
|
if (-not $git -or -not $jdk) { Warn 'Git이나 JDK 21을 찾지 못했습니다. 위의 설치 오류를 확인하고 이 줄을 다시 실행하세요.'; return }
|
|
Set-UserEnv 'JAVA_HOME' $jdk
|
|
Set-UserEnv 'ANDROID_HOME' $Sdk
|
|
if ($GradleHome) { Set-UserEnv 'GRADLE_USER_HOME' $GradleHome; Set-UserEnv 'ANDROID_AVD_HOME' $AvdHome }
|
|
Add-UserPath (Join-Path $Sdk 'platform-tools')
|
|
Good ('JDK 21: ' + $jdk)
|
|
if ($failed.Count -gt 0) { $Summary.Add('설치 실패: ' + ($failed -join ', ') + ' (다시 실행하면 이어서 설치합니다)') }
|
|
|
|
# ---------------------------------------------------------------- 2. Android SDK
|
|
Say '2/6 Android SDK'
|
|
$sdkmanager = Join-Path $Sdk 'cmdline-tools\latest\bin\sdkmanager.bat'
|
|
$avdmanager = Join-Path $Sdk 'cmdline-tools\latest\bin\avdmanager.bat'
|
|
if (-not (Test-Path $sdkmanager)) {
|
|
$zip = Join-Path $Work $ToolsZip
|
|
$unpack = Join-Path $Work 'cmdline-tools-unpack'
|
|
Note 'SDK 명령줄 도구 받는 중...'
|
|
try { Invoke-WebRequest -UseBasicParsing -Uri ('https://dl.google.com/android/repository/' + $ToolsZip) -OutFile $zip -ErrorAction Stop }
|
|
catch { Warn ('내려받기 실패: ' + $_.Exception.Message + ' 인터넷 연결을 확인하고 다시 실행하세요.'); return }
|
|
if ((Get-FileHash -Algorithm SHA1 -Path $zip).Hash.ToLower() -ne $ToolsSha1) {
|
|
Remove-Item $zip -Force
|
|
Warn '받은 파일의 확인값이 Google 목록과 달라 쓰지 않았습니다. 다시 실행하세요.'
|
|
return
|
|
}
|
|
Remove-Item $unpack -Recurse -Force -ErrorAction SilentlyContinue
|
|
Expand-Archive -Path $zip -DestinationPath $unpack -Force
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $Sdk 'cmdline-tools') | Out-Null
|
|
Remove-Item (Join-Path $Sdk 'cmdline-tools\latest') -Recurse -Force -ErrorAction SilentlyContinue
|
|
Move-Item (Join-Path $unpack 'cmdline-tools') (Join-Path $Sdk 'cmdline-tools\latest')
|
|
Remove-Item $zip, $unpack -Recurse -Force -ErrorAction SilentlyContinue
|
|
}
|
|
# 패키지 이름의 세미콜론이 명령 구분자로 읽히지 않도록 목록 파일로 넘긴다.
|
|
$packageFile = Join-Path $Work 'sdk-packages.txt'
|
|
[IO.File]::WriteAllLines($packageFile, [string[]]@('platform-tools', 'platforms;android-36', 'build-tools;36.0.0', 'emulator', $Image))
|
|
Note '약관 동의 기록 중...'
|
|
@(1..60 | ForEach-Object { 'y' }) | & $sdkmanager "--sdk_root=$Sdk" --licenses | Out-Null
|
|
Note 'SDK 패키지 받는 중(처음에는 몇 GB를 받습니다)...'
|
|
& $sdkmanager "--sdk_root=$Sdk" "--package_file=$packageFile" | Out-Host
|
|
$sdkOk = ($LASTEXITCODE -eq 0) -and (Test-Path (Join-Path $Sdk 'platforms\android-36')) -and (Test-Path (Join-Path $Sdk 'build-tools\36.0.0'))
|
|
if ($sdkOk) { Good 'SDK 준비 완료' } else { Warn 'SDK 패키지 일부를 받지 못했습니다. 다시 실행하면 이어서 받습니다.'; $Summary.Add('SDK 패키지 일부 실패') }
|
|
|
|
# ---------------------------------------------------------------- 3. 가상 기기 가속
|
|
Say '3/6 가상 기기 가속(Windows 하이퍼바이저 플랫폼)'
|
|
$needReboot = $false
|
|
try {
|
|
$feature = Get-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -ErrorAction Stop
|
|
if ($feature.State -eq 'Enabled') { Good '이미 켜져 있습니다.' }
|
|
else {
|
|
$enabled = Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All -NoRestart -ErrorAction Stop
|
|
if ($enabled.RestartNeeded) { $needReboot = $true }
|
|
Good '켰습니다.'
|
|
}
|
|
} catch { Warn ('켜지 못했습니다: ' + $_.Exception.Message); $Summary.Add('하이퍼바이저 플랫폼을 켜지 못함(가상 기기는 느리거나 안 뜰 수 있음)') }
|
|
if (-not $needReboot) {
|
|
$pending = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' -ErrorAction SilentlyContinue
|
|
if ($pending) { $needReboot = $true }
|
|
}
|
|
|
|
# ---------------------------------------------------------------- 4. 소스
|
|
Say '4/6 소스'
|
|
if (-not (Test-Path (Join-Path $Src '.git'))) {
|
|
New-Item -ItemType Directory -Force -Path (Split-Path -Parent $Src) | Out-Null
|
|
& $git clone $RepoUrl $Src | Out-Host
|
|
if ($LASTEXITCODE -ne 0) { Warn '소스를 받지 못했습니다. 인터넷 연결을 확인하고 다시 실행하세요.'; return }
|
|
Good ('받았습니다: ' + $Src)
|
|
} else {
|
|
$dirty = & $git -C $Src -c "safe.directory=$($Src.Replace('\', '/'))" status --porcelain
|
|
if ($dirty) { Note '고친 파일이 있어 새로 받지 않았습니다.' }
|
|
else {
|
|
& $git -C $Src -c "safe.directory=$($Src.Replace('\', '/'))" pull --ff-only | Out-Host
|
|
if ($LASTEXITCODE -eq 0) { Good '최신으로 맞췄습니다.' } else { Warn '새로 받지 못했습니다. 있던 소스로 계속합니다.' }
|
|
}
|
|
}
|
|
$globalName = & $git config --global user.name
|
|
if (-not $globalName) {
|
|
& $git -C $Src -c "safe.directory=$($Src.Replace('\', '/'))" config user.name '블리어'
|
|
& $git -C $Src -c "safe.directory=$($Src.Replace('\', '/'))" config user.email 'syskiller@noreply.gitea.itosm.co.kr'
|
|
}
|
|
$localProperties = Join-Path $Src 'local.properties'
|
|
$sdkLine = 'sdk.dir=' + $Sdk.Replace('\', '\\').Replace(':', '\:')
|
|
$lines = @()
|
|
if (Test-Path $localProperties) { $lines = @(Get-Content $localProperties | Where-Object { $_ -notmatch '^sdk\.dir=' }) }
|
|
[IO.File]::WriteAllLines($localProperties, [string[]]($lines + $sdkLine))
|
|
# Android Studio가 동봉 JBR(25)로 Gradle 8.13을 돌리지 않게 Gradle JDK를 JAVA_HOME(JDK 21)으로 정한다. 이미 연 프로젝트는 건드리지 않는다.
|
|
$gradleXml = Join-Path $Src '.idea\gradle.xml'
|
|
if (-not (Test-Path $gradleXml)) {
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $Src '.idea') | Out-Null
|
|
$xml = @(
|
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
'<project version="4">',
|
|
' <component name="GradleSettings">',
|
|
' <option name="linkedExternalProjectsSettings">',
|
|
' <GradleProjectSettings>',
|
|
' <option name="externalProjectPath" value="$PROJECT_DIR$" />',
|
|
' <option name="gradleJvm" value="#JAVA_HOME" />',
|
|
' </GradleProjectSettings>',
|
|
' </option>',
|
|
' </component>',
|
|
'</project>'
|
|
)
|
|
[IO.File]::WriteAllLines($gradleXml, [string[]]$xml)
|
|
}
|
|
Add-UserPath (Join-Path $Src 'tools\windows')
|
|
Good 'local.properties와 Gradle JDK 설정 완료'
|
|
|
|
# ---------------------------------------------------------------- 5. 서명 키
|
|
Say '5/6 배포 서명 키'
|
|
$keytool = Join-Path $jdk 'bin\keytool.exe'
|
|
$expected = ''
|
|
try { $expected = (Get-Content (Join-Path $Src 'tools\release_security_policy.json') -Raw -Encoding UTF8 | ConvertFrom-Json).signerSha256.ToLower() } catch { }
|
|
$androidUser = Join-Path $env:USERPROFILE '.android'
|
|
$key = Join-Path $androidUser 'debug.keystore'
|
|
$keyOk = $false
|
|
if ($expected -and (Test-Path $key) -and ((Get-KeyCert $keytool $key) -eq $expected)) { $keyOk = $true; Good '배포 키가 이미 들어 있습니다.' }
|
|
if (-not $keyOk -and $expected) {
|
|
$places = @([Environment]::GetFolderPath('Desktop'), (Join-Path $env:USERPROFILE 'Downloads'))
|
|
$places += @(Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=2' -ErrorAction SilentlyContinue | ForEach-Object { $_.DeviceID + '\' })
|
|
$found = @()
|
|
foreach ($place in $places) {
|
|
if ($place -and (Test-Path $place)) { $found += @(Get-ChildItem -Path $place -Filter 'debug.keystore' -File -Recurse -Depth 2 -ErrorAction SilentlyContinue) }
|
|
}
|
|
foreach ($file in $found) {
|
|
if ((Get-KeyCert $keytool $file.FullName) -ne $expected) { Note ('인증서가 달라 쓰지 않음: ' + $file.FullName); continue }
|
|
New-Item -ItemType Directory -Force -Path $androidUser | Out-Null
|
|
if (Test-Path $key) {
|
|
$kept = $key + '.이전-' + (Get-Date -Format 'yyyyMMdd-HHmmss')
|
|
Move-Item $key $kept
|
|
Note ('있던 다른 키는 이름을 바꿔 두었습니다: ' + $kept)
|
|
}
|
|
Copy-Item $file.FullName $key
|
|
if ((Get-KeyCert $keytool $key) -eq $expected) {
|
|
$keyOk = $true
|
|
Good ('배포 키를 넣었습니다: ' + $file.FullName + ' -> ' + $key)
|
|
Note '복사에 쓴 USB나 바탕 화면의 키 파일은 이제 지우거나 안전한 곳에 보관하세요.'
|
|
}
|
|
break
|
|
}
|
|
}
|
|
if (-not $keyOk) {
|
|
Warn '배포 서명 키가 아직 없습니다. 확인용 빌드는 되지만 배포용 APK는 만들 수 없습니다.'
|
|
Warn '예전에 앱을 만든 PC의 %USERPROFILE%\.android\debug.keystore 를 USB나 바탕 화면에 두고 이 줄을 다시 실행하세요.'
|
|
$Summary.Add('배포 서명 키 없음')
|
|
}
|
|
|
|
# ---------------------------------------------------------------- 6. 가상 기기와 확인용 빌드
|
|
Say '6/6 가상 기기와 확인용 빌드'
|
|
if ($sdkOk -and -not (Test-Path (Join-Path $AvdHome ($AvdName + '.avd')))) {
|
|
$env:ANDROID_AVD_HOME = $AvdHome
|
|
'no' | & $avdmanager create avd -n $AvdName -k $Image -d pixel_6 | Out-Host
|
|
$config = Join-Path $AvdHome ($AvdName + '.avd\config.ini')
|
|
if (Test-Path $config) {
|
|
# PC 메모리가 16GB보다 적으면 가상 기기 메모리를 서버와 같은 3GB로 줄인다.
|
|
$ram = 4096
|
|
try { if ((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory -lt 15GB) { $ram = 3072 } } catch { }
|
|
$text = @(Get-Content $config | Where-Object { $_ -notmatch '^(hw\.ramSize|hw\.keyboard|disk\.dataPartition\.size)=' })
|
|
[IO.File]::WriteAllLines($config, [string[]]($text + ('hw.ramSize=' + $ram) + 'hw.keyboard=yes' + 'disk.dataPartition.size=4G'))
|
|
Good ('가상 기기를 만들었습니다: ' + $AvdName)
|
|
} else { Warn '가상 기기를 만들지 못했습니다. Android Studio의 Device Manager에서 API 36 기기를 만들어도 됩니다.'; $Summary.Add('가상 기기 만들기 실패') }
|
|
} elseif ($sdkOk) { Good ('가상 기기가 이미 있습니다: ' + $AvdName) }
|
|
|
|
$buildOk = $false
|
|
if ($sdkOk) {
|
|
Note '확인용 빌드와 검사 중(처음에는 Gradle과 라이브러리를 받느라 몇 분 걸립니다)...'
|
|
New-Item -ItemType Directory -Force -Path $TestHome | Out-Null
|
|
$env:ANDROID_USER_HOME = $TestHome # 확인용 빌드는 시험 키를 쓴다. 배포 키 자리에 새 키가 생기지 않게 한다.
|
|
Push-Location $Src
|
|
& (Join-Path $Src 'gradlew.bat') --no-daemon assembleDebug testDebugUnitTest lintDebug | Out-Host
|
|
$buildOk = ($LASTEXITCODE -eq 0)
|
|
Pop-Location
|
|
Remove-Item Env:ANDROID_USER_HOME -ErrorAction SilentlyContinue
|
|
if ($buildOk) { Good '확인용 빌드와 단위 및 정적 검사 통과' } else { Warn '확인용 빌드나 검사가 실패했습니다. 위 오류를 확인하세요.'; $Summary.Add('확인용 빌드 실패') }
|
|
}
|
|
|
|
# 관리자 권한으로 만든 폴더의 소유자를 현재 사용자로 돌린다(Git의 소유자 검사와 일반 권한 작업을 위해).
|
|
$me = [Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
foreach ($dir in @($Src, $androidUser)) { if (Test-Path $dir) { & icacls.exe $dir /setowner $me /T /C /Q | Out-Null } }
|
|
if (-not $plainHome -and (Test-Path 'C:\duty-dev')) {
|
|
& icacls.exe 'C:\duty-dev' /grant ($me + ':(OI)(CI)F') /C /Q | Out-Null
|
|
& icacls.exe 'C:\duty-dev' /setowner $me /T /C /Q | Out-Null
|
|
}
|
|
Remove-Item $Work -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
# ---------------------------------------------------------------- 결과
|
|
Say '결과'
|
|
Note ('소스: ' + $Src)
|
|
Note '도우미: 새 터미널에서 duty-app check | key | release | audit | emu | emu-stop | install | shot'
|
|
Note ' Android Studio에서는 파일 > 열기로 위 소스 폴더를 엽니다.'
|
|
if ($needReboot) { Warn '가상 기기 가속을 켜려면 한 번 재부팅해야 합니다. 재부팅 뒤 같은 줄을 다시 실행하면 확인만 하고 끝납니다.' }
|
|
if ($Summary.Count -eq 0 -and -not $needReboot) { Good '준비 완료. 이 PC에서 앱을 만들 수 있습니다.' }
|
|
elseif ($Summary.Count -eq 0) { Good '준비 완료(재부팅 필요).' }
|
|
else { foreach ($line in $Summary) { Warn ('남은 일: ' + $line) } }
|
|
Note ('진행 기록: ' + $Log)
|
|
} finally { try { Stop-Transcript | Out-Null } catch { } }
|
|
}
|