Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Project setup

ctumwebaze edited this page Jun 19, 2014 · 64 revisions

This page is only for setting up development environment for Mobile App . If you are looking for Web app Source Code & Details go here

  • Mobile App Source Code available here.

This is maven project for more information on how to develop android application with maven see Getting started with the android maven plugin and also Android Application Development with Maven

We are currently targeting Android v2.3 because those are the devices that are currently used. However, this is going to change as we shall be supporting Android v4.0.x

Development Environment Setup

  • RapidFTR-Android maven project have the source code along with the the unit test code. Unit tests are written with the help of Robolectric, Mockito and PowerMock.
  • The RapidFTR-Android contains a folder called feature which is the home of the android integration tests run with calabash

Android SDK download

  • Download the android sdk from the android developers website and unzip the same. If you are on Mac, it is recommended to use homebrew to install Ex: 'brew install android'
  • Entering 'android' command in your terminal will launch the Android SDK Manager. We will use the SDK Manager to install the appropriate Android Platform version. Since we want to support a wide varierty of Android phones, we will compile and build with 2.2 version (API Version 8) of Android. Install version 2.2 from the SDK manager GUI.
  • Create an AVD (from within the SDK Manager) with the size 240320. The lease resolution we would be using is 240320, so, testing for that resolution will help.

As an alternative to using the android AVD, you can use Genymotion for instructions on how to setup and use Genymotion visit (https://cloud.genymotion.com/page/doc/)

Setting up RapidFTR Android for working with Vim or Text Editor (on a Mac)

  • Mac ships Java 1.6 by default(/System/Library/Java/JavaVirtualMachines/1.6.0.jdk) as well as maven. We faced some issues with Java 1.7 so set your $JAVA_HOME to the path above.
  • To get started clean remove $HOME/.m2 folder (if it exists on your machine).
  • Then install android-sdk with brew (brew install android-sdk)
  • Add "export ANDROID_HOME=/usr/local/opt/android-sdk" to your .bashrc or.zshrc file.
  • Open a new terminal and type android
  • See the attached screenshot of android packages screen. Make sure you install packages that are shown here.
  • Once you install everything then from menu bar choose "Tools" --> "Manage AVDs"
  • Add a new minimalist avd (check the screenshot attached)
  • Once added close everything and go back to terminal then type "emulator -avd x"(Note: x is the avd name used in screenshot, change it to whatever you want it to be). The command should start an emulator, give it a minute to start completely.
  • Type "adb devices" this should start daemon server if it hasn't already and then display list of devices. You should see something like this displayed "emulator-5554 device". If it says "emulator-5554 offline" wait for a minute and try again. If the device refuse to come online then kill the emulator and start it again, give it few minutes and try this command "adb kill-server && adb devices"
  • Once the device is up, navigate to your RapidFTR---Android code base and simply run "mvn clean install" It will install all maven packages and run all the unit tests and integration test. If everything passes or even runs completely with failing tests then you are good to go for development with a text editor.
  • NOTE: If on running 'mvn clean install' you get the error 'command not found: mvn', that means maven is not installed. You can install it by running 'brew install maven30' - this installs maven 3.0.5 rather than the latest version which usually causes problems

Android Setup Image

Click here to see AVD Setup screenshot

IDE setup

IntelliJ Idea 11

  • Click File -> Open Project and select the pom file, and the Maven project will be automatically imported.
  • Intellij comes with default Android support, so once the project is loaded it asks for configuring the android framework. Go ahead and configure the framework.
  • From IntelliJ Preferences -> Plugins, install the Lombok Plugin. We are using Project Lombok to generate helper methods (like getters, setters, etc)
  • To run the tests in IntelliJ edit the default JUnit run configuration and amend the working directory to point to ...../RapidFTR---Android/RapidFTR-Android (by default it will just point to ...../RapidFTR---Android )
  • If you get any error related to maven, then click on Preferences => Maven then specify the Maven home directory: to the path of the maven home (In Mac OSX its /usr/share/maven.)
  • If you get an error saying "ANDROID_HOME" not found, go to IntelliJ Preferences > Path Variables, and add an entry for ANDROID_HOME. The ANDROID_HOME points to the "sdk" folder in your Android SDK.
  • If you get compilation errors related to getters, setters, etc - it could be a Lombok configuration issue. Go to IntelliJ Preferences -> Compiler -> Java Compiler and append "-classpath <path-to-your-lombok.jar>" to the Additional Command Line parameters. You may also need to un-check "Enable annotation processing" under Compiler -> Annotation Processors as well.

IntelliJ IDEA 12

  • Delete any old IDEA project config files from the codebase. You can do this by going to the RapidFTR---Android folder in command prompt and run git clean -f -x -d
  • In IntelliJ IDEA 12, select Import Project, select the pom.xml file in the RapidFTR---Android folder. Check Search for projects recursively and Import Maven projects automatically. Click Next -> Next -> Next. In the Please select project SDK dialog, click the + icon, choose the Android SDK folder (most likely /usr/local/Cellar/android-sdk/), and then select Android 2.2 as the build target. Finish the import NOTE: Press Cmd + Shift + . in the file chooser dialog to show hidden files
  • Go to IntelliJ Preferences -> Compiler -> Annotation Processors -> Maven default annotation processors, select the Processor Path radio button and in the text box enter full path to Lombok jar.
  • IntelliJ still has some bugs with Maven and Android. You again have to open File -> Project Structure -> SDKs, and in the right side you will find some Android SDKs listed. Click each of those, and in the right side you will find some jar files in the classpath. In case they are not properly populated by IntelliJ, toggle the Build target from 2.2 -> something else -> back to 2.2 just for IntelliJ to properly detect all the jar files in the Android SDK
In case of errors continue with the following steps:
  • From commandline execute "android update project -p pathToRapidFTR---Android/RapidFTR-Android". This generates local.properties and proguard-project.txt
  • Run "cat pathToRapidFTR---Android/RapidFTR-Android/local.properties | grep sdk.dir". This gives the sdk path (needed for the next step)
  • Open IntelliJ File -> Other Settings -> Default Settings -> Maven -> Runner click "+" under "Properties" and add a new property with name "android.sdk.path" with the sdk path(from previous step) as value
  • View ->Tool Windows -> Maven Projects. Expand RapidFTR Android Parent -> Lifecycle -> install. This downloads all dependencies and runs the test suite, make sure you have your emulator started from a terminal for the integration tests to run.
  • Run -> Edit configurations -> (On the left pane) Defaults -> JUnit
  • By default the working directory is set to your project path. Change this to point to pathToRapidFTR---Android/RapidFTR-Android
  • When trying to build the project and you encounter "java: invalid flag: UTF-8", ensure that the field "Additional Command Line Parameters" under "Compiler > Java Compiler" is left blank.

Eclipse

  • Download the Eclipse ADT plugin for android and also m2eclipse plugin
  • Download Project Lombok and run the JAR file to install it in Eclipse
  • Import the project as existing maven project. If eclipse is not able to run the app because of the heap issues then increase the heap memory in eclipse.ini. Here are some of the configurations recommended -XX:MaxPermSize=1536m -Xms1536m -Xmx1536m

Run the tests

  • You can run all the tests from the android parent directory RapidFTR---Android by using the command mvn clean install. This will also generate the .apk files which could be installed on the mobile phones for testing.
  • To run unit tests alone, navigate to RapidFTR-Android folder and then run mvn clean install. Same is the case with integration-tests, move to RapidFTR-AndroidTests and run mvn clean install.
  • To run individual unit test from IntelliJ, go to the unit test and run it a junit test. You might get some error, If you get an error, edit the configuration and select the working folder as RapidFTR-Android sub folder instead of RapidFTR---Android main folder.

Making Android Emulator Run Faster On Your machine

See RapidFTR Google Group post here on steps for creating AVD: Click Here

Why Maven

  • Though ANT will work for us, as we are using good amount of external jar files, we need some kind of dependency management tool.
  • Any dependency management tool helps project to be moved easily from one machine to the another and aids in easy setup of the IDE.(ex: maven handles the dependency and the build stuff) - IDE neutral.
  • Dependency management will be provided by many tools including ivy, gradle etc,. But android-maven-plugin seems to be widely used and have very good active community(have many releases in the recent past).
  • Android-maven-plugin in specific gives most of the phases of android development for free - apk, apklib, zip, align, unpack, deploy, deploy-dependencies, redeploy, undeploy, emulator-stop/start run, push and pull logs.
  • Maven by default provides a standard release workflow - multiple profiles and patching up an existing library or stripping of some unnecessary classes out of jar(maven-shade-plugin)
Clone this wiki locally