If it is not explicitly told in following recipe, setting up services are described for Ubuntu 20.04 server, but applications are described for Xubuntu 20.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

17. Android Application


  1. Review presentation

    Practical exercise

Download files

Download Android studio from https://developer.android.com/studio/ and extract it in proper place.

Set up your Android phone

  1. Go to Settings, then tap About device or About phone
  2. Scroll down, then tap Build number seven times
  3. If necessary, enter your pattern, PIN or password to enable the Developer options menu
  4. Go back to Settings, select Developer options menu
  5. Scroll down Developer optiosns and enable USB debugging

Set up IDE

  1. Install Android debugger:

    sudo apt-get install android-tools-adb

Set up SDK and AVD

To be able to compile and run Android project, you have to have compatible set of:

  1. project settings (for which version of API it will be compiled (declared in app/build.gradle file),
  2. appropriate libraries for compiler and Android runtime (SDK),
  3. physical (i.e. your phone) and/or virtual device (AVD), which supports chosen API version.

Set up SDK

  1. If necessary, close any project and open Welcome to Android Studio window.
  2. Select  Configure — SDK Manager.
  3. Click on Android 11.0 (R), 30,... and press OK.
  4. Close SDK Manager window.

Set up AVD

  1. If necessary, close any project and open Welcome to Android Studio window.
  2. Select Configure — AVD Manager and clic on + Create Virtual Device.
  3. Select Phone, 2,7" QVGA and press Next.
  4. Select R 30, x86, Android 11 (Google APIs) and press next.
  5. Review proposed name of AVD (name should show API version) e.g. 2.7 QVGA API 30 and press Finish.
  6. Close AVD Manager window.

Create simple test project

  1. If necessary, close any project and open Welcome to Android Studio window.
  2. Select Start new Android Studio project.
  3. Review proposed names and press Next.
  4. Select Phone and Tablet and choose API 30: Android 11 (R) and press Next.
  5. Select Basic Activity and press Next.
  6. Review proposed names and press Finish.

Run simple test project

  1. If necessary, check that you have opened your test project.
  2. Select menu Run — Run....
  3. Select MainActivity.
  4. Select 2.7 QVGA API 30 virtual machine and press OK.
  5. Check that application works properly (i.e. clicking on envelope shows pop up menu).

Clone and implement actual project

  1. Clone project:

    cd ~/AndroidStudioProjects
    git clone https://odo.lv/git/Android_Test Android
  2. Change configuration files:

    1. In app/src/main/res/values/strings.xml file change line:

      <string name="app_name">uuXXXX</string>

      where uuXXXX is your indentifier

    2. In app/build.gradle file change line:

      applicationId "jtm.uuXXXX"

      where xx is your project code in lowercase letters (because by convention Java packages have only lower case letters).

  3. In Android Studio welcome screen select Import project (Gradle, Eclipse ADT, etc.)

    Importing project instead of directly opening goes better, if there are configuration changes caused by newer version of the Android Studio.

    1. Select Android project and press OK.
    2. Check for warnings and suggested fixes, if project needs to be upgraded.
  4. Implement jtm.android.MainActivity.java class of the application, to allow user changing background color of screen using sliders representing RGB colors.
    1. Select menu app — java — org.jtm — MainActivity,
    2. Write your code in necccesary parts of MainActivity.java file.
  5. Check that unit tests are passing:
    1. Select menu app — java — jtm.android — JUnitTest — JUnit unit test,
    2. Select menu app — java — jtm.android — AndroidTest — Android GUI test.
  6. Change existing remote repo entry or add new remote repo entry to the  tools.odo.lv

More info

  1. http://developer.android.com/reference/packages.html including:
  2. Change background color, by SeekBar
  3. https://developer.android.com/training/testing/fundamentals.html
  4. https://developer.android.com/studio/test/

Push changes to the tools.odo.lv

  1. Connect with SSH to the tools.odo.lv and create remote Git repository with commands:

    ssh uuXXXX@tools.odo.lv
    mkdir Android
    cd Android
    git --bare init

    where uuXXXX is your identifier.

  2. Change URL of remote repository origin to the tools.odo.lv:

    cd ~/AndroidStudioProjects/Android
    git remote set-url origin ssh://uuXXXX@tools.odo.lv/home/students/uuXXXX/Android/

    where uXX is your identifier

  3. Add, commit and push all your changes to the tools.odo.lv:

    cd ~/AndroidStudioProjects/Android
    git add -A
    git commit -m "Your comment"
    git push origin master

Optional tasks

Clone your project back from server

To be sure that project pushed to tools.odo.lv is right, you can clone it back to your computer and check it:

  1. Run following commands in terminal:

    cd ~/AndroidStudioProjects/
    git clone ssh://uuXXXX@tools.odo.lv/home/students/uuXXXX/Android/ Android-1

    where Android is your original project, but Android-1 newly cloned project.

  2. Import project Android-1 in Android Studio and check that it works properly.


Created by Valdis Vītoliņš on 2021-01-27 15:09
Last modified by Valdis Vītoliņš on 2023-04-13 21:37
Xwiki Powered
Creative Commons Attribution 3.0 Unported License