The notes below are my journey to move from Visual Studio Tool for Apache Cordova to the CLI option. I use same machine to install the required new components. Hopefully it can help anyone who chooses a similar path as mine.
SETTING UP FRAMEWORKS
First I had Node.js, recent Cordova and Ionic installed. Once they were installed I tried to create a new test app by running:
ionic start myApp sidemenuthen it will show:
+ ionic@4.2.1Chose yes and continued with the installation.
added 242 packages from 151 contributors in 43.756s
? Integrate your new app with Cordova to target native iOS and Android?
After installation:
cd myApp ionic serveI made sure the app could be compiled successfully and showed in a browser.
Then I added Android platform:
ionic cordova platform add androidTo check the installed version run:
cordova platform version androidThen it showed:
7.1.1 is the latest version
SETTING UP EMULATOR
Next, I tried to set up the emulator with latest version of Android. But first I wanted to make sure that I could run an existing virtual device from AVD Manager.
When trying to run one, I got this error:
“Could not find an installed version of Gradle either in Android Studio,I installed Gradle from the website and set an environment variable for it.
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
[ERROR] An error occurred while running subprocess cordova.”
The second error I got after trying to run the emulator:
“Could not unzip C:\Users\rical\.gradle\wrapper\dists\gradle-4.1-all\bzyivzo6n839fup2jbap0tjew\gradle-4.1-all.zip to C:\Users\rical\.gradle\wrapper\dists\gradle-4.1-all\bzyivzo6n839fup2jbap0tjew.I deleted the zip folder and run the command again.
Reason: error in opening zip file
Exception in thread "main" java.util.zip.ZipException: error in opening zip file”
Then I got another error:
“Error occurred during initialization of VMI went to Start -> Control Panel -> System -> Advanced(tab) -> Environment Variables -> System Variables and add new variable:
Could not reserve enough space for 2097152KB object heap”
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M
After trying to run the emulator again, another error shown up:
“A problem occurred configuring project ':CordovaLib'.Went to SDK Manager and install SDK Platform 27 and Android SDK Build-Tools 26.0.2.
> You have not accepted the license agreements of the following SDK components:
[Android SDK Platform 27, Android SDK Build-Tools 26.0.2].
Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.”
The emulator is working now, but I received a warning:
“Running an x86 based Android Virtual Device (AVD) is 10x faster. We strongly recommend creating a new AVD.”Solved this by installing Intel x86 Atom_64 or Intel x86 Atom and setting the emulator (AVD) to use one of them.
I received another error “PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT”. I created a new environment variable called ANDROID_SDK_ROOT that has my SDK path, something like "C:\Program Files (x86)\Android\android-sdk". Then restarted the machine.
I wanted to use recent version of Android which is version 8 or 9 but after installing the system images, I got this error:
“This AVD's configuration is missing a kernel file! Please ensure the file "kernel-qemu" is in the same location as your system image”I found a great article to solve the issue https://www.andreszsogon.com/using-android-8-and-9-emulators-without-android-studio
I followed the instructions:
- download emulator-windows-4848055.zip
- uninstall my current Android 8 and newer system images
- close my Android SDK Manager and AVD Manager tools if open
- extract the contents from the ZIP file into my android-sdk/tools
- download the desired emulator’s System Images from the SDK Manager
- create a new emulator from the AVD Manager
- start a virtual device
Received another error:
“emulator: ERROR: x86 emulation currently requires hardware acceleration!Went to Turn Windows features on and off, checked Windows Hypervisor Platform.
Please ensure Windows Hypervisor Platform (WHPX) is properly installed and usable.
CPU acceleration status: HAXM is not installed on this machine”
Finally, I could run a virtual device from the AVD Manager.
When I tried to run from command prompt:
ionic cordova emulate --target=My_Android_9_Virtual_Device androidI got another error:
“A problem occurred configuring project ':CordovaLib'.I found out that cordova-android 7.1.1 only supports up to Android 8.1 (SDK 27). So I needed to download the SDK Platform and a choice of system image of the newer version.
> Failed to find Platform SDK with path: platforms;android-27”
Finally, the emulator from command prompt is working!
No comments:
Post a Comment