Explorar o código

Merge pull request #84440 from Calinou/scons-android-add-generate-apk-option

Add `generate_apk=yes` to generate an APK after building
Rémi Verschelde hai 1 ano
pai
achega
2966db7d76
Modificáronse 2 ficheiros con 29 adicións e 0 borrados
  1. 1 0
      SConstruct
  2. 28 0
      platform/android/SCsub

+ 1 - 0
SConstruct

@@ -182,6 +182,7 @@ opts.Add(BoolVariable("debug_symbols", "Build with debugging symbols", False))
 opts.Add(BoolVariable("separate_debug_symbols", "Extract debugging symbols to a separate file", False))
 opts.Add(BoolVariable("separate_debug_symbols", "Extract debugging symbols to a separate file", False))
 opts.Add(EnumVariable("lto", "Link-time optimization (production builds)", "none", ("none", "auto", "thin", "full")))
 opts.Add(EnumVariable("lto", "Link-time optimization (production builds)", "none", ("none", "auto", "thin", "full")))
 opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False))
 opts.Add(BoolVariable("production", "Set defaults to build Godot for use in production", False))
+opts.Add(BoolVariable("generate_apk", "Generate an APK/AAB after building Android library by calling Gradle", False))
 
 
 # Components
 # Components
 opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated and removed features", True))
 opts.Add(BoolVariable("deprecated", "Enable compatibility code for deprecated and removed features", True))

+ 28 - 0
platform/android/SCsub

@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 #!/usr/bin/env python
 
 
+import subprocess
+
 Import("env")
 Import("env")
 
 
 android_files = [
 android_files = [
@@ -77,3 +79,29 @@ if lib_arch_dir != "":
         str(env["ANDROID_NDK_ROOT"]) + "/sources/cxx-stl/llvm-libc++/libs/" + lib_arch_dir + "/libc++_shared.so"
         str(env["ANDROID_NDK_ROOT"]) + "/sources/cxx-stl/llvm-libc++/libs/" + lib_arch_dir + "/libc++_shared.so"
     )
     )
     env_android.Command(out_dir + "/libc++_shared.so", stl_lib_path, Copy("$TARGET", "$SOURCE"))
     env_android.Command(out_dir + "/libc++_shared.so", stl_lib_path, Copy("$TARGET", "$SOURCE"))
+
+    def generate_apk(target, source, env):
+        if env["target"] != "editor" and env["dev_build"]:
+            subprocess.run(
+                [
+                    "./gradlew",
+                    "generateDevTemplate",
+                    "--quiet",
+                ],
+                cwd="platform/android/java",
+            )
+        else:
+            # Android editor with `dev_build=yes` is handled by the `generateGodotEditor` task.
+            subprocess.run(
+                [
+                    "./gradlew",
+                    "generateGodotEditor" if env["target"] == "editor" else "generateGodotTemplates",
+                    "--quiet",
+                ],
+                cwd="platform/android/java",
+            )
+
+    if env["generate_apk"]:
+        generate_apk_command = env_android.Command("generate_apk", [], generate_apk)
+        command = env_android.AlwaysBuild(generate_apk_command)
+        env_android.Depends(command, [lib])