The problem
As usual the problem is setting up the development environment for a project. This time it's going to be project using the Quasar framework and building the app for Android. This guide assumes a clean environment that does not contain anything (no Java, no Node no nothing).
Solution
First we need to have NodeJS installed. I install mine using the Node Version Manager (or nvm for short). Follow the instructions on https://github.com/creationix/nvm or simply enter the following commands:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
At this stage you need to close the current terminal and open a new one for the installation to finish and then install the latest stable NodeJS like so:
$ nvm install stable
We'll need two more things: JDK and Gradle. I install mine using the SdkMan:
$ curl -s "https://get.sdkman.io" | bash
At this stage you need to close the current terminal and open a new one for the installation to finish and then install Java and Gradle like so:
$ sdk install java
$ sdk install gradle 2.14.1
The version of Gradle is important. Cordova works with specific versions so you might want to stick to 2.14.1 to avoid any issues
Next we need to have some basic tooling for NodeJS installed. This includes obviously the Quasar CLI but also Yarn and Cordova
$ npm install -g yarn quasar-cli cordova
Having all that installed we can now instantiate and build our first project
$ quasar init hello-world
$ cd hello-world
$ yarn
$ yarn build
At this stage we have have the hello-world type quasar application built. We can work on it as if it would be any other VueJS application by running
$ yarn dev
More on it in the official documentation for Quasar
What we need next is the Android SDK. This is the most troublesome part of all, but if scripted it doesn't seem to be all that hard. First you need to download and extract the Android SDK. To do that we'll use the unzip tool that understands the .zip
archive format. Be patient. It takes forever to download and install all the components. On my connection it took almost 10 minutes!!!
$ sudo apt install -y unzip
$ mkdir -p ~/Android/Sdk
$ cd ~/Android/Sdk
$ wget -c https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
$ unzip -q sdk-tools-linux-3859397.zip
$ cd tools/bin
$ ./sdkmanager --update
$ ./sdkmanager emulator platform-tools
$ ./sdkmanager "build-tools;25.0.3"
$ ./sdkmanager "platforms;android-25"
$ ./sdkmanager "system-images;android-25;google_apis;x86"
$ ./avdmanager create avd --force \
--name test \
--package "system-images;android-25;google_apis;x86" \
--tag google_apis \
--device 'Nexus 4'
Starting the emulator takes some time - be patient!
$ ~/Android/Sdk/tools/emulator -avd test -skin 768x1280
After it is up we have a platform to run our Quasar application on. Let's use it to run our new and shiny app.
$ cd [your_project_folder]
$ quasar wrap cordova
$ cd cordova
$ ANDROID_HOME=~/Android/Sdk cordova platform add android
$ ANDROID_HOME=~/Android/Sdk cordova build
$ ANDROID_HOME=~/Android/Sdk cordova run
That's it! The application should be running on your virtual Android device. Of course you should make the ANDROID_HOME
variable more permanent by adding it to your .profile
or .bashrc
startup files but I'll leave it up to you.
Have fun!
No comments:
Post a Comment