0

I've installed React Native on my 32-bit Windows 10 laptop.

My Xiaomi Androoid phone is connected with a USB cable. Both have Bluetooth but I haven't managed to get them on a local network together so far.

I don't have internet access at home.

When I do yarn run start the project builds and the QR-code appears but scanning it with the phone results in:

Something went wrong.

Could not load exp://192.168 etc etc. Can't connect to internet. Please try again.

Is what I'm trying to do even possible?

(I wasn't sure if this belonged on SO or SU. Let me know if I should move it.)

hippietrail
  • 15,848
  • 18
  • 99
  • 158
  • 1
    Have you tried one of these? 1) Run an ad hoc network off the computer and connecting to it via the mobile phone, 2) [this solution for Android](https://stackoverflow.com/questions/9887621/accessing-localhost-of-pc-from-usb-connected-android-mobile-device), or 3) [run a hotspot from the phone and connecting to it via the computer](https://stackoverflow.com/questions/4779963/how-can-i-access-my-localhost-from-my-android-device)? – Michael Cheng Aug 28 '17 at 02:24
  • I've been assuming hotspot meant sharing Internet so I've been ignoring articles that mention it. Was I wrong about that then? – hippietrail Aug 28 '17 at 02:32
  • 1
    Yes and no. That's the purpose of a hotspot, to share internet access, but it also accomplishes the same thing as an ad hoc network. For your purposes, it will get both your computer and phone onto the same network so you can connect to the development server for React Native and that's all you need. The lack of internet access will not be an issue unless parts of your app need internet access or you need to install a new package that you don't have cached. – Michael Cheng Aug 28 '17 at 03:24
  • 1
    A fourth option if you have a spare router lying around is to just setup a wifi network that has no internet access and connect to it with both your phone and computer. – Michael Cheng Aug 28 '17 at 03:24
  • No I don't have a spare router but I may be get an old one somebody no longer needs at some point now that I know that's an option. Thanks! – hippietrail Aug 28 '17 at 03:41

1 Answers1

1

Taking a second look, I notice that you mention that there is a QR code and that your URL is exp://192.168..., that means you are using create-react-native-app (or Expo) and (possibly) are attempting to scan it in the Expo app to open your app for development (or simply running yarn run android). This will not work without internet access as it leverages the Expo servers as an intermediary for building/bundling parts of the code.

If you are willing to forgo create-react-native-app/Expo, you can create your project using react-native init <projectname> and get a working development environment without internet access using the third method I mentioned in the comments.

Note: I suspect that the first two methods that I suggested will work as well, but I could only verify the third at the moment and only with macOS + Android as I currently do not have access to a Windows machine.

Given that you:

  • create the project using react-native init
  • have no internet access on your computer
  • have no use for the wifi on both the computer and your Android phone
  • have your USB cable for connecting your phone to your computer

You can do the following:

  1. enable a wifi hotspot with your Android phone
  2. connect to it with your computer like any other wifi network
  3. connect your phone to the computer via USB for debugging
  4. run your project with react-native run-android

I've tested this with macOS + Android with React Native 0.47.2 and it works fine.

Michael Cheng
  • 9,644
  • 6
  • 46
  • 48
  • Interesting. I also have a MacBook that is set up and working and I've noticed I can actually do updates with Wi-Fi disabled on the Mac but not with Wi-Fi disabled on the Android. (I'm trying to get the PC working as a backup in case of problems.) – hippietrail Aug 28 '17 at 03:43
  • Also I should point out that I do have internet right now on all devices while I try to get this all working, but I like to do dev work while on the road and away from Internet distractions. I get Wi-Fi by visiting a library or friend's house from time to time. – hippietrail Aug 28 '17 at 03:46
  • I'm very new to most of this stuff. My friend set up the Mac and doesn't do PC's. I have the PC connecting to the Android hotspot and `react-native run-android` fails with `Android project not found. Maybe run react-native android first?` but when I try `react native android` it just tells me `Unrecognized command 'android'` – hippietrail Aug 28 '17 at 04:12
  • @hippietrail If you are this new at react native and development in general, I suggest doing the basic tutorial on react native on the Facebook website and other various resources found online before attempting to setup an offline environment like this. You are running into issues right now primarily because you don't have a working knowledge of the basics. I'd help you through it but I'm actually going on vacation tomorrow and won't have my laptop and don't plan on hopping on here. If you can, ask your friend as these issues aren't difficult to figure out on any OS. – Michael Cheng Aug 28 '17 at 05:40
  • Yes that's what I tried before asking on SO since my setup is not typical. I wasted about two days installing the Android SDK over a throttled library Wi-Fi that times out every two hours for instance. So I decided to ask the experts if I can set up something that will work given my restrictions since the tutorials are written by and for people that have much better setups than I can afford right now. Thanks very much for your help and patience thus far, it is very much appreciated. – hippietrail Aug 30 '17 at 00:22
  • Yes that's what I tried before asking on SO since my setup is not typical. I wasted about two days installing the Android SDK over a throttled library Wi-Fi that times out every two hours for instance. So I decided to ask the experts if I can set up something that will work given my restrictions since the tutorials are written by and for people that have much better setups than I can afford right now. Thanks very much for your help and patience thus far, it is very much appreciated. – hippietrail Aug 30 '17 at 00:23