Struggling to set up a monorepo with 2 RN apps and a shared package that includes native code
See original GitHub issueAsk your Question
Sorry for the impending wall of text, and thank you in advance for any help.
I have a monorepo (using yarn workspaces) that has several non-rn apps (a graphql server, 2 different websites, others) and as of now a single react-native ios/android app. This works by just nohoisting everything RN related, and some metro config to make sure it can find the js in the other packages. Everything related Iβve found (mostly issues in this repo, honestly) is more about getting a single RN app to work in a monorepo.
Iβm looking for help with configuring everything to make this work. This is rapidly approaching being a blocker for some of my team, so I can definitely dedicate some decent time to working on cli if needed. My native-fu is somewhat weak, but Iβm happy to jump in if I can get some some guidance. I am flexible.
Here is my desired project structure:
.
βββ package.json
βββ packages
|
βββ shared (this is shared between everything that wants to use it)
| βββ package.json
| βββ js (does not reference native code)
|
βββ shared-browser
| βββ package.json
| βββ js
|
βββ shared-mobile
| βββ package.json
| βββ js (references native code)
|
βββ mobile-professional (first-mobile-app)
| βββ package.json
| βββ ios
| βββ android
| βββ js (references native code, shared-mobile, and shared-everywhere)
|
βββ mobile-business (second-mobile-app)
| βββ package.json
| βββ ios
| βββ android
| βββ js (references native code)
|
βββ first-web-app
| βββ package.json
| βββ js
|
βββ second-web-app
| βββ package.json
| βββ js
|
βββ non-js-package
βββ non-js-package
βββ non-js-package
Currently, itβs basically the same as that except that there is only one mobile app, and the shared-mobile folder doesnβt reference any native code.
Weβre trying to add a second RN android/ios app to the mix. Currently we have a single shared folder for stuff accessible everywhere. Iβm first trying to get the single app to work with the native code hoisted, since that seems prerequisite to the shared code being able to be hoisted. Assuming that works, Iβd be able to get stuff working by not having any shared native code, but this involves a ton of code duplication with tedious reference changes.
Ideally, weβd like to add the majority of the native stuff to our shared-mobile folder. I was able to get IOS to work with a bit of a hack, but Iβve been unable to get android working. Iβve been trying both with what ships with RN 0.61.2, as well as upgrading the cli to the latest 3 alpha (7?).
For the ioS stuff, to get it working, I simply updated the xcode project and podfile to look for stuff at ../../../node_modules instead of ../node_modules, and then I duplicated the .command file that gets opened in a new window and added a step to CD into the packages/mobile-professional folder (otherwise it runs in the wrong directory and metro doesnβt pick up the config that Iβve got inside that folder).
For the android stuff, I first adjusted the build.grade, app/build.gradle and settings.graddle to look up 2 directories more than before, which gets me farther but then i get A problem occurred evaluating settings ... Text must not be null or empty. Iβve tried various react-native.config.js values in both the root and my folder (and pointing the android dir within both to ./android and ./packages/mobile-professional/android) but that does not work with the old cli or the new. If I modify the native_modules.gradle file that gets installed as part of cli, (or the android subcomponent), so that it runs react-native config in the mobile folder rather than the root, I finds what it wants, but then I get some build errors about not being able to find android.support.annotations.nullable in one of the native components, saying more specifically that android.support.annotations doesnβt exist, which feels like a linking issue.
Just to make sure itβs not a hangup, re: react-native.config.js, iβve also moved the limited rnpm stuff (just assets) in there as well out of the package.json
Iβm trying to set up an example repo, as ours is closed and stripping things out has proven time consuming (we have a lot of process going on, everything is built in reasonml and compiled with bucklescript down to JS). In the meantime Iβm posting original versions of my build and config files, and new versions.
app-build.gradle-modified.txt app-build.gradle-original.txt build.gradle-modified.txt build.gradle-original.txt metro.config.js.txt mobile-professional-package.json.txt rn-cli.config.js.txt settings.gradle-modified.txt settings.gradle-original.txt
Sorry again for the huge wall of text, but I figured it was better to provide everything relevant rather than too little.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:20 (8 by maintainers)

Top Related StackOverflow Question
Here is an example repo I set up that shows what weβve done to get things working
https://github.com/maxkorp/codepush-monorepo-example. There are some commits on master that are related to similar issues for codepush, but you can go back to the second commit to see how I got things working.
Hereβs a probable workaround, make sure you have the same cli and RN version. I donβt give any warranty on this. If you use this, test it thoroughly in debug/release mode on Android/iOS. Also make sure to understand how patch-package work. https://gist.github.com/Minishlink/14fde025b4352d0802e25e098e357046