Skip to content

Latest commit

 

History

History
160 lines (108 loc) · 4.51 KB

File metadata and controls

160 lines (108 loc) · 4.51 KB

docker-ubuntu-android-nativescript-vue

Setting up an android development environment is time-consuming and may change from machine to machine. Docker lets me reproduce my development environment everywhere with a one liner.

Here the goal is:

  • Developing on my host (with my preferred IDE and so on)
  • Building and running application inside my docker container but as I had everything installed on my host

This image is based on andreav/docker-ubuntu-android-nativescript Dockerfile

Setup environment

Setup host and scaffold the project

Standard nativescript-vue project initialization:

npm install -g @vue/cli @vue/cli-init
vue init nativescript-vue/vue-cli-template <you project>
cd <your project>
npm install

Now you host is ready, you have a nativescript-vue project and you can start developing

Then "pull" docker files inside your project:

curl -LJ \
     -O https://raw.githubusercontent.com/andreav/docker-ubuntu-android-nativescript-vue/master/Dockerfile \
     -O https://raw.githubusercontent.com/andreav/docker-ubuntu-android-nativescript-vue/master/.dockerignore
     -O https://raw.githubusercontent.com/andreav/docker-ubuntu-android-nativescript-vue/master/docker-compose.yml

Now you can choose if:

  • Run your app on android emulator of your choice: Mode 1
  • Run your app on real device connected to the host: Mode 2

Mode 1 - Run the app on androir emulator

This is the fastest way.

Run these commands:

UIDV=$(id -u) GIDV=$(id -g) docker-compose up
  1. Downloading andreav/ubuntu-android-nativescript image containing:
  • ubuntu 18.04 is the base
  • java 8 openjdj
  • android-28 SDK
  • nativescript 5.4.0
  1. Creating the same host user into the container
  2. Spawning budtmo/docker-android-x86-9.0 emulator
    • Note: you can edit docker-compose.yml to choose another emulator just modifying 'image' entry under 'docker-emu' service
    • All budtmo/docker-android emulator are valid choices
docker exec -it nsvue npm install

Install npm modules into the toolchain container named 'nsvue'

alias tns='docker exec -it nsvue tns'
alias adb='docker exec -it nsvue adb'

adb connect android-emu:5555
adb devices -l
  • Setup a couple of handy aliases for using container like your host
  • Connecting adb on nsvue container to adb on emulator container
tns build android --bundle
tns run android --bundle

Build and run your app on the emulator!

Now point your browser to:

http://localhost:6080/

Thanks to budtmo/docker-android and noVNC you can see emulator directly from your browser.

If you now change source files from host machine, your app will reflect changes on the emulator.

Mode 2 - Run the app on real device

You will need a real android device connected to the host.

Run these commands:

UIDV=$(id -u) GIDV=$(id -g) docker-compose up --no-deps nsvue
  1. Downloading andreav/ubuntu-android-nativescript image containing:
  • ubuntu 18.04 is the base
  • java 8 openjdj
  • android-28 SDK
  • nativescript 5.4.0
  1. Creating the same host user into the container
docker exec -it nsvue npm install

Install npm modules into the toolchain container

alias tns='docker exec -it nsvue tns'
tns build android --bundle
tns run android --bundle
  • Setup a couple of handy aliases for using container like your host
  • Build project for android
  • Run the app on a real device connected to the host

If you now change source files from host machine, your app will reflect changes on the phone.

Installing new node packages

Every time you need to install a new node package you should:

  • Install it as usual on the host

  • Install it also in teh container, issuing:

docker exec -it nsvue npm install

Security

User management

Sharing code from host to container and receiving artifacts from container to host means mixing users among two worlds.

This image follows these guidelines:

  • Running container as NON ROOT, as from best practices
  • Creating a user with same uid:gid as host user into container
  • Running container with host uid:gid

In this way host and container user differences are harmonized and files generated by one or the other world seem the same.

privileged flag

This flag is mandatory for mounting /dev/bus/usb However user inside container is NOT ROOT (unless you build this image as root) so kernel will grant to the container user the same rights your host user will have.

References