Skip to content

Instantly share code, notes, and snippets.

@neworld
Last active September 15, 2020 11:32
Show Gist options
  • Star 83 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save neworld/6af9154591b24404c01d to your computer and use it in GitHub Desktop.
Save neworld/6af9154591b24404c01d to your computer and use it in GitHub Desktop.
How to make faster Android build without sacrificing new api lint check

Original solution sacrifices new api lint check.

Here my solution:

int minSdk = hasProperty('minSdk') ? minSdk.toInteger() : 16

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "lt.neworld.minsdktest"
        minSdkVersion minSdk
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
}

And just need to pass minSdk with preferred API version. I am using most recent that my device support.

CLI:

./gradlew installDebug -PminSdk=23

IDE:

image

This solution saves me at least 40 seconds for every build, and new API lint check still works:

image

Edit:

You can set default minSdk in global gradle.properties:

echo 'minSdk=22' >> ~/.gradle/gradle.properties
@tasomaniac
Copy link

For me hasProperty is not working alone, I had to use project.hasProperty

@patrykpoborca
Copy link

Thanks for the nice idea! 👍

@jonathan-caryl
Copy link

Like @tasomaniac said, it didn't work for me unless I used project.hasProperty

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