/android-boilerplate

Android boilerplate app that showcases architecture and libraries used at ribot

Primary LanguageJava

Android Boilerplate

Sample Android app that we use at ribot as a reference for new Android projects. It demonstrates the architecture, tools and guidelines that we use when developing for the Android platform (https://github.com/ribot/android-guidelines)

Libraries and tools included:

Requirements

Architecture

This project follows our Android architecture guidelines. Read more about them here.

Code Quality

This project integrates a combination of unit tests, functional test and code analysis tools.

Tests

To run unit tests on your machine:

./gradlew test

To run functional tests on connected devices:

./gradlew connectedAndroidTest

Note: For Android Studio to use syntax highlighting for Automated tests and Unit tests you must switch the Build Variant to the desired mode.

Code Analysis tools

The following code analysis tools are set up on this project:

  • PMD: It finds common programming flaws like unused variables, empty catch blocks, unnecessary object creation, and so forth. See this project's PMD ruleset.
./gradlew pmd
  • Findbugs: This tool uses static analysis to find bugs in Java code. Unlike PMD, it uses compiled Java bytecode instead of source code.
./gradlew findbugs
./gradlew checkstyle

The check task

To ensure that your code is valid and stable use check:

./gradlew check

This will run all the code analysis tools and unit tests in the following order:

Check Diagram

Distribution

The project can be distributed using either Crashlytics or the Google Play Store.

To do this, set up a local variable $ANDROID_DISTRIBUTION to any of the following values:

play-production
play-alpha
play-beta
crashlytics-yourgroupname
crashlytics-yourgroupname2

etc

Then use the following command e.g. on your CI server:

./gradlew clean check connectedAndroidTest assembleRelease $(if [[ $ANDROID_DISTRIBUTION == crashlytics-* ]]; then echo crashlyticsUploadDistributionRelease; else echo publishApkRelease; fi )

New project setup

To quickly start a new project from this boilerplate follow the next steps:

  • Download this repository as a zip.
  • Change the package name.
    • Rename packages in main, androidTest and test using Android Studio.
    • In app/build.gradle file, packageName and testInstrumentationRunner.
    • In src/main/AndroidManifest.xml and src/debug/AndroidManifest.xml.
  • Create a new git repository, see GitHub tutorial.
  • Replace the example code with your app code following the same architecture.
  • In app/build.gradle add the signing config to enable release versions.
  • Add Fabric API key and secret to fabric.properties and uncomment Fabric plugin set up in app/build.gradle
  • Update proguard-rules.pro to keep models (see TODO in file) and add extra rules to file if needed.
  • Update README with information relevant to the new project.