Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Android Development

Gradle

Enable Gradle Daemon

Speed up Gradle build times by enabling the Gradle Daemon

echo org.gradle.daemon=true >> ~/.gradle/gradle.properties

https://www.timroes.de/2013/09/12/speed-up-gradle/

versionName and versionCode

Tie together the versionName and versionCode

https://plus.google.com/108284392618554783657/posts/6f5TcVPRZij

def versionMajor = 3
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.

android {
    defaultConfig {
        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"
    }
}

BuildConfig

Add fields to BuildConfig from Gradle

https://plus.google.com/108284392618554783657/posts/6f5TcVPRZij

def gitSha() {
    return 'git rev-parse --short HEAD'.execute().text.trim()
}

def buildTime() {
    def df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
    df.setTimeZone(TimeZone.getTimeZone("UTC"))
    return df.format(new Date())
}

android {
    defaultConfig {
        buildConfig """\
            public static final String GIT_SHA = "${gitSha()}";
            public static final String BUILD_TIME = "${buildTime()}";
        """
    }
}

Handling Signing Configs with Gradle

https://www.timroes.de/2013/09/22/handling-signing-configs-with-gradle/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment