CommCare is an easily customizable, open source mobile platform that supports frontline workers in low-resource settings. By replacing paper-based forms, frontline workers can use CommCare to track and support their clients with registration forms, checklists, SMS reminders, and multimedia.
This repository represents the Android version of CommCare. It depends on the CommCare Core repository, which contains the XForm engine and case/lookup table implementations.
To set up an Android dev environmnet for commcare-android, do the following:
- Install Android Studio.
- Install Java 8 if you don't have it yet. For ease of test suite setup (see below) OpenJDK is preferred over Oracle's version of Java.
Go ahead and open Android Studio if this is your first time using it; it may take you through some sort of setup wizard, and it's nice to get that out of the way.
Android Studio's default project space is ~/AndroidStudioProjects
so I'm going to use that in the example.
CommCare Android depends on CommCare Core, and CommCare Android expects the core directory to live side by side
in your directory structure. You can acheive this with the following commands (in bash):
cd ~/AndroidStudioProjects
mkdir CommCare
cd CommCare
git clone https://github.com/dimagi/commcare-android.git
git clone https://github.com/dimagi/commcare-core.git
- Open Android Studio
- If this is your first time using Android Studio, click "Config" and setup the Android SDK.
- Download the Android 7 (API 24) SDK Platform and the Google APIs for 24.
- Now go back to the Android Studio Welcome dashboard and click "Import project (Eclipse ADT, Gradle, etc.)"
- Select AndroidStudioProjects > CommCare > commcare-android and hit OK
- Click "OK" to use the Gradle wrapper
- Wait while Android Studio spins its wheels
- Download any build dependencies that the SDK Manager tells you you need.
Now you're basically ready to go. To build CommCare Android and get it running on your phone, plug in an android phone that
- is in developer mode has USB debugging enabled
- doesn't have CommCare Android installed on it
In Android Studio, hit the build button (a green "play" symbol in the toolbar). The first build will take a minute. Then it'll ask you what device to run it on
- Make sure your screen is unlocked (or else you'll see something like this)
- select your device
Enjoy!
CommCare has several different build variants. The normal build variant is commcare
and can built built from the command-line with the following command:
cd commcare-android
gradle assembleCommcareDebug
# the apk can now be found in the build/outputs/apk/ directory
The commcare-android repository uses Robolectric, which provides mocks, allowing you to run Android specific code on your local machine.
cd commcare-android
gradle testCommcareDebugUnitTest
and view the results from the output file generated.
Create a new Android Studio JUnit Build configuration using the following steps.
- Click Run -> Edit Configruations and create a new JUnit configuration by pressing the green plus button.
- Set Name to "commcare android test suite"
- Set Test kind to "All in directory"
- set Directory to
/absolute/path/to/commcare-android/app/unit-tests/src/
- Right click on this directory and click the "Create 'All Tests'" option that should be listed more than half-way down the list.
- Set VM options to
-ea -noverify
- Set Working directory to
/absolute/path/to/commcare-android/app/
- Set Use classpath of module to app
- Click
OK
to finish creating the configuration. - Select the "commcare android test suite" under the configuration drop down to the left of the green play button.
- Press the green play button to run the tests.
java.security.InvalidKeyException: Illegal key size or default parameters
you will need to upgrade the JCE policy files that are being used. To do so:
- Download the JCE Unlimited Strength policy files for Java 8 (Last we checked they could be found here, but this can change
- Find the java home directory on your machine. On mac you can do so by entering the following into the command line:
echo $(/usr/libexec/java_home)
- From there, cd into
jre/lib/security
, and replace the local_policy.jar and US_export_policy.jar files found there with the ones in the zip file you downloaded
NOTE that if you are running the tests from Android Studio, it may be using a different version of Java than that in your java home directory. The first line of the test output will usually show the directory from which Android Studio is running Java. If it is indeed different, you should follow the steps above for that directory as well.
Android Monitor in Android Studio shows the following exceptions:
java.lang.RuntimeException: CommCare ran into an issue deserializing data while inflating type
...
Caused by: org.javarosa.core.util.externalizable.DeserializationException:
No datatype registered to serialization code [4b a9 e5 89]
Resolution:
-
Disable Instant Run found in Settings > Build, Execution, Deployment > Instant Run.
-
Maybe also edit ~/.gradle/gradle.properties (may not exist) and add a line like
org.gradle.jvmargs=-Xmx1536M
if the build fails due to OOM or you see a message like the following during the build:To run dex in process, the Gradle daemon needs a larger heap. It currently has 1024 MB. For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB. To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties.
-
Click Run 'app' to rebuid and run on phone.