Initial Shijian Android source import
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$tasks = $args
|
||||
if ($tasks.Count -eq 0) {
|
||||
$tasks = @('assembleDebug')
|
||||
}
|
||||
|
||||
$toolchain = & (Join-Path $PSScriptRoot 'env.ps1')
|
||||
foreach ($path in @($toolchain.Java, $toolchain.Gradle, (Join-Path $env:ANDROID_HOME 'platforms\android-35\android.jar'))) {
|
||||
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
|
||||
throw "Missing build dependency: $path. Configure SHIJIAN_JAVA_HOME, SHIJIAN_GRADLE and SHIJIAN_ANDROID_SDK as needed."
|
||||
}
|
||||
}
|
||||
|
||||
$localProperties = Join-Path $toolchain.Root 'local.properties'
|
||||
if (Test-Path -LiteralPath $localProperties) {
|
||||
$sdkLines = Select-String -LiteralPath $localProperties -Pattern '^\s*sdk\.dir\s*[:=]?\s*(.*)$'
|
||||
foreach ($line in $sdkLines) {
|
||||
$sdkValue = $line.Matches[0].Groups[1].Value.Trim().Replace('\:', ':').Replace('\\', '\')
|
||||
if ($sdkValue -notmatch '^[dD]:[\\/]' -or [IO.Path]::GetFullPath($sdkValue).TrimEnd('\') -ne $env:ANDROID_HOME.TrimEnd('\')) {
|
||||
throw "Set sdk.dir in local.properties to the configured D: SDK: $env:ANDROID_HOME"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Push-Location -LiteralPath $toolchain.Root
|
||||
try {
|
||||
& $toolchain.Gradle --no-daemon --console=plain "-Dorg.gradle.java.home=$env:JAVA_HOME" @tasks
|
||||
$buildExitCode = $LASTEXITCODE
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
exit $buildExitCode
|
||||
@@ -0,0 +1,19 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$adbArguments = $args
|
||||
if ($adbArguments.Count -eq 0) {
|
||||
$adbArguments = @('devices', '-l')
|
||||
}
|
||||
|
||||
$toolchain = & (Join-Path $PSScriptRoot 'env.ps1')
|
||||
if (-not (Test-Path -LiteralPath $toolchain.Adb -PathType Leaf)) {
|
||||
throw "Missing Android platform-tools: $($toolchain.Adb)"
|
||||
}
|
||||
|
||||
Push-Location -LiteralPath $toolchain.Root
|
||||
try {
|
||||
& $toolchain.Adb @adbArguments
|
||||
$deviceExitCode = $LASTEXITCODE
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
exit $deviceExitCode
|
||||
@@ -0,0 +1,69 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Get-DPath {
|
||||
param([string]$Path)
|
||||
|
||||
if ($Path -notmatch '^[dD]:[\\/]') {
|
||||
throw "Tool and workspace paths must be absolute D: paths: $Path"
|
||||
}
|
||||
$fullPath = [IO.Path]::GetFullPath($Path)
|
||||
for ($cursor = $fullPath; $cursor; $cursor = Split-Path -Parent $cursor) {
|
||||
if (Test-Path -LiteralPath $cursor) {
|
||||
$item = Get-Item -LiteralPath $cursor -Force
|
||||
if ($item.Attributes -band [IO.FileAttributes]::ReparsePoint) {
|
||||
throw "Use a physical D: path for build data: $cursor"
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fullPath
|
||||
}
|
||||
|
||||
function Get-ToolPath {
|
||||
param([string]$Setting, [string]$DefaultPath)
|
||||
|
||||
$currentPath = [Environment]::GetEnvironmentVariable("SHIJIAN_$Setting")
|
||||
if ($currentPath) {
|
||||
return Get-DPath $currentPath
|
||||
}
|
||||
$legacyPath = [Environment]::GetEnvironmentVariable("JIELIU_$Setting")
|
||||
if ($legacyPath) {
|
||||
return Get-DPath $legacyPath
|
||||
}
|
||||
return Get-DPath $DefaultPath
|
||||
}
|
||||
|
||||
$projectRoot = Get-DPath (Split-Path -Parent $PSScriptRoot)
|
||||
$localData = Get-DPath (Join-Path $projectRoot '.local')
|
||||
$projectJavaHome = Get-ToolPath 'JAVA_HOME' (Join-Path $localData 'jdk-21')
|
||||
$projectSdk = Get-ToolPath 'ANDROID_SDK' 'D:\env\android-sdk'
|
||||
$gradleDistribution = Get-ToolPath 'GRADLE' 'D:\env\gradle'
|
||||
$gradleUserDirectory = Get-ToolPath 'GRADLE_USER_HOME' 'D:\env\gradle-home'
|
||||
$tempDirectory = Get-DPath (Join-Path $localData 'temp')
|
||||
$javaUserDirectory = Get-DPath (Join-Path $localData 'user')
|
||||
$androidUserDirectory = Get-DPath (Join-Path $javaUserDirectory '.android')
|
||||
|
||||
foreach ($directory in @($tempDirectory, $androidUserDirectory, $gradleUserDirectory)) {
|
||||
New-Item -ItemType Directory -Force -Path $directory | Out-Null
|
||||
}
|
||||
|
||||
$env:JAVA_HOME = $projectJavaHome
|
||||
$env:GRADLE_USER_HOME = $gradleUserDirectory
|
||||
$env:ANDROID_HOME = $projectSdk
|
||||
$env:ANDROID_SDK_ROOT = $projectSdk
|
||||
$env:ANDROID_USER_HOME = $androidUserDirectory
|
||||
$env:ANDROID_SDK_DISABLE_ANALYTICS = '1'
|
||||
$env:TEMP = $tempDirectory
|
||||
$env:TMP = $tempDirectory
|
||||
$env:JAVA_TOOL_OPTIONS = "`"-Duser.home=$javaUserDirectory`" `"-Djava.io.tmpdir=$tempDirectory`""
|
||||
|
||||
foreach ($name in @('ANDROID_SDK_HOME', 'ANDROID_EMULATOR_HOME', 'ANDROID_AVD_HOME', 'ADB_VENDOR_KEYS',
|
||||
'JAVA_OPTS', 'GRADLE_OPTS', 'JDK_JAVA_OPTIONS', '_JAVA_OPTIONS')) {
|
||||
Remove-Item -LiteralPath "Env:$name" -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
[pscustomobject]@{
|
||||
Root = $projectRoot
|
||||
Java = Get-DPath (Join-Path $projectJavaHome 'bin\java.exe')
|
||||
Gradle = Get-DPath (Join-Path $gradleDistribution 'bin\gradle.bat')
|
||||
Adb = Get-DPath (Join-Path $projectSdk 'platform-tools\adb.exe')
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
param([string]$ApkPath = 'app\build\outputs\apk\debug\app-debug.apk')
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$toolchain = . (Join-Path $PSScriptRoot 'env.ps1')
|
||||
$artifact = if ([IO.Path]::IsPathRooted($ApkPath)) { $ApkPath } else { Join-Path $toolchain.Root $ApkPath }
|
||||
$artifact = Get-DPath $artifact
|
||||
$signer = Get-DPath (Join-Path $env:ANDROID_HOME 'build-tools\34.0.0\apksigner.bat')
|
||||
|
||||
foreach ($path in @($artifact, $signer, $toolchain.Java)) {
|
||||
if (-not (Test-Path -LiteralPath $path -PathType Leaf)) {
|
||||
throw "Missing APK verification input: $path"
|
||||
}
|
||||
}
|
||||
|
||||
Push-Location -LiteralPath $toolchain.Root
|
||||
try {
|
||||
& $signer verify --verbose --print-certs $artifact
|
||||
$signatureExitCode = $LASTEXITCODE
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
if ($signatureExitCode -ne 0) {
|
||||
exit $signatureExitCode
|
||||
}
|
||||
Get-FileHash -LiteralPath $artifact -Algorithm SHA256 | Format-List Algorithm, Hash, Path
|
||||
Reference in New Issue
Block a user