From 12b330e4ecc8149230c7c594b0de75bb42b02441 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 28 Feb 2023 15:49:34 +0100 Subject: [PATCH] Add support for building Android app on Linux or Mac --- .../Platform/Android/AndroidPlatformTools.cpp | 5 +++- Source/Editor/Editor.Build.cs | 2 ++ Source/Editor/Windows/GameCookerWindow.cs | 2 ++ .../Engine/Platform/Linux/LinuxPlatform.cpp | 24 +++++++++++++++++++ Source/Engine/Platform/Linux/LinuxPlatform.h | 1 + 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp index 6610f2295..8e3e91b51 100644 --- a/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/Android/AndroidPlatformTools.cpp @@ -304,10 +304,13 @@ bool AndroidPlatformTools::OnPostProcess(CookingData& data) const Char* gradlew = TEXT("gradlew.bat"); #else const Char* gradlew = TEXT("gradlew"); +#endif +#if PLATFORM_LINUX + Platform::RunProcess(String::Format(TEXT("chmod +x \"{0}/gradlew\""), data.OriginalOutputPath), data.OriginalOutputPath, Dictionary(), true); #endif const bool distributionPackage = buildSettings->ForDistribution; const String gradleCommand = String::Format(TEXT("\"{0}\" {1}"), data.OriginalOutputPath / gradlew, distributionPackage ? TEXT("assemble") : TEXT("assembleDebug")); - const int32 result = Platform::RunProcess(gradleCommand, data.OriginalOutputPath, envVars, true); + const int32 result = Platform::RunProcess(gradleCommand, data.OriginalOutputPath, Dictionary(), true); if (result != 0) { data.Error(TEXT("Failed to build Gradle project into package (result code: {0}). See log for more info."), result); diff --git a/Source/Editor/Editor.Build.cs b/Source/Editor/Editor.Build.cs index 0b69e8aa3..91785036e 100644 --- a/Source/Editor/Editor.Build.cs +++ b/Source/Editor/Editor.Build.cs @@ -66,10 +66,12 @@ public class Editor : EditorModule else if (options.Platform.Target == TargetPlatform.Linux) { AddPlatformTools(options, platformToolsRoot, platformToolsRootExternal, "Linux", "PLATFORM_TOOLS_LINUX"); + AddPlatformTools(options, platformToolsRoot, platformToolsRootExternal, "Android", "PLATFORM_TOOLS_ANDROID"); } else if (options.Platform.Target == TargetPlatform.Mac) { AddPlatformTools(options, platformToolsRoot, platformToolsRootExternal, "Mac", "PLATFORM_TOOLS_MAC"); + AddPlatformTools(options, platformToolsRoot, platformToolsRootExternal, "Android", "PLATFORM_TOOLS_ANDROID"); } // Visual Studio integration diff --git a/Source/Editor/Windows/GameCookerWindow.cs b/Source/Editor/Windows/GameCookerWindow.cs index 338eebe3e..0c602422b 100644 --- a/Source/Editor/Windows/GameCookerWindow.cs +++ b/Source/Editor/Windows/GameCookerWindow.cs @@ -119,6 +119,7 @@ namespace FlaxEditor.Windows switch (BuildPlatform) { case BuildPlatform.LinuxX64: + case BuildPlatform.AndroidARM64: IsSupported = true; break; default: @@ -129,6 +130,7 @@ namespace FlaxEditor.Windows switch (BuildPlatform) { case BuildPlatform.MacOSx64: + case BuildPlatform.AndroidARM64: IsSupported = true; break; default: diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 783af803d..429fc78cb 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -2755,6 +2755,30 @@ Window* LinuxPlatform::CreateWindow(const CreateWindowSettings& settings) return New(settings); } +extern char **environ; + +void LinuxPlatform::GetEnvironmentVariables(Dictionary& result) +{ + char **s = environ; + for (; *s; s++) + { + char* var = *s; + int32 split = -1; + for (int32 i = 0; var[i]; i++) + { + if (var[i] == '=') + { + split = i; + break; + } + } + if (split == -1) + result[String(var)] = String::Empty; + else + result[String(var, split)] = String(var + split + 1); + } +} + bool LinuxPlatform::GetEnvironmentVariable(const String& name, String& value) { char* env = getenv(StringAsANSI<>(*name).Get()); diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.h b/Source/Engine/Platform/Linux/LinuxPlatform.h index e41031f7a..89afe9292 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.h +++ b/Source/Engine/Platform/Linux/LinuxPlatform.h @@ -131,6 +131,7 @@ public: static String GetWorkingDirectory(); static bool SetWorkingDirectory(const String& path); static Window* CreateWindow(const CreateWindowSettings& settings); + static void GetEnvironmentVariables(Dictionary& result); static bool GetEnvironmentVariable(const String& name, String& value); static bool SetEnvironmentVariable(const String& name, const String& value); static int32 StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow = false, bool waitForEnd = false);