Add Kotlin and Rust Android agent with signed APK export
This commit is contained in:
1 parent
e366eb5bec
commit
5b3022e1f3
20 files changed
+3568
-2
No files matched your search
@@ -0,0 +1,26 @@
|
||||
param([string]$Ndk = $env:ANDROID_NDK_HOME)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (-not $Ndk -or -not (Test-Path $Ndk)) { throw 'Set ANDROID_NDK_HOME to an installed NDK (r28+ recommended for 16 KB pages).' }
|
||||
$project = Split-Path $PSScriptRoot -Parent
|
||||
$manifest = Join-Path $project 'native/Cargo.toml'
|
||||
$targets = @(
|
||||
@{Rust='aarch64-linux-android'; Abi='arm64-v8a'; Clang='aarch64-linux-android23-clang.cmd'},
|
||||
@{Rust='armv7-linux-androideabi'; Abi='armeabi-v7a'; Clang='armv7a-linux-androideabi23-clang.cmd'},
|
||||
@{Rust='x86_64-linux-android'; Abi='x86_64'; Clang='x86_64-linux-android23-clang.cmd'}
|
||||
)
|
||||
foreach ($t in $targets) {
|
||||
$linker = Join-Path $Ndk "toolchains/llvm/prebuilt/windows-x86_64/bin/$($t.Clang)"
|
||||
if (-not (Test-Path $linker)) { throw "Missing NDK clang: $linker" }
|
||||
$key = 'CARGO_TARGET_' + $t.Rust.Replace('-', '_').ToUpper() + '_LINKER'
|
||||
[Environment]::SetEnvironmentVariable($key, $linker, 'Process')
|
||||
$ccKey = 'CC_' + $t.Rust.Replace('-', '_')
|
||||
[Environment]::SetEnvironmentVariable($ccKey, $linker, 'Process')
|
||||
$ar = Join-Path $Ndk 'toolchains/llvm/prebuilt/windows-x86_64/bin/llvm-ar.exe'
|
||||
[Environment]::SetEnvironmentVariable(('AR_' + $t.Rust.Replace('-', '_')), $ar, 'Process')
|
||||
[Environment]::SetEnvironmentVariable(($key.Replace('_LINKER', '_RUSTFLAGS')), '-C link-arg=-Wl,-z,max-page-size=16384', 'Process')
|
||||
cargo build --manifest-path $manifest --release --target $t.Rust --locked
|
||||
if ($LASTEXITCODE -ne 0) { throw "Rust build failed: $($t.Rust). Install rust target separately if missing." }
|
||||
$out = Join-Path $project "app/src/main/jniLibs/$($t.Abi)"
|
||||
New-Item -ItemType Directory -Force $out | Out-Null
|
||||
Copy-Item -LiteralPath (Join-Path $project "native/target/$($t.Rust)/release/libads_android.so") -Destination (Join-Path $out 'libads_android.so')
|
||||
}
|
||||
Reference in new issue
Block a user