Skip to content

Commit 19cbfea

Browse files
[react-native-app] cleanup build instructions (#1860)
* cleanup build instructions * cleanup build instructions * cleanup build instructions --------- Co-authored-by: Juliano Costa <julianocosta89@outlook.com>
1 parent 2210b5b commit 19cbfea

File tree

1 file changed

+74
-69
lines changed

1 file changed

+74
-69
lines changed

src/react-native-app/README.md

+74-69
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Example React Native app
22

3-
This was created using [`npx create-expo-app@latest`](https://reactnative.dev/docs/environment-setup#start-a-new-react-native-project-with-expo)
3+
This was created using
4+
[`npx create-expo-app@latest`](https://reactnative.dev/docs/environment-setup#start-a-new-react-native-project-with-expo)
45

56
Content was taken from the web app example in src/frontend and modified to work
67
in a React Native environment.
@@ -17,102 +18,122 @@ make start # or start-minimal
1718
## Building the app
1819

1920
Unlike the other components under src/ which run within containers this
20-
app must be built and then run on a mobile simulator on your machine or a physical
21-
device. If this is your first time running a React Native app then in order to
22-
execute the steps under "Build on your host machine" you will need to setup your
23-
local environment for Android or iOS development or both following
24-
[this guide](https://reactnative.dev/docs/set-up-your-environment). Alternatively
25-
for Android you can instead follow the steps under "Build within a container" to
26-
leverage a container to build the app's apk for you.
21+
app must be built and then run on a mobile simulator on your machine or a
22+
physical device. If this is your first time running a React Native app then in
23+
order to execute the steps under "Build on your host machine" you will need to
24+
setup your local environment for Android or iOS development or both following
25+
[this guide](https://reactnative.dev/docs/set-up-your-environment).
26+
Alternatively for Android you can instead follow the steps under "Build within a
27+
container" to leverage a container to build the app's apk for you.
2728

2829
### Build on your host machine
2930

30-
Build and run the React Native app for a given platform by navigating to this folder
31-
and running:
31+
Before building the app you will need to install the dependencies for the app.
3232

3333
```bash
3434
cd src/react-native-app
3535
npm install
3636
```
3737

38-
To run on Android:
38+
#### Android: Build and run app
39+
40+
To run on Android, the following command will compile the Android app and deploy
41+
it to a running Android simulator or connected device. It will also start a
42+
a server to provide the JS Bundle required by the app.
3943

4044
```bash
4145
npm run android
4246
```
4347

44-
Note that for the above command a server is also spun up to serve the JS bundle
45-
to the deployed app.
48+
#### iOS: Setup dependencies
4649

47-
To run on iOS you may find it cleanest to build through the XCode IDE. First spin
48-
up the react native dev server with the following (feel free to ignore the output
49-
commands referring to opening an iOS simulator, we'll do that directly through
50-
XCode in a later step):
50+
Before building for iOS you will need to setup the iOS dependency management
51+
using CocoaPods. This command only needs to be run the first time before
52+
building the app for iOS.
5153

5254
```bash
53-
npm run start
55+
cd ios && pod install && cd ..
5456
```
5557

56-
Then install the pods for the project:
58+
#### iOS: Build and run with XCode
5759

58-
```bash
59-
cd ios
60-
pod install
61-
```
62-
63-
Note that the above is the quickest way to get going but you may end up with
64-
slightly different versions of the Pods than what has been committed to this repo,
65-
in order to install the precise versions first setup [rbenv](https://github.com/rbenv/rbenv#installation)
66-
followed by:
60+
To run on iOS you may find it cleanest to build through the XCode IDE. In order
61+
to start a server to provide the JS Bundle, run the following command (feel free
62+
to ignore the output commands referring to opening an iOS simulator, we'll do
63+
that directly through XCode in the next step).
6764

6865
```bash
69-
rbenv install 2.7.6 # the version of ruby we've pinned for this app
70-
bundle install
71-
cd ios
72-
bundle exec pod install
66+
npm run start
7367
```
7468

75-
Then open XCode, open this as an existing project by opening `src/react-native-app/ios/react-native-app.xcworkspace`
76-
then trigger the build by hitting the Play button or from the menu using Product->Run.
69+
Then open XCode, open this as an existing project by opening
70+
`src/react-native-app/ios/react-native-app.xcworkspace` then trigger the build
71+
by hitting the Play button or from the menu using Product->Run.
72+
73+
#### iOS: Build and run from the command-line
7774

78-
Or alternatively build and run from the command-line:
75+
You can build and run the app using the command line with the following
76+
command. This will compile the iOS app and deploy it to a running iOS simulator
77+
and start a server to provide the JS Bundle.
7978

8079
```bash
8180
npm run ios
8281
```
8382

84-
Note that for the above command a server is also spun up to serve the JS bundle
85-
to the deployed apps.
86-
8783
### Build within a container
8884

8985
For Android builds you can produce an apk using Docker without requiring the dev
90-
tools to be installed on your host. From the project root run:
86+
tools to be installed on your host. From this repository root run the
87+
following command.
9188

9289
```bash
9390
make build-react-native-android
9491
```
9592

96-
Or directly from this folder using:
93+
Or directly from this folder using.
9794

9895
```bash
9996
docker build -f android.Dockerfile --platform=linux/amd64 --output=. .
10097
```
10198

102-
This will produce `react-native-app.apk` in the directory where you ran the command.
103-
If you have an Android emulator running on your machine then you can simply drag
104-
and drop this file onto the emulator's window in order to install it following
105-
[these steps](https://developer.android.com/studio/run/emulator-install-add-files).
106-
107-
TODO: For a physical device you can install this by sending the apk file to your
108-
device, giving the "Install unknown apps" permission to the app you will be opening
109-
the file with, and then installing it. However this won't be able to hit the APIs
110-
because they are hard-coded to be localhost, need those to be configurable before
111-
this method would work.
99+
This will create a `react-native-app.apk` file in the directory where you ran
100+
the command. If you have an Android emulator running on your machine then you
101+
can drag and drop this file onto the emulator's window in order to install it.
112102

113103
## Troubleshooting
114104

115-
### iOS build issues
105+
### JS Bundle: build issues
106+
107+
Try removing the `src/react-native-app/node_modules/` folder and then re-run
108+
`npm install` from inside `src/react-native-app`.
109+
110+
### Android: build app issues
111+
112+
Try stopping and cleaning local services (in case there are unknown issues
113+
related to the start of the app).
114+
115+
```bash
116+
cd src/react-native-app/android
117+
./gradlew --stop // stop daemons
118+
rm -rf ~/.gradle/caches/
119+
```
120+
121+
### iOS: pod install issues
122+
123+
Note that the above is the quickest way to get going but you may end up with
124+
slightly different versions of the Pods than what has been committed to this
125+
repository, in order to install the precise versions first setup
126+
[rbenv](https://github.com/rbenv/rbenv#installation) followed by the following
127+
commands.
128+
129+
```bash
130+
rbenv install 2.7.6 # the version of ruby we've pinned for this app
131+
bundle install
132+
cd ios
133+
bundle exec pod install
134+
```
135+
136+
### iOS: build app issues
116137

117138
If you see a build failure related to pods try forcing a clean install with and
118139
then attempt another build after:
@@ -126,25 +147,9 @@ then attempt another build after:
126147
pod install --repo-update --verbose
127148
```
128149

129-
If there is an error compiling or running the app try closing any open simulators
130-
and clearing all derived data:
150+
If there is an error compiling or running the app try closing any open
151+
simulators and clearing all derived data:
131152

132153
```bash
133154
rm -rf ~/Library/Developer/Xcode/DerivedData
134155
```
135-
136-
### Android build issues
137-
138-
Try stopping and cleaning local services (in case there are unknown issues related
139-
to the start of the app):
140-
141-
```bash
142-
cd src/react-native-app/android
143-
./gradlew --stop // stop daemons
144-
rm -rf ~/.gradle/caches/
145-
```
146-
147-
### JS build issues
148-
149-
Try removing the `src/react-native-app/node_modules/` folder and then re-run
150-
`npm install` from inside `src/react-native-app`.

0 commit comments

Comments
 (0)