diff --git a/packages/platform-android/native_modules.gradle b/packages/platform-android/native_modules.gradle index 3e925a62e..e7e00e20a 100644 --- a/packages/platform-android/native_modules.gradle +++ b/packages/platform-android/native_modules.gradle @@ -54,8 +54,8 @@ class ReactNativeModules { private ArrayList> reactNativeModules private static String LOG_PREFIX = ":ReactNative:" - private static String REACT_NATIVE_CLI_BIN = "node_modules${File.separator}@react-native-community${File.separator}cli${File.separator}build${File.separator}index.js" - private static String REACT_NATIVE_CONFIG_CMD = "node ${REACT_NATIVE_CLI_BIN} config" + private static String REACT_NATIVE_CONFIG_CMD = "yarn run --silent react-native config" + private static String REACT_NATIVE_CONFIG_CMD_FALLBACK = "node ./node_modules/.bin/react-native config" ReactNativeModules(Logger logger) { this.logger = logger @@ -173,9 +173,17 @@ class ReactNativeModules { ArrayList> reactNativeModules = new ArrayList>() def cmdProcess + def root = getReactNativeProjectRoot() + def command = REACT_NATIVE_CONFIG_CMD_FALLBACK try { - cmdProcess = Runtime.getRuntime().exec(REACT_NATIVE_CONFIG_CMD, null, getReactNativeProjectRoot()) + try { + // Check if project uses Yarn + def isYarnProject = Runtime.getRuntime().exec("node -e console.log(require.resolve('./yarn.lock'))", null, root) + isYarnProject.waitFor() + command = REACT_NATIVE_CONFIG_CMD + } catch(Exception exception) {} + cmdProcess = Runtime.getRuntime().exec(command, null, root) cmdProcess.waitFor() } catch (Exception exception) { this.logger.warn("${LOG_PREFIX}${exception.message}") diff --git a/packages/platform-ios/native_modules.rb b/packages/platform-ios/native_modules.rb index 63d8c296e..0df725e74 100644 --- a/packages/platform-ios/native_modules.rb +++ b/packages/platform-ios/native_modules.rb @@ -5,12 +5,20 @@ # def use_native_modules!(root = "..", packages = nil) if (!packages) - # Resolve the CLI's main index file - cli_bin = Pod::Executable.execute_command("node", ["-e", "console.log(require.resolve('@react-native-community/cli/build/index.js'))"], true).strip + command = "node" + args = ["./node_modules/.bin/react-native", "config"] + begin + # Check if project uses Yarn + Pod::Executable.execute_command("node", ["-e", "console.log(require.resolve('#{root}/yarn.lock'))"], true) + command = "yarn" + args = ["run", "--silent", "react-native", "config"] + rescue + end + output = "" # Make sure `react-native config` is ran from your project root Dir.chdir(root) do - output = Pod::Executable.execute_command("node", [cli_bin, "config"], true) + output = Pod::Executable.execute_command(command, args, true) end json = []