Running our first react-native app (windows)

Running our first react-native app (windows)

ยท

2 min read

Hey there! Welcome to the most difficult and chaotic part of learning to react- native. Today I will be showing you how to run your first app on your android device and I will also introduce the errors and bugs which I faced during the process.

As we won't be using the virtual device, we need to connect our physical android device to the PC via a USB cable( make sure it's a media transfer supported cable and not just for charging ). connect your device and once it shows USB tethering, turn on the developer mode in your android device. Go to the developer options and turn on USB Debugging and also go to search for SELECT USB CONFIGURATION and change it to MTP (media transfer protocol). That's all you need to do on your android device.

After that open CMD in your windows machine and type the following command

npx react-native init Awesome01

This will generate a new project for you with a folder name "Awesome01".

Once completed, cd into the Awesome01 and (cd Awesome01) and type the following command which will run the app on your android device.

npx react-native run-android

That's it, it will open up this screen on your android device.

This seemed very straightforward forward but people do face issues, like me.

There were 2 major issues I faced during building the process. The first one was weird that it took me hours to solve. My android device wasn't appearing on the desktop and was only getting charged when I connected to PC. The way i fixed it is by downloading Media transfer protocol tool kit on my windows machine, installing it and clicking on the repair. this will restart your PC and fix the issue. To verify, go to Cmd and write adb devices , and it will list the devices connected to your PC.

The second was something like this,

The way you can fix this COMPILESDKVERSION IS NOT SPECIFIED ... is by following these steps.

  1. open up VScode and open the Awesome01 directory.

  2. Now go to the android folder, and create a new file inside of it , name it "local.properties".

  3. open that file and add the following line on it

     sdk.dir = %LOCALAPPDATA%\\Android\\Sdk
    

    Don't forget to add double backslashes in file dir name.

  4. once done, run the npx react-native run-android .

Even After this i faced a loop of issues , it all got fixed after i made a new project and just followed the above steps.

THANKS FOR READING!!!๐Ÿ˜€

ย