I am new to ionic and I want to run my app on android studio emulator. I did refer the link
https://developer.android.com/studio/run/index.html. But I do not seem to understand how to run my ionic app on emulator
First ensure that your Android Studio setup is correctly done. If want to do that from scratch refer these links - link1 and link2. In link2, you can choose your OS as well.
This ionic guide will help you setup ionic project correctly. If you follow this guide entirely, you will see the use of emulate, platform, run, serve, etc commands of ionic.
Basically what you need to do is first add an android platform to your project:
ionic cordova platform add android
And then emulate your project using:
ionic cordova emulate android
First open Android studio and start an emulator wait when its still done (first time needs more time)
test if the emulator is available with `android list devices``
ionic cordova emulate android will publish it on your emulator
You can install capacitor which created by the ionic team and i recommend it over cordova
Inside your project do this
ionic integrations enable capacitor
then
npx cap init [appName] [appId]
after that add android or ios folder to your project by this command
npx cap add ios
npx cap add android
then finaly you can run your app by
npx cap open ios
npx cap open android
or this command
ionic capacitor run android
In the latest Android Studio you need to make at least one project and open the project, and then create AVD (android virtual device) in Tools - Android - AVD Manager, and then in your ionic project
ionic cordova emulate [platform]
I was able to run the ionic app in emulator by first launching it from the Android Studio on Windows. Trying to run just by the command timed out.
-Start emulator from Studio (Tools | AVD Manager)
-On command line, run "ionic cordova emulate android"
step 1 - Create Virtual Device
AVDs are managed with the AVD Manager. In the Android Studio welcome
screen, click Configure » AVD Manager. The AVD Manager can also be
opened inside Android projects in the Tools » AVD Manager menu.
step 2 - set environment From the desktop, right click the Computer icon.->Properties -> Advanced system settings->Environment Variables->User variable ->Path->edit->New and add your emulator path like given below
eg. C:\Users\kunal\AppData\Local\Android\sdk\emulator
then,
ionic cordova platform add android
ionic cordova emulate android
or
ionic cordova run android
You can use this for example :
ionic cordova emulate android -lcs
If you have not integrated capacitor to your project follow from step 1. If you have already integrated capacitor follow from step 2.
Enter below command on your command prompt.
Step 1
ionic integrations enable capacitor
Step 2
npx cap init [appName] [appId]
(appName is the name of your app, and appId is the domain identifier of your app (ex: com.example.app))
Step 3
ionic build - Build your application
Step 4
npx cap add ios - Copy to ios destination folder
npx cap add android - Copy to android destination folder
Step 5
npx cap open ios
npx cap open android
If you need to run ios app on a emulator you need to have xcode in a mac device. But if you need to run it on an android emulator you need to install android studio either on ios or windows.
Related
How to run moodle mobile app on android studio? I want to add my own plugins as well.
I have followed moodle documentation https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2 but it stuck on Native build dependencies.
Code I am following: https://github.com/moodlehq/moodleapp
Also try to run this code on android studio ( follow:https://www.youtube.com/watch?v=IA3c2lpoOtU&t=757s ),I am having a blank white screen(I have paste moodle src folder on www folder and run the src/index.html)
Can somebody share video tutorial regarding this? It will be really helpful.
At first you need to add android platform to your project by these bash commands:
Removing and adding
npx ionic cordova platform remove android
npx ionic cordova platform remove ios
npx ionic cordova platform add android
npx ionic cordova platform add ios
Once you have added platforms, you can run setup using this command:
npm run setup
After successful setup you can open the the project in android studio:
android studio project location should be CORDOVA_PROJECT_DIRECTORY/platforms/android
Source:
https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2
i had build the ionic project (sample in 'www' folder) and run the sample in browser. but i need to convert the sample/project in to android app, and want to test that sample in my android phone. please provide what are all the software needed to do this and what are all the step by step procedure.
You will need the Android SDK to compile Android code. Set ANDROID_HOME environment variable to the SDK location.
On windows: set ANDROID_HOME=/path/to/sdk
From the command line, run the following command which generates an Android project:
ionic add platform android
Then build an apk file using this command:
ionic build android
Copy the apk to an Android device for testing.
The next step after starting an ionic project and building the app is deployment.
Make sure your device connected to your machine. Make sure android ionic support is enabled via $ionic platform add android. Check that android is supported via $ionic platform list.
Then build your app.
$ionic build android and run it $ionic run android
This should run to the connected device to test. You can also use emulators by adjusting the run syntax.
I am new to Ionic and Android programming, so I am sorry if there are any inconveniences.
My problem is that I can't see my app (default app in tutorial) on the emulated android virtual device. It just shows a stock android phone basically after I run ionic emulate android. So I assume the app wasn't installed on the emulator.
It builds the apk but doesn't do anything with it it seems.
I think I installed everythink correctly:
> duc#duc-ThinkPad-T450s:~/myApp$ ionic info Your system information:
> Cordova CLI: 6.0.0 Ionic Version: 1.2.4 Ionic CLI Version: 1.7.14
> Ionic App Lib Version: 0.7.0 OS: Distributor ID: Ubuntu Description:
> Ubuntu 14.04.4 LTS Node Version: v4.4.1
I hope you could help me out, just wanted to get the tutorial going :)
Greets, Duc
Edit:
I finally managed to install the apk manually to the emulated device
using this command:
adb -s <your emulator> install </your/apk/path>
However installing it manually is very inconvenient and annoying.
Anyone has a solution for this?
Problem solved!
You have to write in the commandline:
android avd
Then a menu pops up and you have to create your own avd, then start it
Then you need to open a new terminal (ctrl+alt+t).
Cd to the right path of your app.
Now ionic emulate android should work.
You can also use third-party emulator like Genymotion (which works much faster).
Use ionic build android and just drag build APK /platforms/android/build/outputs/apk/android-debug.apk to Genymotion emulator.
I have setup phonegap for android on my machine.I have searched over net and come with two different solutions for starting android project in phonegap
(1) Using Command Line Tool for creating project
phonegap create myFirstApp
cd myFirstApp
and then importing project in eclipse
(2) Directly from eclipse IDE
Choose New > Android Project and then filling necessary information
Now question is which should I use, and which one is better for starting phonegap project for android?
There is obviously, no single answer. You can use any, whatever you are interested in. Also, you can write your entire code in the www folder and may not open Eclipse at all.
Personally, I connect my android phone with USB debugging on, and whenever I feel like testing my app, I type in the command in the terminal
$ cordova run android
If you have configured a Virtual Machine, it will start the virtual machine or the app is installed directly on my device.
The correct way is
3) Using Command Line Tool for creating project
phonegap create myFirstApp
cd myFirstApp
Use any editor to edit the www folder (brackets, sublime)
Use the CLI to run, build, etc.
Forget about eclipse.
According to the Documentation the best way is as follows:
$ cordova create hello com.example.hello HelloWorld
$ cd hello
Then to add platforms:
$ cordova platform add ios
$ cordova platform add amazon-fireos
$ cordova platform add android
$ cordova platform add blackberry10
$ cordova platform add firefoxos
And run the app
$ cordova emulate ios
And build the app
$ cordova build ios
I can't seem to figure out how to open up my android phonegap project in eclipse. I need todo this because I need to customize some android settings and files specifally to install facebook connect on phonegap 3.0.0. The app runs fine on my emulator, but the problem is that I can't find the local android files to open in eclipse. With ios its easy, you go into platforms/ios/projectname.xcodeproj and it opens your ios build in xcode. With android, it's nothing like this. I'm using this tutorial btw: https://github.com/phonegap/phonegap-facebook-plugin/tree/3.0
The Android Platform Guide has instructions on how you can use an IDE (eclipse) with Cordova 3.0.0 and the command line:
Use the command line to set up the new project:
$ cordova create hello com.example.hello "HelloWorld"
$ cd hello
$ cordova platform add android
$ cordova build
After that, open up Eclipse, select "New Project", hit "Android Project from Existing Code", and navigate to the hello/platforms/android folder that was created. This should load the project into your Eclipse workspace and you should be able to edit the Android files just like in the pre-3.0.0 days.