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 | |
| parent | 7298699afb4e2baf50978cda9b2cc8822170301b (diff) | |
resolve review comments
| -rw-r--r-- | tests/projects/android/native_app/android/AndroidManifest.xml (renamed from tests/projects/c++/ndk_raylib/android/AndroidManifest.xml) | 0 | ||||
| -rw-r--r-- | tests/projects/android/native_app/android/debug.jks (renamed from tests/projects/c++/ndk_raylib/android/debug.jks) | bin | 2487 -> 2487 bytes | |||
| -rw-r--r-- | tests/projects/android/native_app/android/res/mipmap-mdpi/icon.png (renamed from tests/projects/c++/ndk_raylib/android/res/mipmap-mdpi/icon.png) | bin | 2643 -> 2643 bytes | |||
| -rw-r--r-- | tests/projects/android/native_app/android/res/mipmap/icon.png (renamed from tests/projects/c++/ndk_raylib/android/res/mipmap/icon.png) | bin | 2643 -> 2643 bytes | |||
| -rw-r--r-- | tests/projects/android/native_app/android/res/values/strings.xml (renamed from tests/projects/c++/ndk_raylib/android/res/values/strings.xml) | 0 | ||||
| -rw-r--r-- | tests/projects/android/native_app/android/res/values/styles.xml (renamed from tests/projects/c++/ndk_raylib/android/res/values/styles.xml) | 0 | ||||
| -rw-r--r-- | tests/projects/android/native_app/src/main.cpp (renamed from tests/projects/c++/ndk_raylib/src/main.cpp) | 0 | ||||
| -rw-r--r-- | tests/projects/android/native_app/xmake.lua | 18 | ||||
| -rw-r--r-- | tests/projects/c++/ndk_raylib/xmake.lua | 22 | ||||
| -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 |
14 files changed, 58 insertions, 65 deletions
diff --git a/tests/projects/c++/ndk_raylib/android/AndroidManifest.xml b/tests/projects/android/native_app/android/AndroidManifest.xml index 40cfd7066..40cfd7066 100644 --- a/tests/projects/c++/ndk_raylib/android/AndroidManifest.xml +++ b/tests/projects/android/native_app/android/AndroidManifest.xml diff --git a/tests/projects/c++/ndk_raylib/android/debug.jks b/tests/projects/android/native_app/android/debug.jks Binary files differindex b4eb4f9f2..b4eb4f9f2 100644 --- a/tests/projects/c++/ndk_raylib/android/debug.jks +++ b/tests/projects/android/native_app/android/debug.jks diff --git a/tests/projects/c++/ndk_raylib/android/res/mipmap-mdpi/icon.png b/tests/projects/android/native_app/android/res/mipmap-mdpi/icon.png Binary files differindex 743413831..743413831 100644 --- a/tests/projects/c++/ndk_raylib/android/res/mipmap-mdpi/icon.png +++ b/tests/projects/android/native_app/android/res/mipmap-mdpi/icon.png diff --git a/tests/projects/c++/ndk_raylib/android/res/mipmap/icon.png b/tests/projects/android/native_app/android/res/mipmap/icon.png Binary files differindex 743413831..743413831 100644 --- a/tests/projects/c++/ndk_raylib/android/res/mipmap/icon.png +++ b/tests/projects/android/native_app/android/res/mipmap/icon.png diff --git a/tests/projects/c++/ndk_raylib/android/res/values/strings.xml b/tests/projects/android/native_app/android/res/values/strings.xml index e98a18284..e98a18284 100644 --- a/tests/projects/c++/ndk_raylib/android/res/values/strings.xml +++ b/tests/projects/android/native_app/android/res/values/strings.xml diff --git a/tests/projects/c++/ndk_raylib/android/res/values/styles.xml b/tests/projects/android/native_app/android/res/values/styles.xml index 621547380..621547380 100644 --- a/tests/projects/c++/ndk_raylib/android/res/values/styles.xml +++ b/tests/projects/android/native_app/android/res/values/styles.xml diff --git a/tests/projects/c++/ndk_raylib/src/main.cpp b/tests/projects/android/native_app/src/main.cpp index 4c8253ead..4c8253ead 100644 --- a/tests/projects/c++/ndk_raylib/src/main.cpp +++ b/tests/projects/android/native_app/src/main.cpp diff --git a/tests/projects/android/native_app/xmake.lua b/tests/projects/android/native_app/xmake.lua new file mode 100644 index 000000000..81ac545e5 --- /dev/null +++ b/tests/projects/android/native_app/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +add_requires("raylib 5.5.0") + +target("raydemo_android") + set_kind("binary") + set_languages("c++17") + add_files("src/main.cpp") + add_packages("raylib") + + add_rules("android.native_app", { + android_sdk_version = "35", + android_manifest = "android/AndroidManifest.xml", + android_res = "android/res", + keystore = "android/debug.jks", + keystore_pass = "123456", + package_name = "com.raylib.demo" + }) diff --git a/tests/projects/c++/ndk_raylib/xmake.lua b/tests/projects/c++/ndk_raylib/xmake.lua deleted file mode 100644 index 08a102d9d..000000000 --- a/tests/projects/c++/ndk_raylib/xmake.lua +++ /dev/null @@ -1,22 +0,0 @@ -add_rules("mode.debug", "mode.release") - - -add_requires("raylib 5.5.0") - -target("raydemo_android") - set_kind("binary") - set_languages("c++17") - add_files("src/main.cpp") - add_packages("raylib") - - if is_plat("android") then - - add_rules("android.native_app", { - android_sdk_version = "35", - android_manifest = "android/AndroidManifest.xml", - android_res = "android/res", - keystore = "android/debug.jks", - keystore_pass = "123456", - package_name = "com.raylib.demo" - }) - end 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 |
