From d526d523b4469ff84b30e22ca14b83d4b5191783 Mon Sep 17 00:00:00 2001
From: Raul Santos <raulsntos@gmail.com>
Date: Fri, 13 Dec 2024 08:01:13 +0100
Subject: [PATCH] [.NET] Fix gradle builds for multiple ABIs

Include the needed .NET jar in the Godot templates so it's always available, then we don't need to include the jar from a .NET publish which could fail when exporting to multiple architectures because it would attempt to add the same jar for each architecture.
---
 .../GodotTools/GodotTools/Export/ExportPlugin.cs  |  14 ++++++++++++--
 platform/android/java/app/build.gradle            |   5 +----
 ...ystem.Security.Cryptography.Native.Android.jar | Bin
 3 files changed, 13 insertions(+), 6 deletions(-)
 rename {modules/mono/thirdparty => platform/android/java/app/monoLibs}/libSystem.Security.Cryptography.Native.Android.jar (100%)

diff --git a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
index 6fd84d383498..9332d08ed42b 100644
--- a/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
+++ b/modules/mono/editor/GodotTools/GodotTools/Export/ExportPlugin.cs
@@ -323,7 +323,17 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
                                 {
                                     if (platform == OS.Platforms.Android)
                                     {
-                                        if (IsSharedObject(Path.GetFileName(path)))
+                                        string fileName = Path.GetFileName(path);
+
+                                        if (fileName.EndsWith(".jar"))
+                                        {
+                                            // We exclude jar files from the export since they should
+                                            // already be included in the Godot templates, adding them
+                                            // again would cause conflicts.
+                                            return;
+                                        }
+
+                                        if (IsSharedObject(fileName))
                                         {
                                             AddSharedObject(path, tags: new string[] { arch },
                                                 Path.Join(projectDataDirName,
@@ -336,7 +346,7 @@ private void _ExportBeginImpl(string[] features, bool isDebug, string path, long
                                         static bool IsSharedObject(string fileName)
                                         {
                                             if (fileName.EndsWith(".so") || fileName.EndsWith(".a")
-                                             || fileName.EndsWith(".jar") || fileName.EndsWith(".dex"))
+                                             || fileName.EndsWith(".dex"))
                                             {
                                                 return true;
                                             }
diff --git a/platform/android/java/app/build.gradle b/platform/android/java/app/build.gradle
index 308f126d5d15..661e350dae20 100644
--- a/platform/android/java/app/build.gradle
+++ b/platform/android/java/app/build.gradle
@@ -70,10 +70,7 @@ dependencies {
     }
 
     // .NET dependencies
-    String jar = '../../../../modules/mono/thirdparty/libSystem.Security.Cryptography.Native.Android.jar'
-    if (file(jar).exists()) {
-        monoImplementation files(jar)
-    }
+    monoImplementation fileTree(dir: 'monoLibs', include: ['*.jar'])
 }
 
 android {
diff --git a/modules/mono/thirdparty/libSystem.Security.Cryptography.Native.Android.jar b/platform/android/java/app/monoLibs/libSystem.Security.Cryptography.Native.Android.jar
similarity index 100%
rename from modules/mono/thirdparty/libSystem.Security.Cryptography.Native.Android.jar
rename to platform/android/java/app/monoLibs/libSystem.Security.Cryptography.Native.Android.jar