Skip to content

Development

Dieter Adriaenssens edited this page Dec 21, 2021 · 68 revisions

Setting up the development environment

Get the source code

Build dependencies

  • Android SDK (API 29) -> Check the system requirements
  • Android Build tools (v29.0.3)
  • Java (OpenJDK 8 or Oracle JDK 8)
  • for the Vagrant-based build environment :
  • Gradle (v6.8), with Android for Gradle plugin (v4.4.1))
  • used libraries :
    • Crouton v1.8.1, Apache 2.0 (library is installed during gradle build)
  • unit test libraries:
    • jUnit v5.7.0 (plugin is installed during gradle build)
    • android-junit v1.7.0 (plugin is installed during gradle build)
    • Mockito v3.7.7 (plugin is installed during gradle build
  • optional build tools :
    • jacoco (plugin is installed during gradle build)
    • coveralls-jacoco v1.2.7 (plugin is installed during gradle build)
    • javadoc (plugin is installed during gradle build)

Setup the Vagrant build environment

Create/start the Vagrant box

In the root of the getback_gps project :

vagrant up

The first time 'vagrant up' is started, the vagrant box is created. This can take several minutes, depending on your speed of your internet connection and the speed of your machine.

Every other time, 'vagrant up' launches the already provisioned Virtual box.

Connect to the Vagrant box

After starting the Vagrant box (with 'vagrant up'), you can login to the Vagrant VirtualBox. From the root of the getback_gps project :

23:12 $ vagrant ssh
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-141-generic x86_64)

vagrant@ubuntu-xenial:~$ cd /vagrant/
vagrant@ubuntu-xenial:/vagrant$

The getback_gps project folder is mounted in /vagrant folder inside the Vagrant Virtualbox.

Build and test the code

build and run unit tests : ./gradlew clean test

build and run unit tests + lint : ./gradlew clean check

build and test with code coverage report : ./gradlew clean test jacocoTestReport

publish coverage report to Coveralls : ./gradlew coverallsJacoco (requires COVERALLS_REPO_TOKEN env variable)

build and deploy to an Android device : ./gradlew clean installDebug

Test results

  • test report build/reports/tests/testReleaseUnitTest/index.html
  • test coverage report jacoco : build/reports/jacoco/jacocoTestReportRelease/html/index.html
  • test coverage report on Coveralls

Enable debug mode for an android device

Lookup vendor id and product id

ubuntu@ubuntu-xenial:~$ lsusb
Bus 001 Device 002: ID 18d1:4ee2 Google Inc. Nexus 4 (debug)

In this example, vendor id is '18d1', product id is '4ee2'.

Add vendor id and product id to udev rules

in provisioning/files/51-android.rules

SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="4ee2", GROUP="plugdev"

and run vagrant provision to install the 51-android.rules file to /etc/udev/rules.d/

Add vendor id and product id to vagrant setup

To make the android device available in the vagrant environment :

in Vagrantfile

  config.vm.provider "virtualbox" do |v|
    v.customize ["modifyvm", :id, "--usb", "on"]
    v.customize ["modifyvm", :id, "--usbxhci", "on"]
    v.customize ['usbfilter', 'add', '0', '--target', :id, '--name', 'Google Inc. Nexus 4 (debug)', '--vendorid', '0x18d1', '--productid', '0x4ee2']
  end

Add user to vboxusers

Make sure the user starting vagrant belongs to the vboxusers group

$ groups $USER
john : adm cdrom sudo dip plugdev lpadmin sambashare

$ sudo usermod -a -G vboxusers $USER

$ groups $USER
john : adm cdrom sudo dip plugdev lpadmin sambashare vboxusers

Enable PTP transfer mode

On the Android device, enable Debug mode and PTP transfer mode.

Debugging adb connections

More info in : https://stackoverflow.com/questions/25614067/android-studio-recognizes-physical-device-as-null

List connected android devices

vagrant@ubuntu-xenial:/vagrant$ adb devices -l
List of devices attached
ZY224J75HS             device usb:2-1 product:payton model:moto_x4 device:payton transport_id:1