Android Usage

This guide will help you setup BundleCop with your Android project. You will be using our command line tool. It will work irregardless of the build system you are using, whether that be Gradle, Buck, or something else.

Before you begin, make sure the CLI tool is installed, and log into BundleCop to copy your project key and bundle set id.

Submit as part of your CI build

Usually, you would be running BundleCop only during builds on your CI server. If you do this, we recommend you simply call the bundlecop binary after your build script is complete.

For example, if you are building via Gradle, go to the place in your build script where you invoke ./gradlew assembleRelease. Gradle by default writes the output APK to ./app/build/outputs/apk/app-release-unsigned.apk, so you can run the following command to submit the readings to our server:

$ bundlecop submit \
    --projectKey YOUR_PROJECT_KEY \
    --bundleset YOUR_BUNDLE_SET_ID \
    ./app/build/outputs/apk/app-release-unsigned.apk

In some cases, you may need to pass additional options to get the most out of BundleCop. You may also want to look at the complete CLI usage docs.

Submit as part of your Android Studio build

If you are not using Continuous Integration, and are instead building only on your local machine as part of developing the app, you can configure Android Studio, via it’s Gradle build system, to submit a file size reading every time you do an production build.

Find the build.gradle file in your app folder. You will likely have two files with that name in your project. You’ll want to pick the one that is in the child folder, with an android {} section inside.

Add the following code at the bottom:

task submitBundleCop(type:Exec) {
    commandLine 'bundlecop', 'submit',
            '--projectKey', 'YOUR_PROJECT_KEY',
            '--bundleset', 'YOUR_BUNDLESET_ID',
            './build/outputs/apk/app-release*.apk'
}

afterEvaluate { project ->
    project.tasks.assembleRelease.finalizedBy(submitBundleCop)
}

And usually that’s it! In some cases, you may need to pass additional options to get the most out of BundleCop. You may also want to look at the complete CLI usage docs.