Mobile Development 17 min read

Android Mobile App Build Process: Ant and Gradle Compilation Methods

This article provides a comprehensive guide to Android app compilation, detailing the step‑by‑step build process, the use of Ant and Gradle tools, configuration of build.xml and build.gradle files, and essential settings such as obfuscation, signing, multidex, and code coverage to streamline CI pipelines.

Baidu Intelligent Testing
Baidu Intelligent Testing
Baidu Intelligent Testing
Android Mobile App Build Process: Ant and Gradle Compilation Methods

The article introduces mobile client compilation as the starting point of CI, explaining that automated builds via Jenkins and version control can save manpower and manage test versions.

Android compilation process is outlined, describing resource packaging with aapt , AIDL processing, Java compilation, dex conversion, APK packaging with apkbuilder , signing using jarsigner , and alignment with zipalign . A flow diagram is referenced.

Ant compilation is explained next. Ant, a cross‑platform Java tool, uses a build.xml file. A simple example is shown:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="XXX" default="release">
  <!-- Define paths and tools -->
  <property file="default.properties" />
  <property name="sdk.dir" value="${ANDROID_SDK_HOME}" />
  ...
  <target name="clean"> ... </target>
  <target name="dir" depends="clean">
    <mkdir dir="${in.resource.absolute.dir}" />
    ...
  </target>
</project>

The article then explains key Ant tags such as <project> , <target> , <mkdir> , <jar> , <javac> , and <exec> , describing their attributes and typical usage.

Gradle compilation is presented as the Google‑recommended method. Gradle uses Groovy‑based DSL in build.gradle files. A minimal module build.gradle example is provided:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 19
    buildToolsVersion "19.0.0"
    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    signingConfigs {
        release {
            storeFile file('debug.keystore')
            storePassword 'Android'
            keyAlias 'androiddebugkey'
            keyPassword 'Android'
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
        demo {
            applicationId "com.buildsystemexample.app.demo"
            versionName "1.0-demo"
        }
        full {
            applicationId "com.buildsystemexample.app.full"
            versionName "1.0-full"
        }
    }
    dependencies {
        compile project(":lib")
        compile 'com.android.support:appcompat-v7:19.0.1'
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
}

Important Gradle configurations are covered:

Obfuscation: enable minifyEnabled true and specify proguardFiles (default or custom).

Source sets: customize locations for manifest.srcFile , java.srcDirs , resources.srcDirs , etc.

Signing: define signingConfigs and reference them in buildTypes .

Multidex: set multiDexEnabled true and optionally adjust dex parameters.

Coverage: enable testCoverageEnabled true and add Jacoco dependencies, then configure a jacocoTestReport task.

A custom TimingsListener class example demonstrates how to collect task execution times:

class TimingsListener implements TaskExecutionListener, BuildListener {
    private Clock clock
    private timings = []
    @Override
    void beforeExecute(Task task) { clock = new org.gradle.util.Clock() }
    @Override
    void afterExecute(Task task, TaskState state) {
        def ms = clock.timeInMs
        timings.add([ms, task.path])
        task.project.logger.warn "${task.path} took ${ms}ms"
    }
    @Override
    void buildFinished(BuildResult result) {
        println "Task timings:"
        for (timing in timings) {
            if (timing[0] >= 50) {
                printf "%7sms  %s\n", timing
            }
        }
    }
}
gradle.addListener new TimingsListener()

Finally, common Gradle command‑line usage is listed (e.g., gradle clean , gradle build , gradle assembleDebug , gradle tasks --all ) and tips for invoking specific tasks to speed up builds.

Mobile Developmentbuild automationAndroidGradleCIAnt
Baidu Intelligent Testing
Written by

Baidu Intelligent Testing

Welcome to follow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.