summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-05-09 22:56:07 +0800
committerruki <[email protected]>2019-05-09 11:36:44 +0800
commit29402afc13dc1678661a4ce35efb657eb138dc77 (patch)
tree144940aed2bcde07ca2380a81b5a50b5a2599403
parent1e711f4240904d564062aea9ca9c43d832dcbe61 (diff)
find android sdk
-rw-r--r--xmake/modules/detect/sdks/find_android_sdk.lua108
-rw-r--r--xmake/platforms/android/config.lua13
-rw-r--r--xmake/platforms/android/xmake.lua14
-rw-r--r--xmake/rules/qt/xmake.lua23
4 files changed, 147 insertions, 11 deletions
diff --git a/xmake/modules/detect/sdks/find_android_sdk.lua b/xmake/modules/detect/sdks/find_android_sdk.lua
new file mode 100644
index 000000000..35a415db8
--- /dev/null
+++ b/xmake/modules/detect/sdks/find_android_sdk.lua
@@ -0,0 +1,108 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file find_android_sdk.lua
+--
+
+-- imports
+import("lib.detect.cache")
+import("core.base.option")
+import("core.base.global")
+import("core.project.config")
+import("lib.detect.find_directory")
+
+-- find sdk directory
+function _find_android_sdkdir(sdkdir)
+
+ -- get sdk directory
+ if not sdkdir then
+ sdkdir = os.getenv("ANDROID_SDK_ROOT")
+ if not sdkdir and is_host("macosx") then
+ sdkdir = "~/Library/Android/sdk"
+ end
+ end
+
+ -- get sdk directory
+ if sdkdir and os.isdir(sdkdir) then
+ return sdkdir
+ end
+end
+
+-- find the android sdk
+function _find_android_sdk(sdkdir)
+
+ -- find sdk root directory
+ sdkdir = _find_android_sdkdir(sdkdir)
+ if not sdkdir then
+ return {}
+ end
+
+ -- ok?
+ return {sdkdir = sdkdir}
+end
+
+-- find android sdk directory
+--
+-- @param sdkdir the android sdk directory
+-- @param opt the argument options, e.g. {force = true}
+--
+-- @return the sdk toolchains. .e.g {sdkdir = ..}
+--
+-- @code
+--
+-- local sdk = find_android_sdk("~/Library/Android/sdk")
+--
+-- @endcode
+--
+function main(sdkdir, opt)
+
+ -- init arguments
+ opt = opt or {}
+
+ -- attempt to load cache first
+ local key = "detect.sdks.find_android_sdk"
+ local cacheinfo = cache.load(key)
+ if not opt.force and cacheinfo.sdk and cacheinfo.sdk.sdkdir and os.isdir(cacheinfo.sdk.sdkdir) then
+ return cacheinfo.sdk
+ end
+
+ -- find sdk
+ local sdk = _find_android_sdk(sdkdir or config.get("android_sdk") or global.get("android_sdk"))
+ if sdk and sdk.sdkdir then
+
+ -- save to config
+ config.set("android_sdk", sdk.sdkdir, {force = true, readonly = true})
+
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the Android SDK directory ... ${color.success}%s", sdk.sdkdir)
+ end
+ else
+
+ -- trace
+ if opt.verbose or option.get("verbose") then
+ cprint("checking for the Android SDK directory ... ${color.nothing}${text.nothing}")
+ end
+ end
+
+ -- save to cache
+ cacheinfo.sdk = sdk or false
+ cache.save(key, cacheinfo)
+
+ -- ok?
+ return sdk
+end
diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua
index 860f37e14..246e96291 100644
--- a/xmake/platforms/android/config.lua
+++ b/xmake/platforms/android/config.lua
@@ -22,6 +22,7 @@
import("core.project.config")
import("core.base.singleton")
import("detect.sdks.find_ndk")
+import("detect.sdks.find_android_sdk")
import("private.platform.toolchain")
import("private.platform.check_arch")
import("private.platform.check_toolchain")
@@ -43,6 +44,14 @@ function _check_ndk()
end
end
+-- check the android sdk
+function _check_android_sdk()
+ local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true})
+ if sdk then
+ config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global
+ end
+end
+
-- get toolchains
function _toolchains()
@@ -80,7 +89,6 @@ function _toolchains()
cxx:add({name = "g++", cross = cross}, "clang++")
-- init the c preprocessor
--- cpp:add({name = "cpp", cross = cross, pathes = gcc_toolchain_bin}, "cpp")
cpp:add({name = "gcc -E", cross = cross}, "clang -E")
-- init the assember
@@ -131,6 +139,9 @@ function main(platform, name)
-- check ndk
_check_ndk()
+ -- check android sdk
+ _check_android_sdk()
+
-- check ld and sh, @note toolchains must be initialized after calling check_ndk()
local toolchains = singleton.get("android.toolchains", _toolchains)
check_toolchain(config, "ld", toolchains.ld)
diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua
index 04b18db05..5dc3a6982 100644
--- a/xmake/platforms/android/xmake.lua
+++ b/xmake/platforms/android/xmake.lua
@@ -43,16 +43,18 @@ platform("android")
set_menu {
config =
{
- {category = "Android NDK Configuration" }
- , {nil, "ndk", "kv", nil, "The NDK Directory" }
- , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
+ {category = "Android NDK Configuration" }
+ , {nil, "ndk", "kv", nil, "The NDK Directory" }
+ , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
+ , {nil, "android_sdk", "kv", nil, "The Android SDK Directory" }
}
, global =
{
- {category = "Android NDK Configuration" }
- , {nil, "ndk", "kv", nil, "The NDK Directory" }
- , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
+ {category = "Android NDK Configuration" }
+ , {nil, "ndk", "kv", nil, "The NDK Directory" }
+ , {nil, "ndk_sdkver", "kv", "auto", "The SDK Version for NDK" }
+ , {nil, "android_sdk", "kv", nil, "The Android SDK Directory" }
}
}
diff --git a/xmake/rules/qt/xmake.lua b/xmake/rules/qt/xmake.lua
index 7d6fc74a7..48ff4636d 100644
--- a/xmake/rules/qt/xmake.lua
+++ b/xmake/rules/qt/xmake.lua
@@ -145,7 +145,7 @@ rule("qt.application")
local java_home = assert(os.getenv("JAVA_HOME"), "please set $JAVA_HOME environment variable first!")
-- get android sdk directory
- local android_sdkdir = path.translate(assert(config.get("sdk"), "please run `xmake f --sdk=xxx` to set the android sdk directory!"))
+ local android_sdkdir = path.translate(assert(config.get("android_sdk"), "please run `xmake f --android_sdk=xxx` to set the android sdk directory!"))
-- get the target architecture
local target_archs =
@@ -166,7 +166,13 @@ rule("qt.application")
-- get stdcpp path
local stdcpp_path = path.join(ndk, "sources/cxx-stl/llvm-libc++/libs", target_arch, "libc++_shared.so")
+ -- get toolchain version
+ local ndk_toolchains_ver = config.get("ndk_toolchains_ver") or "4.9"
+
-- generate android-deployment-settings.json file
+ --
+ -- TODO "sdkBuildToolsRevision": "28.0.3",
+ --
local android_deployment_settings = path.join(workdir, "android-deployment-settings.json")
io.writefile(android_deployment_settings, format([[
{
@@ -176,14 +182,14 @@ rule("qt.application")
"ndk": "%s",
"toolchain-prefix": "llvm",
"tool-prefix": "llvm",
- "toolchain-version": "4.9",
+ "toolchain-version": "%s",
"ndk-host": "%s",
"target-architecture": "%s",
"qml-root-path": "%s",
"stdcpp-path": "%s",
"useLLVM": true,
"application-binary": "%s"
- }]], qt.sdkdir, android_sdkdir, ndk, ndk_host, target_arch, os.projectdir(), stdcpp_path, target:targetfile()))
+ }]], qt.sdkdir, android_sdkdir, ndk, ndk_toolchains_ver, ndk_host, target_arch, os.projectdir(), stdcpp_path, target:targetfile()))
-- do deploy
local argv = {"--input", android_deployment_settings,
@@ -210,6 +216,15 @@ rule("qt.application")
-- show install info
print("installing %s ..", target_apk)
+ -- get android sdk directory
+ local android_sdkdir = path.translate(assert(get_config("android_sdk"), "please run `xmake f --android_sdk=xxx` to set the android sdk directory!"))
+
+ -- get adb
+ local adb = path.join(android_sdkdir, "platform-tools", "adb" .. (is_host("windows") and ".exe" or ""))
+ if not os.isexec(adb) then
+ adb = "adb"
+ end
+
-- install apk to device
- os.vrunv("adb", {"install", "-r", target_apk})
+ os.execv(adb, {"install", "-r", target_apk})
end)