1
1
# Example React Native app
2
2
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 )
4
5
5
6
Content was taken from the web app example in src/frontend and modified to work
6
7
in a React Native environment.
@@ -17,102 +18,122 @@ make start # or start-minimal
17
18
## Building the app
18
19
19
20
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.
27
28
28
29
### Build on your host machine
29
30
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.
32
32
33
33
``` bash
34
34
cd src/react-native-app
35
35
npm install
36
36
```
37
37
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.
39
43
40
44
``` bash
41
45
npm run android
42
46
```
43
47
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
46
49
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.
51
53
52
54
``` bash
53
- npm run start
55
+ cd ios && pod install && cd ..
54
56
```
55
57
56
- Then install the pods for the project:
58
+ #### iOS: Build and run with XCode
57
59
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).
67
64
68
65
``` 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
73
67
```
74
68
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
77
74
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.
79
78
80
79
``` bash
81
80
npm run ios
82
81
```
83
82
84
- Note that for the above command a server is also spun up to serve the JS bundle
85
- to the deployed apps.
86
-
87
83
### Build within a container
88
84
89
85
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.
91
88
92
89
``` bash
93
90
make build-react-native-android
94
91
```
95
92
96
- Or directly from this folder using:
93
+ Or directly from this folder using.
97
94
98
95
``` bash
99
96
docker build -f android.Dockerfile --platform=linux/amd64 --output=. .
100
97
```
101
98
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.
112
102
113
103
## Troubleshooting
114
104
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
116
137
117
138
If you see a build failure related to pods try forcing a clean install with and
118
139
then attempt another build after:
@@ -126,25 +147,9 @@ then attempt another build after:
126
147
pod install --repo-update --verbose
127
148
```
128
149
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:
131
152
132
153
``` bash
133
154
rm -rf ~ /Library/Developer/Xcode/DerivedData
134
155
```
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