Skip to content

Android project build structure

anandsadu edited this page May 18, 2016 · 5 revisions

Project structure:

Project built using Gradle and contains two flavors namely e2eTest and server. refer Gradle Build Variants for more info on build variants and flavors.

    productFlavors {
            e2eTest {
                applicationId 'io.appium.uiautomator2.e2etest'
            }
            server {
                applicationId 'io.appium.uiautomator2.server'
            }
        }

Flavor e2eTest contains all tests against to implemented handlers.

Flavor server contains code snippet to run the server.

Handlers implementation will be available in base implementation(main repo).

Refer this repo structure for more info.


Building the Flavors:

Whenever we build any of the flavor, resultant build will consist Handlers implementation(base implementation) and corresponding flavor related implementation(in our case either e2eTest or server).

Building server flavor:

gradle clean assembleServerDebug assembleServerDebugAndroidTest

as a result of the above command execution, two apk files will be generated app-server-debug and app-server-debug-androidTest.

app-server-debug will contains base implementation and app-server-debug-androidTest contains flavor specific implementation.

Starting server: install both apks to the device and execute the instrumentation tests.

adb shell am instrument -w io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner

Building e2eTest flavor:

gradle clean assembleE2ETestDebug assembleE2ETestDebugAndroidTest

e2eTest flavor contains tests for handlers and can be invoked by using either following ways

    1. install both apks to the device/emulator and execute the instrumentation tests.
    adb shell am instrument -w io.appium.uiautomator2.e2etest.test/android.support.test.runner.AndroidJUnitRunner
  • 2.gradle clean connectedE2ETestDebugAndroidTest

    the above command takes care about installing both the built apks and also installs AUT.


Build Directory:

Gradle project will be built based on buildDir property and by default it will build repository in ./app/build, but in Windows operating systems gradle can't build the project if the 'buildDir' path of contains more then 240 characters. refer https://code.google.com/p/android/issues/detail?id=187430

As a temporary workaround configuring 'buildDir' property only for Windows OS.

if (Os.isFamily(Os.FAMILY_WINDOWS)) {

        /**
         * In Windows OS, gradle can't build the project
         * if the project path is containing more than 240 characters.
         * As a temporary fix, changing the 'buildDir' to 'windowsBuildDir' property in package.json file
         * if the 'windowsBuildDir' property not available it will build the apks in the default value
         * of 'buildDir' which is current repo.
         * refer: https://code.google.com/p/android/issues/detail?id=187430
         */
        def packagejson = new JsonSlurper().parseText(new File("./package.json").text)
        if (packagejson.windowsBuildDir) {
            buildDir = packagejson.windowsBuildDir + "/${rootProject.name}/${project.name}/build"
        }
    }