Prev
15. GUI Application
Next
17. Web Application

16. exercise: Android Application

General steps

Download files

  1. Download android-studio-ide-...-linux.zip from bcserver (or from https://developer.android.com/studio/) and extract it in proper place.

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 8.0 (Oreo), 26, 2 .. 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 Oreo, 26, x85, Android 8 (Google APIs) and press next.
  5. Review proposed name of AVD (name should show API version) 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 26: Android 8.0 (Oreo) 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 26 (Android 8.0.0., API 26) 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_Abcd

    where Abcd is your unique project code

  2. Change configuration files:

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

      ...
      <string name="app_name">Android_Abcd</string>
      ...

      where Abcd is your project code in with uppercase letters allowed

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

      ...
      applicationId "jtm.android_abcd"
      ...

      where abcd 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_abcd 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 bcserver

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 bcserver

  1. Connect with SSH to the bcserver and create remote Git repository with commands:

    ssh student@bcserver
    mkdir /home/git/Android_Aaaa
    cd /home/git/Android_Aaaa
    git --bare init
    exit

    where Aaaa is code of your project.

  2. Change URL of remote repository origin to the bcserver:

    cd ~/AndroidStudioProjects/Android_Aaaa
    git remote set-url origin ssh://student@bcserver/home/git/Android_Aaaa/

    where Aaaa is code of your project.

  3. Add, commit and push all your changes to the bcserver:

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

Optional task — clone your project back from server

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

  1. Run following commands in terminal:

    cd ~/AndroidStudioProjects/
    git clone ssh://student@bcserver/home/git/Android_Aaaa/ Android_Aaaa1

    where Android_Aaaa is your original project, but Android_Aaaa1 newly cloned project.

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

Prev
15. GUI Application
Next
17. Web Application
Tags:
Created by Valdis Vītoliņš on 2018-03-26 10:58
Last modified by Valdis Vītoliņš on 2019-08-21 11:19
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License