How to simulate offline mode in expo app during development - android

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?

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:
Run the following command: ifconfig -a. Take note of highest number network interface on list like en7 for example
Connect phone with usb cable
Rerun ifconfig, two new network interfaces should show up with highest numbers. Take the second highest. E.g. en8. Note down it’s inet ip address
Run export EXPO_DEVTOOLS_LISTEN_ADDRESS=<ip address here> in the shell where you will run the development server
Run export REACT_NATIVE_PACKAGER_HOSTNAME=<ip address here>
expo start --dev-client as normal
The IP address advertised through the QR code will now be the IP for the usb connection that you put in above, so mobile client app will go through the usb cable to reach the dev server on your computer.
Switch on airplane mode on the phone as much as you want. Metro, hot reloading, debugging, all keep functioning, and in fact are usually much faster than via router. Enjoy!

I faced the same issue and didn't find an easy solution online. Luckily I've tried the following and it worked:
Connect a physical device. I've tried it on emulator for a while but failed.
Start Expo on localhost instead of LAN as it does by default: expo start --localhost.
Disable WiFi/cellular connection on the device.
See that the connection to Metro bundler is still working.
Work as you are used to.

If you are testing on an android device, the following steps have worked for me:
Connect your physical device via a USB cable. Make sure you have developer mode turned on.
Start expo in localhost using expo start --localhost.
Using adb, set up a connection so your device can listen to the port where the development server is running. This can be done using the command adb reverse tcp:[port] tcp:[port]. Say for example your server is running on 127.0.0.1:19000, run the command
adb reverse tcp:19000 tcp:19000
Now you should able to run the app in expo without an active internet connection.

Related

how to test an app without a USB cable which attaches the device to the debugger?

I'm new to android studio and have just made a new app, which uses position sensors.
All is well when the device is usb connected to the debugger. When I unplug the cable, the app runs fine and I can wave the device around, going to a different room etc. .
But when the app is restarted without that cable, it is "waiting for debugger", which is a little annoying at that point.
I have seen this https://developer.android.com/studio/run#changing-variant but that way I need to sign the app, and I fail on that.
Is there a way to run the app without signing it, and without that debugger cable?
To be more precise in view of the two answers that suggested wi-fi connections (which I can't verify at the moment because the box running AS doesn't have wf-fi connection).
I want to test the app even without debugging, and test it by changing location, too. So I would have to set up a wi-fi connection that would connect to AS over really long distances.
Instead I just want to tell the app (or the device): forget about the debugger.
This: https://stackoverflow.com/a/56541740/4142984 solved my problem.
For the first time you must need to connect device to the android adb and after that you can remove it and still get connection to the android adb.
you should install Android Wifi ADB
you need to connect first time your device with cable in usb debug mode and by using this plugin you can connect your device on the wifi after that you can remove the cable from the system and you will get connected your device to the Android Studio
Note : make sure your system and mobile device must be connected with the same wifi network.
1.Download android-sdk-platform-tools
2. Add the path to environment variables
3. Connect your phone to usb cable
4. Connect your phone and computer in same network(WiFi)\
Now in cmd
5.adb tcpip 5555
6. adb connect *your_phone_ip*:5555
Now you can unplug the usb cable.

Android WiFi ADB plugin not working. Giving error

I installed the Android WiFi ADB plugin to run the app wirelessly. But it's not working it's giving error that Phone and PC should be connected on the same network. I use my phone hotspot to run the internet on my PC. Then I use another phone but then also same error. Someone says it will not work because you use the mobile hotspot for an internet connection on your PC. But when I try to connect another phone then also the same issue. But the same way my friend also does. he also uses the internet using a mobile hotspot but it's working fine on his phone. I have a POCO F1 Phone.
I'm answering this hoping this may help others as well as I find it helpful for my use.
First, Turn on ADB in your phone's developer options. You can search Your_phone_model developer options to find that.
Second, After turning on ADB, Connect your phone with data cable to your laptop/desktop.
Open a Command prompt window, Type adb tcpip 5555, Press allow in adb prompt shown in your phone, it will show restarting adb in tcpip mode. Now, disconnect the USB cable. You can use different port number to connect another device.
Type adb connect your_phone_ip:5555 as for example adb connect 192.168.43.1:5555 in case of hotspot. You can check Phone's IP in WIFI's advanced setting of your phone or in status section.
Now, Everytime your device restarts, repeat steps 3-4.
You can also make a script, just type adb connect your_phone_ip:5555 in a notepad file, save it as name.bat file, right click on it and send to desktop (create shortcut), in the settings on the shortcut, set any shortcut keys. Now, anytime you want to connect, just press the shortcut keys. That's how I do it. You can further open Android studio by this script so it will open Android Studio as well.
Remember, whenever it says Device is Offline, restarts your phone's wifi and reconnect it.

check android auto app log messages while connected to car

I have a question on checking logs/debugging of android auto app when the mobile device is connected to the main Head Unit (car).
During apk installation on the Mobile device from the development machine
using Android Studio, the logs can to checked using adb (Android Debug Bridge).
Since it is a development machine, the calls does not go into functions like onCarConnectionCallbacks.
So tried using DHU (Desktop Head Unit), but DHU is connected using adb forward socket connection, How to check for app log messages simultaneously?
And also how to check log messages or debug the app, when it is connected to the main Head Unit (Car), Should the adb be installed? (Here the mobile is not on development mode).
I am not able to find convincing answers online.
Please give your view on this.
Thanks
Having the port forwarded for the DHU connection won’t affect the ADB streaming the logcat in another terminal. You can checkout the ADB documentation on how to Connect to a device over Wi-Fi, and use a laptop to connect with since the usb connection will be used on the phone to connect to the car or DHU.
For the onConnectionCallbacks, those are still functional even when connecting to the DHU. Sounds like it might be a coding issue with registering the connection callback.

Stuck on Meteor example “todos” loading screen when running on an android device

Issue(s)
The Meteor “todos” example is stuck on the loading screen forever when I try to run it on an android device. As can be seen in the screenshot below, the following error message is shown:
Failed to load resource: net::ERR_ADDRESS_UNREACHABLE http://10.0.2.15:3000/sockjs/info?cb=...
Also the app indicates it is having trouble connecting.
Is it possible this could be due a bug in the Cordova Meteor 1.0 release? Or am I missing some important configuration/setup step?
Setup / Configuration
System Setup
Meteor 1.0
Ubuntu 14.04 VM with VirtualBox 4.3.18
Motorola Droid Turbo (Android 4.4.4) with Developer Mode and USB debugging enabled
Chrome 38
Run these commands in the Linux terminal
meteor create --example todos
cd todos
ifconfig <------- gives inet addr:10.0.2.15
meteor run android-device –p 10.0.2.15:3000
Open Chrome DevTools
Wait until the “todos” app launches on my android device (it does launch but it doesn’t move past the loading screen).
Then open up Google Chrome and type “chrome://inspect” in the search bar.
Click on the “Inspect” link under the “Todos” app listed under my Android device connected via USB.
Exapnding on imslavko's answer...
The mobile device downloads the intial templates and whatnot over USB, but after that is tries to load the data from the server. In your case the, the mobile device is (or should be) connected to your LAN via Wifi, provided by your router. I'm also assuming your dev PC is connected to that router.
Now the server is running inside a VM which would make it problematic for the mobile device to see your server. The IP in the VM (in your case 10.0.2.15) is not directly accessible from the rest of the LAN which would only see the IP of your host computer (likely 192.168.x.x).
When you run the command meteor
run android-device –p 10.0.2.15:3000
you are telling your meter to start a webserver at that IP, but you are also telling the mobile device to look for the webserver at that IP (which it can't see as stated above).
So what do you do?
2 things...
You will need to port forward from the guest VM to your Host PC. To do this...
Get your host PCs IP... in windows run cmd, then ipconfig.... save that
On your guest VM get the IP with ifconfig (in your case 10.0.2.15)
On your guest VM, go to the Virtual Box menu at the top then Devices->Network->Network Settings... in that window click the "Port Forwarding" button.
In there add a rule... HostIP = your hosts IP from step 1, Host Port = 3000, Guest IP = IP from step 2, Guest Port = 3000.... hit OK
Next you need to tell your mobile device to look for the server on a different IP than the one the server is actually running on. Now that you are forwarding the webserver IP to your host PC you want the device to look at your host PC's IP
so the new command would be....
meteor run android-device –p 10.0.2.15:3000 --mobile-server 192.168.x.x:3000
Your app can not connect to the server (it might that the device and your computer are on different networks, or your home network has client isolation turned on).
The code in the app explicitly holds the load screen until it loads the initial data.

Testing app beetween real device and emulator via WiFi without router

I develop app which contains a client and a server side, so I need to test work between them. I have a real android device and I want android device to connects to emulator. I'm working at work sometimes(if I have free time of course) and at home. I have the WiFi router at home and I can connect to the real device by emulator(TCP listener running on the real device), but not vise versa(I don't know which exactly IP to use). But at work I have only hot-spot WiFi point without router. My android device connects to it fine. Even more ADB can connect to the device when adbWireless running on it. But it doesn't work, I can't connect to tcp listener in any cases. The difference between home and work is existence of WiFi router. Are there any solutions? If not why Android debug bridge(ADB) can connect to adbWireless? Thanks.
I solved the problem. I run tethering on my real device and run the server on it. Then I use a program Connection state viewer there is a link: https://play.google.com/store/apps/details?id=ru.nolesh.android.connectionstateviewer It helps me to find IP address. After that I start the emulator and the client side on it. So I connect to my server by given IP.

Categories

Resources