diff options
| author | Yi Jianlong <[email protected]> | 2025-12-15 10:10:35 +0800 |
|---|---|---|
| committer | Yi Jianlong <[email protected]> | 2025-12-15 15:54:41 +0800 |
| commit | 8e63376d62415825aa2836df19ebb7c895aa7a2e (patch) | |
| tree | e7383f5f288453a47c56d1228505348d25d0da4a /xmake | |
| parent | 7298699afb4e2baf50978cda9b2cc8822170301b (diff) | |
resolve review comments
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/rules/ndk/install.lua | 8 | ||||
| -rw-r--r-- | xmake/rules/ndk/load.lua | 10 | ||||
| -rw-r--r-- | xmake/rules/ndk/package.lua | 38 | ||||
| -rw-r--r-- | xmake/rules/ndk/run.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/ndk/xmake.lua | 21 |
5 files changed, 40 insertions, 43 deletions
diff --git a/xmake/rules/ndk/install.lua b/xmake/rules/ndk/install.lua index 3a1b04342..8dae64ccd 100644 --- a/xmake/rules/ndk/install.lua +++ b/xmake/rules/ndk/install.lua @@ -14,8 +14,8 @@ -- -- Copyright (C) 2015-present, Xmake Open Source Community. -- --- @author Xmake Open Source Community --- @file xmake.lua +-- @author keosu +-- @file install.lua -- function main(target) @@ -26,9 +26,9 @@ function main(target) local final_apk = path.join(target:targetdir(), target:basename() .. ".apk") assert(os.exists(final_apk)) - cprint("${green}[Android][Install] try to install apk ...") + cprint("${color.success}[Android][Install] try to install apk ...") os.vrunv(adb, {"install", final_apk}) - cprint("${green}[Android][Install] done.") + cprint("${color.success}[Android][Install] done.") end diff --git a/xmake/rules/ndk/load.lua b/xmake/rules/ndk/load.lua index 5eaee58aa..8119c31a2 100644 --- a/xmake/rules/ndk/load.lua +++ b/xmake/rules/ndk/load.lua @@ -14,12 +14,10 @@ -- -- Copyright (C) 2015-present, Xmake Open Source Community. -- --- @author Xmake Open Source Community --- @file xmake.lua +-- @author keosu +-- @file load.lua -- -import("core.tool.toolchain") - -- main entry function main (target) @@ -30,10 +28,8 @@ function main (target) raise("NDK path not set! Please set NDK path properly.") end - local native_app_glue_file = path.join(ndk_root, "sources", "android", "native_app_glue", "android_native_app_glue.c") - -- Add glue file to target - local conf = target:extraconf("rules", "android.native_app") + local native_app_glue_file = path.join(ndk_root, "sources", "android", "native_app_glue", "android_native_app_glue.c") target:add("files", native_app_glue_file) target:add("includedirs", native_app_glue_path) diff --git a/xmake/rules/ndk/package.lua b/xmake/rules/ndk/package.lua index 227afaaa8..795b87d0d 100644 --- a/xmake/rules/ndk/package.lua +++ b/xmake/rules/ndk/package.lua @@ -14,14 +14,13 @@ -- -- Copyright (C) 2015-present, Xmake Open Source Community. -- --- @author Xmake Open Source Community --- @file xmake.lua +-- @author keosu +-- @file package.lua -- - import("core.tool.toolchain") function main(target) - local conf = target:extraconf("rules", "android.native_app") + local conf = target:extraconf("rules", "android.native_app") local android_sdk_version = conf.android_sdk_version local android_manifest = conf.android_manifest local android_res = conf.android_res @@ -32,66 +31,65 @@ function main(target) assert(android_sdk_version, "android sdk version not set") assert(android_manifest, "android manifest not set") - cprint("${green}[Android][Package]${white} Starting...") + cprint("${color.success}[Android][Package]${clear} Starting...") local tmp_path = path.join(target:targetdir(), "temp") - os.mkdir(tmp_path) - os.mkdir(path.join(tmp_path, "lib")) + os.mkdir(tmp_path) + os.mkdir(path.join(tmp_path, "lib")) os.mkdir(path.join(tmp_path, "lib", target:arch())) -- copy the target library to temp folder with name libmain.so local libfile = path.join(tmp_path, "lib", target:arch(), "libmain.so") os.cp(target:targetfile(), libfile) - -- get android tool path local android_sdkdir = target:toolchain("ndk"):config("android_sdk") local android_build_toolver = target:toolchain("ndk"):config("build_toolver") local sdk_tool_path = path.join(android_sdkdir, "build-tools", android_build_toolver) - local aapt = path.join(sdk_tool_path, "aapt" .. (is_host("windows") and ".exe" or "")) + local aapt = path.join(sdk_tool_path, "aapt" .. (is_host("windows") and ".exe" or "")) local zipalign = path.join(sdk_tool_path, "zipalign" .. (is_host("windows") and ".exe" or "")) local apksigner = path.join(sdk_tool_path, "apksigner" .. (is_host("windows") and ".bat" or "")) -- pack resources - local resonly_apk = path.join(tmp_path, "res_only.apk") + local resonly_apk = path.join(tmp_path, "res_only.apk") local androidjar = path.join(android_sdkdir, "platforms", string.format("android-%s", android_sdk_version), "android.jar") assert(os.exists(androidjar), "%s not found", androidjar) local aapt_argv = {"package", "-f", "-M", android_manifest, "-I", androidjar, "-F", resonly_apk} - if android_res ~= nil and os.exists(android_res) then + if android_res and not os.emptydir(android_res) then table.insert(aapt_argv, "-S") table.insert(aapt_argv, android_res) end - if android_assets ~= nil and os.exists(android_assets) and os.emptydir(android_assets) == false then + if android_assets and not os.emptydir(android_assets) then table.insert(aapt_argv, "-A") table.insert(aapt_argv, android_assets) end - cprint("${green}[Android][Packing resources]${white} Create a resource only apk...") + cprint("${color.success}[Android][Packing resources]${clear} Create a resource only apk...") os.vrunv(aapt, aapt_argv) -- pack libs - cprint("${green}[Android][Packing library]${white} Adding library to res_only.apk...") + cprint("${color.success}[Android][Packing library]${clear} Adding library to res_only.apk...") os.vrunv(aapt, {"add", "res_only.apk", "lib/" .. target:arch() .."/libmain.so"}, {curdir = tmp_path}) -- align apk - local aligned_apk = path.join(tmp_path, "unsigned.apk") + local aligned_apk = path.join(tmp_path, "unsigned.apk") local zipalign_argv = {"-f", "4", "res_only.apk", "unsigned.apk"} - cprint("${green}[Android][Align apk]${white} Save to " .. aligned_apk .. "...") - os.vrunv(zipalign, zipalign_argv, {curdir = tmp_path}) + cprint("${color.success}[Android][Align apk]${clear} Save to " .. aligned_apk .. "...") + os.vrunv(zipalign, zipalign_argv, {curdir = tmp_path}) -- sign apk local final_apk = path.join(target:targetdir(), target:basename() .. ".apk") local apksigner_argv = {"sign", "--ks", keystore, "--ks-pass", string.format("pass:%s", keystore_pass), "--out", final_apk, "--in", aligned_apk} - cprint("${green}[Android][Signing apk]${white} Save to " .. final_apk .. "...") + cprint("${color.success}[Android][Signing apk]${clear} Save to " .. final_apk .. "...") os.vrunv(apksigner, apksigner_argv) - cprint("${green}[Android][Package]${white} Done!") - + cprint("${color.success}[Android][Package]${clear} Done!") + end diff --git a/xmake/rules/ndk/run.lua b/xmake/rules/ndk/run.lua index 08751021a..1c08099bd 100644 --- a/xmake/rules/ndk/run.lua +++ b/xmake/rules/ndk/run.lua @@ -14,8 +14,8 @@ -- -- Copyright (C) 2015-present, Xmake Open Source Community. -- --- @author Xmake Open Source Community --- @file xmake.lua +-- @author keosu +-- @file run.lua -- function main(target) @@ -29,7 +29,7 @@ function main(target) local run_argv = {"shell", "am", "start", "-n", package_name .. "/" .. activity_name} - cprint("${green}[Android] Starting app ...") + cprint("${color.success}[Android] Starting app ...") os.vrunv(adb, run_argv) end diff --git a/xmake/rules/ndk/xmake.lua b/xmake/rules/ndk/xmake.lua index 2779a0665..313c57c05 100644 --- a/xmake/rules/ndk/xmake.lua +++ b/xmake/rules/ndk/xmake.lua @@ -14,20 +14,23 @@ -- -- Copyright (C) 2015-present, Xmake Open Source Community. -- --- @author Xmake Open Source Community +-- @author keosu -- @file xmake.lua -- -- define rule: build android native app with NDK rule("android.native_app") - -- we must set_kind and add some glue files to target - on_load("load") + -- this rule only for android target + if is_plat("android") then + -- we must set_kind and add some glue files to target + on_load("load") - -- generate android apk package - on_package("package") + -- generate android apk package + on_package("package") - -- install android package with adb - on_install("install") + -- install android package with adb + on_install("install") - -- run android app through adb - after_install("run")
\ No newline at end of file + -- run android app through adb + after_install("run") + end
\ No newline at end of file |
