-
Notifications
You must be signed in to change notification settings - Fork 905
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
feat: improve native_module.gradle for certain custom project setups #2341
feat: improve native_module.gradle for certain custom project setups #2341
Conversation
This change include the ability for project to set their own custom path to the actual folder which contains the react-native project. Given we have a consumer app which contains an android project but not actually react-native with the exception of the react-native gradle plugin, the current integration would lead to bunch of build failures. This is because the native_modules.gradle integration assumes that the react native project will be at the same some spot as the gradle root project location. This change is backwards compatible and won't break any templates or existing projects.
This is unnecessary. Instead we should access |
@cortinico I was able to figure out how to use the react plugin root property in the applyNativeModulesAppBuildGradle function. I reverted the signature changes and internally it will work as you've mentioned in your message. But unfortunately I cannot see a working scenario for the applyNativeModulesSettingsGradle function. We've only got the DefaultProject and DefaultSettings available at that point - maybe I'm missing something. Do you have an idea? |
Instead of parsing a path, I changed the signature to pass a file object instead.
The call From |
@cortinico I see what you mean. That won't work in my project setup. This CLI call already requires a root folder defintion but in my case the react-native project sits not within the project root but within a different folder. This is the part I'm referring to: def cliResolveScript = "try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}"
String[] nodeCommand = ["node", "-e", cliResolveScript]
def cliPath = this.getCommandOutput(nodeCommand, this.root)
String[] reactNativeConfigCommand = ["node", cliPath, "config"]
def reactNativeConfigOutput = this.getCommandOutput(reactNativeConfigCommand, this.root) If I don't do that, the android project runs into the error of not being able to find the IMO we need to know about where the RN project is located before we actually call that CLI otherwise this will always fail. |
mmm I'm not sure I follow you. Do you have an example of your folder setup? |
Yep My project has the following structure:
The android project is a standard Android project which includes a few lines from the react-native boilerplate (e.g. classpath defintions for the react-native gradle plugin, usage of the react-native plugin and applying changes to the settings.gradle file). The This is how my react plugin looks in regards to its options: react {
root = file("../reactnativemodule/")
reactNativeDir = file("../reactnativemodule/node_modules/react-native")
codegenDir = file("../reactnativemodule/node_modules/@react-native/codegen")
cliFile = file("../reactnativemodule/node_modules/react-native/cli.js")
entryFile = file("../reactnativemodule/index.js")
} This is the error I can see if I run my project without the patch in this PR:
|
Sorry for the dumb question, but why is this the case? You're resolving a package that you have installed in your node_modules no? Could I ask you to have a super small reproducer with your folder setup? |
Correct, but that node_modules is sitting with the I can definitely create an example project for you over the next few days. |
Someone linked this as a repro for the same issues, might be helpful. |
@cortinico I have added an example project which includes my scenario including the patch. https://github.com/AlexanderEggers/react-native-module-example |
Hey @cortinico, I'm sure you must be super busy and I hope you don't mind tagging you in a message but I just wanted to follow up on my last message and see if you had a chance to review the example project. Because you mentioned that you will be moving some of the CLI related code into the react-native gradle plugin soon, I believe it would be great if the issue can be solved as part of that migration. Let me now if you have any thoughts. |
Hi @AlexanderEggers I believe we don't want to support this setup. The current setup doesn't work because your We had this same issue reported in the past weeks:
The thing is that we developed all the logic under the assumption that the On top of this, @blakef is working on moving this file ( |
There hasn't been any activity on this pull request in the past 3 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
Summary:
This change include the ability for project to run a custom setup where the react project is not directly part of the android root project but instead is located somewhere else.
This change is backwards compatible and won't break any templates or existing projects.
I have added more details as part of this issue: #2289
Test Plan:
I added a patch in my local project setup (RN 0.73.6) and was able to compile and run the project without issues. This is the following patch I've applied:
Checklist