Fix android sdk setup in plain new machine

This commit is contained in:
halx99 2023-07-09 23:27:24 +08:00
parent cba35d2b77
commit 235d8cb1ef
1 changed files with 27 additions and 11 deletions

View File

@ -186,9 +186,13 @@ if (!$TOOLCHAIN_VER) {
$TOOLCHAIN_NAME = $TOOLCHAIN
}
function mkdirs($path) {
New-Item $path -ItemType Directory 1>$null
}
$prefix = if ($options.prefix) { $options.prefix } else { Join-Path $HOME 'build1k' }
if (!(Test-Path "$prefix" -PathType Container)) {
mkdir $prefix | Out-Null
mkdirs $prefix
}
b1k_print "proj_dir=$((Get-Location).Path), prefix=$prefix"
@ -203,6 +207,9 @@ function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $param =
$env:PATH = "$path$envPathSep$env:PATH"
}
}
else {
$storedPATH = $null
}
if (!$cmd) { $cmd = $name }
# try get match expr and preferred ver
@ -239,6 +246,12 @@ function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $param =
# find command
$cmd_info = (Get-Command $cmd -ErrorAction SilentlyContinue)
# needs restore immidiately since further cmd invoke maybe require system bins
if ($path) {
$env:PATH = "$path$envPathSep$storedPATH"
}
$found_rets = $null # prog_path,prog_version
if ($cmd_info) {
$prog_path = $cmd_info.Source
@ -278,9 +291,10 @@ function find_prog($name, $path = $null, $mode = 'ONLY', $cmd = $null, $param =
}
}
if ($path) {
if($storedPATH) {
$env:PATH = $storedPATH
}
return $found_rets
}
@ -335,7 +349,7 @@ function setup_cmake() {
}
elseif ($HOST_OS -eq $HOST_LINUX) {
chmod 'u+x' "$cmake_pkg_path"
mkdir $cmake_root
mkdirs $cmake_root
& "$cmake_pkg_path" '--skip-license' '--exclude-subdir' "--prefix=$cmake_root"
}
elseif ($HOST_OS -eq $HOST_MAC) {
@ -375,7 +389,7 @@ function setup_nuget() {
}
if (!(Test-Path -Path $nuget_bin -PathType Container)) {
mkdir $nuget_bin | Out-Null
mkdirs $nuget_bin
}
$nuget_prog = Join-Path $nuget_bin 'nuget.exe'
@ -453,7 +467,7 @@ function setup_glslcc() {
Expand-Archive -Path $glslcc_pkg -DestinationPath $glslcc_bin
}
else {
mkdir -p $glslcc_bin | Out-Null
mkdirs $glslcc_bin
tar xvf "$glslcc_pkg" -C $glslcc_bin
}
}
@ -565,7 +579,7 @@ function setup_android_sdk() {
else {
$sdk_root = Join-Path $prefix 'adt/sdk'
if (!(Test-Path -Path $sdk_root -PathType Container)) {
mkdir $sdk_root
mkdirs $sdk_root
}
}
@ -609,6 +623,7 @@ function setup_android_sdk() {
$ndkFullVer = $ndks[$ndk_ver]
((1..10 | ForEach-Object {"yes"; Start-Sleep -Milliseconds 100}) | . $sdkmanager_prog --licenses --sdk_root=$sdk_root) | Out-Host
exec_prog -prog $sdkmanager_prog -params '--verbose', "--sdk_root=$sdk_root", 'platform-tools', 'cmdline-tools;latest', 'platforms;android-33', 'build-tools;30.0.3', 'cmake;3.22.1', $ndkFullVer | Out-Host
$fullVer = $ndkFullVer.Split(';')[1]
@ -722,6 +737,9 @@ function preprocess_andorid([string[]]$inputOptions) {
$cmake_toolchain_file = "$ndk_root\build\cmake\android.toolchain.cmake"
$arch = $t_archs[$options.a]
$outputOptions += '-G', 'Ninja', '-DANDROID_STL=c++_shared', "-DCMAKE_MAKE_PROGRAM=$ninja_prog", "-DCMAKE_TOOLCHAIN_FILE=$cmake_toolchain_file", "-DANDROID_ABI=$arch"
# If set to ONLY, then only the roots in CMAKE_FIND_ROOT_PATH will be searched
# If set to BOTH, then the host system paths and the paths in CMAKE_FIND_ROOT_PATH will be searched
# If set to NEVER, then the roots in CMAKE_FIND_ROOT_PATH will be ignored and only the host system root will be used
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH'
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH'
$outputOptions += '-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH'
@ -826,17 +844,15 @@ if ($BUILD_TARGET -eq 'win32') {
}
}
elseif ($BUILD_TARGET -eq 'android') {
$null = setup_jdk # setup android sdk cmdlinetools require jdk
$sdk_root, $ndk_root = setup_android_sdk
$env:ANDROID_HOME = $sdk_root
$env:ANDROID_NDK = $ndk_root
# we assume 'gradle' to build apk, so require setup jdk11+
# otherwise, build for android libs, needs setup ninja
if ($options.xt -eq 'gradle') {
$null = setup_jdk
}
else {
if ($options.xt -ne 'gradle') {
$ninja_prog = setup_ninja
}
}
}
if (!$options.setupOnly) {