17. Android Application
Main steps
- Download files
- Set up your Android phone
- Set up IDE
- Clone and implement actual project
- Push changes to the tools.odo.lv
- Optional tasks
Download files
Download Android studio from https://developer.android.com/studio/ and extract it in proper place.
Set up your Android phone
- Go to Settings, then tap About device or About phone
- Scroll down, then tap Build number seven times
- If necessary, enter your pattern, PIN or password to enable the Developer options menu
- Go back to Settings, select Developer options menu
- Scroll down Developer optiosns and enable USB debugging
Set up IDE
Install Android debugger:
sudo apt-get install android-tools-adb
Set up SDK and AVD
Set up SDK
- If necessary, close any project and open Welcome to Android Studio window.
- Select Configure — SDK Manager.
- Click on Android 11.0 (R), 30,... and press OK.
- Close SDK Manager window.
Set up AVD
- If necessary, close any project and open Welcome to Android Studio window.
- Select Configure — AVD Manager and clic on + Create Virtual Device.
- Select Phone, 2,7" QVGA and press Next.
- Select R 30, x86, Android 11 (Google APIs) and press next.
- Review proposed name of AVD (name should show API version) e.g. 2.7 QVGA API 30 and press Finish.
- Close AVD Manager window.
Create simple test project
- If necessary, close any project and open Welcome to Android Studio window.
- Select Start new Android Studio project.
- Review proposed names and press Next.
- Select Phone and Tablet and choose API 30: Android 11 (R) and press Next.
- Select Basic Activity and press Next.
- Review proposed names and press Finish.
Run simple test project
- If necessary, check that you have opened your test project.
- Select menu Run — Run....
- Select MainActivity.
- Select 2.7 QVGA API 30 virtual machine and press OK.
- Check that application works properly (i.e. clicking on envelope shows pop up menu).
Clone and implement actual project
Clone project:
cd ~/AndroidStudioProjects
git clone https://odo.lv/git/Android_Test AndroidChange configuration files:
In app/src/main/res/values/strings.xml file change line:
...
<string name="app_name">uuXXXX</string>
...where uuXXXX is your indentifier
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).
In Android Studio welcome screen select Import project (Gradle, Eclipse ADT, etc.)
- Select Android project and press OK.
- Check for warnings and suggested fixes, if project needs to be upgraded.
- Implement jtm.android.MainActivity.java class of the application, to allow user changing background color of screen using sliders representing RGB colors.
- Select menu app — java — org.jtm — MainActivity,
- Write your code in necccesary parts of MainActivity.java file.
- Check that unit tests are passing:
- Select menu app — java — jtm.android — JUnitTest — JUnit unit test,
- Select menu app — java — jtm.android — AndroidTest — Android GUI test.
- Change existing remote repo entry or add new remote repo entry to the tools.odo.lv
More info
- http://developer.android.com/reference/packages.html including:
- SeekBar.OnSeekBarChangeListener class
- Color class
- Change background color, by SeekBar
- https://developer.android.com/training/testing/fundamentals.html
- https://developer.android.com/studio/test/
Push changes to the tools.odo.lv
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
exitwhere uuXXXX is your identifier.
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
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:
Run following commands in terminal:
cd ~/AndroidStudioProjects/
git clone ssh://uuXXXX@tools.odo.lv/home/students/uuXXXX/Android/ Android-1where Android is your original project, but Android-1 newly cloned project.
- Import project Android-1 in Android Studio and check that it works properly.