Reputation: 111
I am developing an expo app and I was working with some caching features. To test them I have to test my app in offline mode, but if I turn off my wifi (system or device) my app simply is unable to connect to the metro server. Even turning the network settings to offline in debugger didn't work, the app was again completely not loading. How can I simulate offline mode in my device while still being able to connect to the metro bundler?
Upvotes: 11
Views: 10705
Reputation: 143
This works for me
Start the expo on localhost using npx expo start --localhost
.
Press a
on the terminal to open Android
Accept the permissions on your Android phone
Press a
on the terminal again and wait for expo Go to update.
Install from your Android the expo Go that you downloaded from the terminal.
When you open the development page on your mobile device select the open with expo Go option.
Enjoy the offline access on your expo Go.
Upvotes: 11
Reputation: 11
If you are testing on an android device, the following steps have worked for me:
expo start --localhost
.adb reverse tcp:[port] tcp:[port]
. Say for example your server is running on 127.0.0.1:19000
, run the commandadb reverse tcp:19000 tcp:19000
Upvotes: 1
Reputation: 1675
I faced the same issue and didn't find an easy solution online. Luckily I've tried the following and it worked:
expo start --localhost
.Upvotes: 0
Reputation: 600
I struggled with this for a while before I came across an answer. Connect via USB! I have tested this with iPhone only so far, but should work for Android too.
I should caveat that I'm using EAS Build, but this should also work with basic Expo.
With the basic development method (expo start --dev-client), the client app and server connect via your local router. The server automatically listens on an ip address available in the local LAN (that's what the QR code is). This is not helpful for developing offline-first features, because as soon as you disconnect your phone from WiFi, the connection will be lost and the dev app will close. In order to develop offline you can do the following:
ifconfig -a
. Take note of highest number network interface on list like en7
for exampleifconfig
, two new network interfaces should show up with highest numbers. Take the second highest. E.g. en8. Note down it’s inet ip
addressexport EXPO_DEVTOOLS_LISTEN_ADDRESS=<ip address here>
in the shell where you will run the development serverexport REACT_NATIVE_PACKAGER_HOSTNAME=<ip address here>
expo start --dev-client
as normalUpvotes: 6