Skip to content

Commit d2b736c

Browse files
authored
Improve android sdk setup (#2588)
load sdk.dir from 'proj.android/local.properties' if it's present
1 parent 27ea87d commit d2b736c

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

1k/1kiss.ps1

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,25 @@ if ($1k.isfile($manifest_file)) {
481481

482482
if($1k.isfile($Global:__1k_user_profile)) {
483483
$1k.println("Loading user build profile: $__1k_user_profile")
484-
$user_profile = ConvertFrom-Props (Get-Content $__1k_user_profile)
485-
foreach($entry in $user_profile.GetEnumerator()) {
484+
$profile_entries = ConvertFrom-Props (Get-Content $__1k_user_profile)
485+
foreach($entry in $profile_entries.GetEnumerator()) {
486486
$manifest[$entry.Key] = $entry.Value
487487
}
488488
}
489489

490+
function unescape_path([string]$Path) {
491+
return ($Path -replace '\\:', ':') -replace '\\\\', '\'
492+
}
493+
494+
$Script:preferred_sdk_dir = $null
495+
if($1k.isfile($Global:__1k_android_local_profile)) {
496+
$1k.println("Loading android local profile: $__1k_android_local_profile")
497+
$profile_entries = ConvertFrom-Props (Get-Content $__1k_android_local_profile)
498+
if ($profile_entries.Contains('sdk.dir')) {
499+
$Script:preferred_sdk_dir = unescape_path $profile_entries['sdk.dir']
500+
}
501+
}
502+
490503
$install_prefix = if ($options.prefix) { $options.prefix } else { Join-Path $HOME '.1kiss' }
491504
if (!$1k.isdir($install_prefix)) {
492505
$1k.mkdirs($install_prefix)
@@ -1278,12 +1291,16 @@ function setup_android_sdk() {
12781291
$ndk_ver = $ndk_ver.Substring(0, $ndk_ver.Length - 1)
12791292
}
12801293

1281-
$__1k_sdk_root = Join-Path $install_prefix 'adt/sdk'
1282-
12831294
$sdk_dirs = @()
1284-
$1k.insert([ref]$sdk_dirs, $env:ANDROID_HOME)
1285-
$1k.insert([ref]$sdk_dirs, $env:ANDROID_SDK_ROOT)
1286-
$1k.insert([ref]$sdk_dirs, $__1k_sdk_root)
1295+
if ($Script:preferred_sdk_dir) {
1296+
$1k.println("Add preferred android sdk dir: $Script:preferred_sdk_dir")
1297+
$sdk_dirs += $Script:preferred_sdk_dir
1298+
} else {
1299+
$__1k_sdk_root = Join-Path $install_prefix 'adt/sdk'
1300+
$1k.insert([ref]$sdk_dirs, $env:ANDROID_HOME)
1301+
$1k.insert([ref]$sdk_dirs, $env:ANDROID_SDK_ROOT)
1302+
$1k.insert([ref]$sdk_dirs, $__1k_sdk_root)
1303+
}
12871304

12881305
$ndk_minor_base = [int][char]'a'
12891306

@@ -1337,8 +1354,9 @@ function setup_android_sdk() {
13371354
}
13381355
}
13391356

1340-
if(!$sdk_root) {
1341-
$sdk_root = Join-Path $install_prefix 'adt/sdk'
1357+
if (!$sdk_root) {
1358+
$sdk_root = $Script:preferred_sdk_dir
1359+
if (!$sdk_root) { Join-Path $install_prefix 'adt/sdk' }
13421360
$1k.mkdirs($sdk_root)
13431361
}
13441362

tools/cmdline/build.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ if($Global:is_axmol_app) {
103103
$Global:__1k_user_profile = Join-Path $source_proj_dir '.axproj'
104104
}
105105

106+
# the android local.properties generated by android studio
107+
$ax_app_android_profile = Join-Path $source_proj_dir 'proj.android/local.properties'
108+
if (Test-Path $ax_app_android_profile -PathType Leaf) {
109+
$Global:__1k_android_local_profile = $ax_app_android_profile
110+
}
111+
106112
# start construct full cmd line
107113
$1k_args = @()
108114

0 commit comments

Comments
 (0)