Last Updated: December 30, 2020
·
4.279K
· swampmobile

Android Studio: Various Gradle Build Tips

Specify custom keystores

Add the following to your app's build.gradle file. Change the various paths and credentials as needed.

App's build.gradle:

android {
    ...

    signingConfigs {
        debug {
            // path relative to project root
            storeFile file("keystores/debug/debug.keystore") 
        }
        release {
            // path relative to project root
            storeFile file("keystores/release/release.keystore")
            storePassword "[your keystore password]"
            keyAlias "[your key alias]"
            keyPassword "[your key password]"
        }
    }

    ...
}

Setup Java annotation processing

The following instructions were taken from:
http://snowdream.github.io/blog/android/2013/11/07/building-with-androidannotations-and-gradle/

First, open the Java compiler settings within Android Studio and enable annotation processing.

Second, add the following to your app module's build.gradle file at the root level of the file.

App's build.gradle:

configurations {
    apt
    ...
}

android.applicationVariants.all { variant ->
    aptOutput = file("${project.buildDir}/source/apt_generated/${variant.dirName}")
    println "****************************"
    println "variant: ${variant.name}"
    println "manifest:  ${variant.processResources.manifestFile}"
    println "aptOutput:  ${aptOutput}"
    println "****************************"

    variant.javaCompile.doFirst {
        println "*** compile doFirst ${variant.name}"
        aptOutput.mkdirs()
        variant.javaCompile.options.compilerArgs += [
                '-processorpath', configurations.apt.getAsPath(),
                '-AandroidManifestFile=' + variant.processResources.manifestFile,
                '-s', aptOutput
        ]
    }
}