Repository navigation
Description
I'm trying to run react native in a monorepo, and if I run the project with the old 2.9 version, I can run in development mode, if I override the native_modules.gradle-file like this:
- def command = "node ./node_modules/react-native/cli.js config"
+ def command = "../../node_modules/react-native/cli.js config"As well as run react-native start in my mobile folder, and run-android in my root folder in a separate terminal window.
But then can't build for production, due to it not finding the node_modules/react-native/cli.js-file when I run with the --variant=release flag.
Now I've upgraded to version 3.0.1 of the @react-native-community/cli package, And added a configuration file in my root folder like so:
// react-native.config.js
module.exports = {
project: {
android: {
sourceDir: './packages/mobile/android',
},
ios: {
project: './packages/mobile/ios/mobile.xcodeproj',
},
},
}Then I run yarn react-native run-android --root packages/mobile from root.
However, it keeps complaining about my configuration.
React Native CLI failed to determine Android project configuration. This is likely due to misconfiguration. Config output: <config output>
If I run react-native config in my root directory, this is what I get:
{
"root": "C:\\Users\\glink\\Documents\\projects\\my-project",
"reactNativePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\node_modules\\react-native",
"dependencies": {},
"commands": [<commands omittted for brevity>],
"assets": [],
"platforms": {
"ios": {},
"android": {}
},
"haste": {
"providesModuleNodeModules": [
"react-native"
],
"platforms": [
"ios",
"android"
]
},
"project": {
"ios": {
"sourceDir": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios",
"folder": "C:\\Users\\glink\\Documents\\projects\\my-project",
"pbxprojPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios\\mobile.xcodeproj\\project.pbxproj",
"podfile": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios\\Podfile",
"podspecPath": null,
"projectPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\ios\\mobile.xcodeproj",
"projectName": "mobile.xcodeproj",
"libraryFolder": "Libraries",
"sharedLibraries": [],
"plist": [],
"scriptPhases": []
},
"android": {
"sourceDir": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android",
"isFlat": true,
"folder": "C:\\Users\\glink\\Documents\\projects\\my-project",
"stringsPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\src\\main\\res\\values\\strings.xml",
"manifestPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\app\\src\\main\\AndroidManifest.xml",
"buildGradlePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\build.gradle",
"settingsGradlePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\android\\settings.gradle",
"assetsPath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\src\\main\\assets",
"mainFilePath": "C:\\Users\\glink\\Documents\\projects\\my-project\\packages\\mobile\\android\\src\\main\\java\\com\\mobile\\MainApplication.java",
"packageName": "com.mobile"
}
}
}
Activity
grabbou commentedon Nov 19, 2019
Hey,
I know this may be confusing, but
run-androiddoesn't use thereact-native configyet. That's what @thymikee is working on in his PR: #791. It has its own historical resolution mechanism and that's why it doesn't take into account your paths.I would recommend you to drop custom React Native configuration and just run the CLI from within
packages/mobilefolder instead. This is the standard/recommended approach and also supports multiple React Native apps living side by side.So
cd ./packages/mobile && yarn react-native run-iosshould get you there.Glinkis commentedon Nov 19, 2019
@grabbou
Thanks for the response. I cannot run
yarn react-native run-androidfrom within my./packages/mobile-folder, as react native can then not find the commandrun-android.What I have to do is run
yarn react-native startfrom mymobilefolder, andyarn react-native run-android --root ./packages/mobilefrom the root folder.I've already written this in the original question, though I realize it might be slightly confusing with all the different conditions.
grabbou commentedon Nov 24, 2019
Can you make sure that your
./packages/mobile/package.jsonlistsreact-nativeas a dependency?In CLI 3.x, it's entirely decoupled from Android and iOS. That way, other platforms, such as Windows, can integrate in an easier way.
Now, the CLI detects the presence of a platform by looking up your
package.jsonfor projects. For example, if you have areact-nativedependency listed in yourpackage.json, the CLI will open up this package and load additional commands dynamically, in this case,run-iosandrun-android.You can see how
react-nativedefines additional commands in this file: https://github.com/facebook/react-native/blob/master/react-native.config.jsPS. If you have
react-nativedependency on the root, I recommend moving it down to every package that depends on React Native. Don't worry, Yarn will de-dupe them anyway and hoist.sibelius commentedon Nov 26, 2019
I've solved like this on
native_modules.gradlebviebahn commentedon Dec 2, 2019
Solved it by deleting the entries in yarn.lock as described here:
https://github.com/react-native-community/cli#updating-the-cli
grabbou commentedon Jan 13, 2020
Closing due to lack of response from OP. Will reopen if needed. We're going to remove
npxat all anyway (in my experience,yarnworks better, but we're gonna go for package manager-agnostic solution).#886
joshuapinter commentedon Feb 4, 2021
In our case, we have an atypical structure since we added React Native to an existing Android application years ago. After changing the main app/module name to
appand moving the entire Android application into aandroidsub directory, things started to work without an issue.I'm sure you could configure things to make the non-standard structure work, which we were doing previously, but with the advent of autolinking, the extra hoop jumping didn't feel warranted. So we caved to the defaults and are moving forward now.
LiangRenDev commentedon Feb 8, 2021
I have met the same issue, solved it by yarn install, I think this is caused by I use npm install, anyway I think it is caused by wrong version of react-native-community
DevineDecrypter commentedon Jul 1, 2021
is there a way to add android tv as a platform in the react-native-video's platforms?