How to run ionic-react applications on real devices? - reactjs

Hi I am Really happy to see that , ionic now supporting React Scripting , When i try to run the Ionic react apps in the real devices it shows some error which i could not resolve.
I have tried ,
ionic cordova run android
It will not support because ionic-react using the capacitor instead of cordova,
npx cap open android
It throws an error that "[error] Unable to launch Android Studio. Make sure the latest version of Android Studio is installed"
It says that need to open Android Studio, But what i have tried is to run the app in real devices
Is there any work around ?

Instead of using Cordova, I've been using Capacitor which works with Android.
Try running;
ionic capacitor add and select android
Running npx cap open android should now open android studio.
If you want to see your app on a physical device (android or iOS) without android studio, you can download the ionic Devapp and run ionic serve --devapp. As long as your PC and device are on the same WiFi network, you will be able to view the app as if it were installed natively.

Install Capacitor and Capacitor CLI
npm i #capacitor/core --save-exact
npm i #capacitor/cli --save-exact --save-dev
Build The Project Using This Command
ionic build
Initiate Capacitor With App ID
npx cap init YourAppName com.domain.yourappname
Add platforms using "npx cap add":
npx cap add ios
npx cap add electron
npx cap add android
Now you can run following cmd to launch Android Studio
npx cap open android
If You make changes in your project you can build again using
ionic build
Then Sync Your Project and Run
npx cap sync android
npx cap open android

You should let it open Android Studio.
It will open the "android" directory as an android project(that's what it is).
If you have your device plugged in and USB debugging available you should see your device in the IDE. Then just hit start app and you should get you app running on the device.
You can open the project manually from the IDE if you can't fix the

Related

Can you create a build using expo without counting foe the EAS build count?

I am trying to figure out if all the methods to create a build using expo must go through EAS (Expo Application Services) since apparently they limit the free tier to 30 builds per month.
Can I build the web-app locally without an EAS account / 100% for free?
The documentation isn't clear to me.
I do not have enough rep to comment so I will ask here and edit/delete later.
Have you tried building your application manually using android studio / xcode? You should be able to generate a build folder for both platforms and open that folder with android studio or xcode, make, build and run the project to test.
For android:
Step 1: install OpenJDK
Step 2: install android studio
Step 3: CD in your application folder and locate package.json.
Step 4: Run npm android in the same directory where package.json is located
This should open up android studio for you in the same directory and you can start debugging there with the android studio built in emulator. You can also build an APK of your application and install it to your device or connect your mobile device to android studi via wifi pairing and install the application on your android.
According to this video, using eas build --local should do the trick

How do I run expo apps on android studio without ejecting?

I followed expo documentation, but I can't figure out how to run it on an emulator without ejecting. I've heard ejecting is risky and I can't keep making changes to the app if I eject. When I click run, it gives me Error: Module not specified, but there is no module from the dropdown list.
You can run your app on android emulator with expo app on this emulator or make expo build:android and select apk option. Then just download and install apk on any device. You don't able to run expo app in android studio like native app without ejecting. I recommend you not to use Expo at all and have a look on fast line, pure react native app is more flexible and with fast line has almost the same benefits like expo app. Development without expo is not a big deal.

React native EXPO installation (npm start)

I created my app in react native using Expo but when i run the npm start command its showing me this:
running metro bundler on port 8081
and then
loading dependency graph, done
and never end. what to do?
Here is the complete console output.
First of all if you have a bundler like the one that you have used then it would suggest that you have used react-native init to create you application, instead of expo.
Expo bunders look like this:
If you have created a react-native init and as it suggests in your screenshot that you are building the app on a Windows machine, that means you will be developing on Android.
The instructions for using Android and running react-native are quite long and complicated, they can be found here. For the sake of brevity I am not going to repeat them here asyou can just follow this link. Make sure to choose Building Projects with Native Code -> Development OS: Windows -> Target OS: Android to find the instructions that are pertinent to your situation.
https://facebook.github.io/react-native/docs/getting-started.html
If you are planning on developing on an emulator then you will need to make sure that you have one installed (the link above has all the info that you need). Also you need to make sure that you launch your emulator before running react-native run-android if you do that then it should load on to the emulator and you should be able to see what you are developing on.
If you want to run on your own Android device then you should follow the instructions on this page https://facebook.github.io/react-native/docs/running-on-device (again choosing the options for your situation).
Expo
If this feels like too much effort, you can always try Expo. It doesn't require you to be able to deal with native code. And depending on your use case can be a better option than creating a project with react-native init, plus you can always eject from the expo project and turn it in to a full fledged react-native app.
You install the expo-cli with
npm install -g expo-cli
Then download the expo app from the App Store or the Google Play Store (depending on the mobile that you are using).
Then you can use
expo init
to create your application
Check out the expo documentation for more information https://docs.expo.io/versions/v32.0.0/workflow/up-and-running
Well, Nice question, First of all, I totally understand what's exactly your problem is, let me give you a solution in a very appropriate way.
Basically, there is two way to install and setup React Native Project on your mac and windows machines
1st React Native (native) Method: (That's basically you're using right know
Note: If you're using Apple product - Like MacBook then you can do IOS and Android both platform by using this method, if you're using Windows or Linux you can only do this part for Android platforms
In this method, we have to follow these simple steps
Download Nodejs from Offical website link here
Installing the React Native Cli
npm install -g react-native-cli
If you get an error like Cannot find module 'npmlog', try installing npm directly: curl -0 -L https://npmjs.org/install.sh | sudo sh.
(Only for mac)
Install the Xcode from Appstore (Only for Mac user/macos users)
otherwise
download and install the Android Studio (Stable version) from the official website of Android studio
Setup Xcode (Simulator) or Setup Android Studio for Android devices use (emulator)
by learn and guide from this link here
Note: Basically in your scenario, I'm pretty sure you didn't set up your emulator for android and simulator for IOS that's why you didn't see anything after
2nd React Native with Expo Method: that's you're not using a loading dependency graph
Use
For Android
react-native run-android
For IOS
react-native run-ios
2nd React Native without Expo (that's not your case):
In this method, we have to follow these simple steps
Download Nodejs from Offical website link here
installing expo cli
npm install -g expo-cli
expo init yourprojectname
cd yourprojectname
npm start
Note: Simulators and emulators way same for both

React native run stays in IDLE state

This is my first time setting up react native on Ubuntu 18.04 LTS. I have done the setup and I was trying to run the app on the device using the react-native run-android command.
Here is the output what I get in terminal,
ron#lenovo:~/react/app$ react-native run-android
Scanning folders for symlinks in /home/ron/react/app/node_modules (9ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory. It is currently set to /home/ron/Android/Sdk/ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.
File /home/ron/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 26.0.3 in /home/ron/Android/Sdk/licenses
License for package Android SDK Build-Tools 26.0.3 accepted.
Preparing "Install Android SDK Build-Tools 26.0.3 (revision: 26.0.3)".
<=============> 100% CONFIGURING
> IDLE
It stays in this IDLE position forever. What is the fix or this issue?
The solution is to install Android SDK rev. 26.0.3. Your can install it from Android Studio's SDK Manager menu in File > Settings. Hope this helps.
I got the same error today. The solution is to create a file named local.properties and write in it this line:
sdk.dir=[the position of android sdk]
example:
sdk.dir=N\:\\Users\\andy\\AppData\\Local\\Android\\Sdk
you can get the sdk android via android studio: Android Studio - How to Change Android SDK Path
hope this will help you and other people out there who just begin learning react native.

React-native can not map tcp port with device

I'm a newbie in React-native. In the first project. I init react project with command line react-native init <project name>
This environment:
nodejs: v4.5.0, npm: 4.1.2 and ANDROID_HOME.
When I run adb device
But when I run project react-native run-android
I try run command line adb reverse tcp:8081 tcp:8081 but it not working.
Who can tell me fix this error. Thanks
Install Android SDK v23 should resolve your problem.
Update answer:
Android API 23 I installed but when I install Android SDK Build-tool
23.0.1 it's working while Android SDK Build-tool 23.0.2 or 23.0.3 not working
Because 23.0.1 is the default SDK version for a React Native project. I don't know how to modify this but if you want to see the build version, checkout this file android/app/build.gradle. You would see a section with following content:
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
}
Did you enable developer options on your phone? if not check this line: enable developer options on android device
You need to install the Android build tools via Android Studio.
Open Android Studio
Go to Tools > Android > SDK Manager
Click "Launch Standalone SDK Manager" at the bottom of the window
Find the referenced package and check it (see below)
Click "Install packages..."
Agree to the licences
You should then be able to build onto the device.

Resources