From 4587d14796bfd21be3c677efb2273656876f5241 Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Thu, 26 Sep 2024 15:12:25 -0700 Subject: [PATCH] Add logic to automatically pick up jar/aar library dependencies in the `res://addons` directory --- platform/android/export/export_plugin.cpp | 3 +++ platform/android/java/app/build.gradle | 6 ++++++ platform/android/java/app/config.gradle | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index cfd258cddc3..41f460ca8f3 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -3263,8 +3263,11 @@ Error EditorExportPlatformAndroid::export_project_helper(const Refglobalize_path("res://addons"); + cmdline.push_back("-p"); // argument to specify the start directory. cmdline.push_back(build_path); // start directory. + cmdline.push_back("-Paddons_directory=" + addons_directory); // path to the addon directory as it may contain jar or aar dependencies cmdline.push_back("-Pexport_package_name=" + package_name); // argument to specify the package name. cmdline.push_back("-Pexport_version_code=" + version_code); // argument to specify the version code. cmdline.push_back("-Pexport_version_name=" + version_name); // argument to specify the version name. diff --git a/platform/android/java/app/build.gradle b/platform/android/java/app/build.gradle index fdc57537982..308f126d5d1 100644 --- a/platform/android/java/app/build.gradle +++ b/platform/android/java/app/build.gradle @@ -63,6 +63,12 @@ dependencies { implementation files(pluginsBinaries) } + // Automatically pick up local dependencies in res://addons + String addonsDirectory = getAddonsDirectory() + if (addonsDirectory != null && !addonsDirectory.isBlank()) { + implementation fileTree(dir: "$addonsDirectory", include: ['*.jar', '*.aar']) + } + // .NET dependencies String jar = '../../../../modules/mono/thirdparty/libSystem.Security.Cryptography.Native.Android.jar' if (file(jar).exists()) { diff --git a/platform/android/java/app/config.gradle b/platform/android/java/app/config.gradle index 597a4d5c145..e8921e1bb1f 100644 --- a/platform/android/java/app/config.gradle +++ b/platform/android/java/app/config.gradle @@ -408,3 +408,8 @@ ext.shouldUseLegacyPackaging = { -> // Default behavior for minSdk >= 23 return false } + +ext.getAddonsDirectory = { -> + String addonsDirectory = project.hasProperty("addons_directory") ? project.property("addons_directory") : "" + return addonsDirectory +}