diff --git a/docs/autolinking.md b/docs/autolinking.md index 70a3c5d84..5c2174681 100644 --- a/docs/autolinking.md +++ b/docs/autolinking.md @@ -116,6 +116,7 @@ module.exports = { libraryName: null, componentDescriptors: null, androidMkPath: null, + cmakeListsPath: null, }, }, }, diff --git a/docs/dependencies.md b/docs/dependencies.md index ef32d8389..1bdc01adb 100644 --- a/docs/dependencies.md +++ b/docs/dependencies.md @@ -58,6 +58,7 @@ type AndroidDependencyParams = { libraryName?: string | null; componentDescriptors?: string[] | null; androidMkPath?: string | null; + cmakeListsPath?: string | null; }; ``` @@ -140,3 +141,9 @@ An array of custom component descriptor strings. By default they're generated ba > Note: Only applicable when new architecture is turned on. A relative path to a custom _Android.mk_ file not registered by codegen. Relative to `sourceDir`. + +#### platforms.android.cmakeListsPath + +> Note: Only applicable when new architecture is turned on. + +A relative path to a custom _CMakeLists.txt_ file not registered by codegen. Relative to `sourceDir`. diff --git a/docs/platforms.md b/docs/platforms.md index 053ada04f..d15dae887 100644 --- a/docs/platforms.md +++ b/docs/platforms.md @@ -121,5 +121,6 @@ type AndroidDependencyConfig = { libraryName?: string | null; componentDescriptors?: string[] | null; androidMkPath?: string | null; + cmakeListsPath?: string | null; }; ``` diff --git a/packages/cli-config/src/schema.ts b/packages/cli-config/src/schema.ts index 234691f7b..552567d7f 100644 --- a/packages/cli-config/src/schema.ts +++ b/packages/cli-config/src/schema.ts @@ -86,6 +86,7 @@ export const dependencyConfig = t libraryName: t.string().allow(null), componentDescriptors: t.array().items(t.string()).allow(null), androidMkPath: t.string().allow(null), + cmakeListsPath: t.string().allow(null), }) .allow(null), }) @@ -137,6 +138,7 @@ export const projectConfig = t libraryName: t.string().allow(null), componentDescriptors: t.array().items(t.string()).allow(null), androidMkPath: t.string().allow(null), + cmakeListsPath: t.string().allow(null), }) .allow(null), }), diff --git a/packages/cli-platform-android/native_modules.gradle b/packages/cli-platform-android/native_modules.gradle index 7f06fa7e0..4a63eafc5 100644 --- a/packages/cli-platform-android/native_modules.gradle +++ b/packages/cli-platform-android/native_modules.gradle @@ -300,8 +300,13 @@ class ReactNativeModules { if (packages.size() > 0) { libraryIncludes = packages.collect { - if (it.libraryName != null && it.androidMkPath != null) { - // The CMakeLists.txt file is in the same folder as the Android.mk + if (it.libraryName != null && it.cmakeListsPath != null) { + // If user provided a custom cmakeListsPath, let's honor it. + String nativeFolderPath = it.cmakeListsPath.replace("CMakeLists.txt", "") + "add_subdirectory($nativeFolderPath ${it.libraryName}_autolinked_build)" + } else if (it.libraryName != null && it.androidMkPath != null) { + // Fallback to previous behavior: reusing androidMkPath. + // We assume CMakeLists.txt file is in the same folder as the Android.mk String nativeFolderPath = it.androidMkPath.replace("Android.mk", "") "add_subdirectory($nativeFolderPath ${it.libraryName}_autolinked_build)" } else { @@ -470,6 +475,7 @@ class ReactNativeModules { reactNativeModuleConfig.put("libraryName", androidConfig["libraryName"]) reactNativeModuleConfig.put("componentDescriptors", androidConfig["componentDescriptors"]) reactNativeModuleConfig.put("androidMkPath", androidConfig["androidMkPath"]) + reactNativeModuleConfig.put("cmakeListsPath", androidConfig["cmakeListsPath"]) if (androidConfig["buildTypes"] && !androidConfig["buildTypes"].isEmpty()) { reactNativeModulesBuildVariants.put(nameCleansed, androidConfig["buildTypes"]) diff --git a/packages/cli-platform-android/src/config/index.ts b/packages/cli-platform-android/src/config/index.ts index 7c61c6b76..be515f4c8 100644 --- a/packages/cli-platform-android/src/config/index.ts +++ b/packages/cli-platform-android/src/config/index.ts @@ -127,6 +127,9 @@ export function dependencyConfig( const androidMkPath = userConfig.androidMkPath ? path.join(sourceDir, userConfig.androidMkPath) : path.join(sourceDir, 'build/generated/source/codegen/jni/Android.mk'); + const cmakeListsPath = userConfig.cmakeListsPath + ? path.join(sourceDir, userConfig.cmakeListsPath) + : path.join(sourceDir, 'build/generated/source/codegen/jni/CMakeLists.txt'); return { sourceDir, @@ -137,5 +140,6 @@ export function dependencyConfig( libraryName, componentDescriptors, androidMkPath, + cmakeListsPath, }; } diff --git a/packages/cli-types/src/android.ts b/packages/cli-types/src/android.ts index aa2a796f6..8e7b9ba54 100644 --- a/packages/cli-types/src/android.ts +++ b/packages/cli-types/src/android.ts @@ -22,6 +22,7 @@ export type AndroidDependencyConfig = { libraryName?: string | null; componentDescriptors?: string[] | null; androidMkPath?: string | null; + cmakeListsPath?: string | null; }; export type AndroidDependencyParams = { @@ -35,4 +36,5 @@ export type AndroidDependencyParams = { libraryName?: string | null; componentDescriptors?: string[] | null; androidMkPath?: string | null; + cmakeListsPath?: string | null; };