Skip to content

Commit 8a4bc98

Browse files
Add linux-bionic RID Export Option
Adds an export option to enable the linux-bionic RID so Android can export with NativeAOT enabled.
1 parent 71d80b2 commit 8a4bc98

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,28 @@ public override string[] _GetExportFeatures(EditorExportPlatform platform, bool
3737

3838
public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetExportOptions(EditorExportPlatform platform)
3939
{
40-
return new Godot.Collections.Array<Godot.Collections.Dictionary>()
40+
var exportOptionList = new Godot.Collections.Array<Godot.Collections.Dictionary>();
41+
42+
if (platform.GetOsName().Equals(OS.Platforms.Android, StringComparison.OrdinalIgnoreCase))
4143
{
44+
exportOptionList.Add
45+
(
46+
new Godot.Collections.Dictionary()
47+
{
48+
{
49+
"option", new Godot.Collections.Dictionary()
50+
{
51+
{ "name", "dotnet/android_use_linux_bionic" },
52+
{ "type", (int)Variant.Type.Bool }
53+
}
54+
},
55+
{ "default_value", false }
56+
}
57+
);
58+
}
59+
60+
exportOptionList.Add
61+
(
4262
new Godot.Collections.Dictionary()
4363
{
4464
{
@@ -49,7 +69,10 @@ public override string[] _GetExportFeatures(EditorExportPlatform platform, bool
4969
}
5070
},
5171
{ "default_value", false }
52-
},
72+
}
73+
);
74+
exportOptionList.Add
75+
(
5376
new Godot.Collections.Dictionary()
5477
{
5578
{
@@ -60,7 +83,10 @@ public override string[] _GetExportFeatures(EditorExportPlatform platform, bool
6083
}
6184
},
6285
{ "default_value", true }
63-
},
86+
}
87+
);
88+
exportOptionList.Add
89+
(
6490
new Godot.Collections.Dictionary()
6591
{
6692
{
@@ -72,7 +98,8 @@ public override string[] _GetExportFeatures(EditorExportPlatform platform, bool
7298
},
7399
{ "default_value", false }
74100
}
75-
};
101+
);
102+
return exportOptionList;
76103
}
77104

78105
private void AddExceptionMessage(EditorExportPlatform platform, Exception exception)
@@ -158,11 +185,12 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
158185
throw new NotImplementedException("Target platform not yet implemented.");
159186
}
160187

188+
bool useAndroidLinuxBionic = (bool)GetOption("dotnet/android_use_linux_bionic");
161189
PublishConfig publishConfig = new()
162190
{
163191
BuildConfig = isDebug ? "ExportDebug" : "ExportRelease",
164192
IncludeDebugSymbols = (bool)GetOption("dotnet/include_debug_symbols"),
165-
RidOS = DetermineRuntimeIdentifierOS(platform),
193+
RidOS = DetermineRuntimeIdentifierOS(platform, useAndroidLinuxBionic),
166194
Archs = new List<string>(),
167195
UseTempDir = platform != OS.Platforms.iOS, // xcode project links directly to files in the publish dir, so use one that sticks around.
168196
BundleOutputs = true,
@@ -335,6 +363,14 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
335363

336364
if (IsSharedObject(fileName))
337365
{
366+
if (fileName.EndsWith(".so") && !fileName.StartsWith("lib"))
367+
{
368+
// Add 'lib' prefix required for all native libraries in Android.
369+
string newPath = string.Concat(path.AsSpan(0, path.Length - fileName.Length), "lib", fileName);
370+
Godot.DirAccess.RenameAbsolute(path, newPath);
371+
path = newPath;
372+
}
373+
338374
AddSharedObject(path, tags: new string[] { arch },
339375
Path.Join(projectDataDirName,
340376
Path.GetRelativePath(publishOutputDir,
@@ -450,8 +486,14 @@ private string SanitizeSlashes(string path)
450486
return path;
451487
}
452488

453-
private string DetermineRuntimeIdentifierOS(string platform)
454-
=> OS.DotNetOSPlatformMap[platform];
489+
private string DetermineRuntimeIdentifierOS(string platform, bool useAndroidLinuxBionic)
490+
{
491+
if (platform == OS.Platforms.Android && useAndroidLinuxBionic)
492+
{
493+
return OS.DotNetOS.LinuxBionic;
494+
}
495+
return OS.DotNetOSPlatformMap[platform];
496+
}
455497

456498
private string DetermineRuntimeIdentifierArch(string arch)
457499
{

modules/mono/editor/GodotTools/GodotTools/Utils/OS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static class DotNetOS
5555
public const string Linux = "linux";
5656
public const string Win10 = "win10";
5757
public const string Android = "android";
58+
public const string LinuxBionic = "linux-bionic";
5859
public const string iOS = "ios";
5960
public const string iOSSimulator = "iossimulator";
6061
public const string Browser = "browser";
@@ -99,7 +100,6 @@ public static class DotNetOS
99100
[Platforms.iOS] = DotNetOS.iOS,
100101
[Platforms.Web] = DotNetOS.Browser
101102
};
102-
103103
private static bool IsOS(string name)
104104
{
105105
Internal.godot_icall_Utils_OS_GetPlatformName(out godot_string dest);

modules/mono/mono_gd/gd_mono.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ godot_plugins_initialize_fn try_load_native_aot_library(void *&r_aot_dll_handle)
416416
String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".dll");
417417
#elif defined(MACOS_ENABLED) || defined(IOS_ENABLED)
418418
String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".dylib");
419+
#elif defined(ANDROID_ENABLED)
420+
String native_aot_so_path = "lib" + assembly_name + ".so";
419421
#elif defined(UNIX_ENABLED)
420422
String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".so");
421423
#else

platform/android/export/export_plugin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,6 +2058,9 @@ bool EditorExportPlatformAndroid::get_export_option_visibility(const EditorExpor
20582058
return false;
20592059
}
20602060

2061+
if (p_option == "dotnet/android_use_linux_bionic") {
2062+
return advanced_options_enabled;
2063+
}
20612064
return true;
20622065
}
20632066

0 commit comments

Comments
 (0)