Gopinath Kaliappan
Gopinath Kaliappan

Reputation: 7369

How to run ionic-react applications on real devices?

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 ?

Upvotes: 0

Views: 1937

Answers (3)

Ashirbad Panigrahi
Ashirbad Panigrahi

Reputation: 815

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

Upvotes: 1

Guillermo de Ipola
Guillermo de Ipola

Reputation: 21

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

Upvotes: 0

James Brightman
James Brightman

Reputation: 935

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.

Upvotes: 1

Related Questions