Search This Blog

Wednesday, May 17, 2017

Ionic app development on virtual machine with Android SDK


If you have planned to use virtual machine for mobile development and you have used VMware or virtual box to emulate the android device from ionic, this post is for you.

If your app is ready and working via the ionic serve, its right time to bundle and see if it can be deployed to the android device. There can be other reasons like you may want to test the Bar code or the GPS of your phone inside your app. In both the cases you will need to build the app for android via ionic and render it inside the android emulator.

In this section we will see how to quickly setup the android device emulator.
First you need to download the android sdk and run the installation.
https://developer.android.com/studio/index.html
Download and run the setup with Admin access.
If PATH and ANDROID_HOME are not updated after the install is complete, do that manually.
PATH – /sdk/tools
ANDROID_HOME – /sdk

Open new windows command prompts and test the path command by typing android, it should work.

Now its time to build our ionic app
> ionic build android

You might face an error on the build, about some license crap.
Follow the solution below.

======================================================
Can't accept license agreement Android SDK Platform 24
======================================================
Follow this
http://stackoverflow.com/questions/40383323/cant-accept-license-agreement-android-sdk-platform-24

If the build is successful proceed, else keep debugging it.


It should build the app, lets test if ionic is connected to the emulator.
> ionic emulate android

If android emulator doesn’t turn up, it could be a problem with your AVD(android virtual device) or the hardware virtualization is not enabled for your VM, I mentioned enabling the Intel Vtx setting of the processor on the vmware settings in the tutorial (How to build a hybrid mobile app using ionic ?)
vm processor android adb virtualization



If you don’t enable the virtualization support , you will get following error.
===================
Emulator: ERROR: x86 emulation currently requires hardware acceleration!
Please ensure Intel HAXM is properly installed and usable.
CPU acceleration status: HAX kernel module is not installed!
============================
Solution : To fix the above error, go to
C:\Android\sdk\extras\intel\Hardware_Accelerated_Execution_Manager
Click to Install, use admin privileges
intelhaxm-android.exe

==========================================
Now lets test the emulator independently and later we will test from ionic.

Go to sdk/avd manager.exe and open it.

avd settings android for virtual machine vmware
I have a Nexus 5 avd configured, for first time use you will have to create an AVD by clicking create.You need to attach the processor image, i had to download it the first time ~ 800mb
Before trying the android emulate from ionic, try to open emulator by clicking the start button once you have created the image.

Let me show my settings for the AVD, these are very important settings without which the Android emulator won’t boot properly.

image
I couldn’t get the AVD boot by using the host gpu and i had to uncheck it, else I was getting the following error.
Error
====================================
ensionString: Could not create GLES 1.x Pbuffer!
====================================
Solution: Uncheck use host gpu option on avd settings.
I had to update the sdk manager with new sdks versions ( 25)
After I updated my SDK and tools to new version which is 25, my HAXM stopped working and the error it displayed was related to version ( 1.1 <6). I had to download the new HAXM from the intel site which is compatible with the new versions.
Your HAXM is located in
sdk/extras/intel/*
https://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager.

After all this when i tried to boot the AVD, it was so slow and it was only showing the android sign.
image
That’s it, for around 30 minutes, I checked a few places and found it it takes time to load at first time.
And I tried to check the logs by

> adb logcat
and found it was trying to compile some packages and after a while it loaded.
image

Later i could push the app the android by running the following command.
> ionic run android
image

and my app was pushed to the device.
adk pushed to android avd on vm by ionic

If you want to push the app to a real device, follow the previous article on “How to push ionic mobile app to a real android phone connected to virtual machine” over a usb.

Keep Reading !

No comments:

Post a Comment