Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to determine project configuration #854

Closed
Glinkis opened this issue Nov 18, 2019 · 9 comments
Closed

Fails to determine project configuration #854

Glinkis opened this issue Nov 18, 2019 · 9 comments
Labels
question Further information is requested

Comments

@Glinkis
Copy link

Glinkis commented Nov 18, 2019

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"
    }
  }
}
@Glinkis Glinkis added the question Further information is requested label Nov 18, 2019
@grabbou
Copy link
Member

grabbou commented Nov 19, 2019

Hey,

I know this may be confusing, but run-android doesn't use the react-native config yet. 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/mobile folder 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-ios should get you there.

@Glinkis
Copy link
Author

Glinkis commented Nov 19, 2019

@grabbou
Thanks for the response. I cannot run yarn react-native run-android from within my ./packages/mobile-folder, as react native can then not find the command run-android.

What I have to do is run yarn react-native start from my mobile folder, and yarn react-native run-android --root ./packages/mobile from 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
Copy link
Member

grabbou commented Nov 24, 2019

Thanks for the response. I cannot run yarn react-native run-android from within my ./packages/mobile-folder, as react-native can then not find the command run-android.

Can you make sure that your ./packages/mobile/package.json lists react-native as 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.json for projects. For example, if you have a react-native dependency listed in your package.json, the CLI will open up this package and load additional commands dynamically, in this case, run-ios and run-android.

You can see how react-native defines additional commands in this file: https://github.com/facebook/react-native/blob/master/react-native.config.js

PS. If you have react-native dependency 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
Copy link
Member

I've solved like this on native_modules.gradle

- def command = "${npx} --quiet --no-install react-native config"
+ def command = "yarn --silent react-native config"
` ``

@bviebahn
Copy link

bviebahn commented 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
Copy link
Member

grabbou commented Jan 13, 2020

Closing due to lack of response from OP. Will reopen if needed. We're going to remove npx at all anyway (in my experience, yarn works better, but we're gonna go for package manager-agnostic solution).

#886

@grabbou grabbou closed this as completed Jan 13, 2020
@joshuapinter
Copy link

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 app and moving the entire Android application into a android sub 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
Copy link

LiangRenDev commented 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
Copy link

is there a way to add android tv as a platform in the react-native-video's platforms?

module.exports = {
  assets: ['./assets/fonts'],
  dependencies: {
    'react-native-video': {
      platforms: {
        android: {
          sourceDir: '../node_modules/react-native-video/android-exoplayer',
        },
      },
    },
  },
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

7 participants