Android Gradle – All About

How do we force all sub-Android projects to be compiled with an SDK version?

build.gradle

buildscript {
    ...
    ext {
        minSdkVersion = 24
        targetSdkVersion = 33
        compileSdkVersion = 33
    }

    subprojects { subproject ->
        afterEvaluate{
            if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
                android {
                    compileSdkVersion rootProject.ext.compileSdkVersion
                }
            }
        }
    }
    ...
}

app/build.gradle

android {
    ...
    defaultConfig {
        ...
        minSdk rootProject.ext.minSdkVersion
        targetSdk rootProject.ext.targetSdkVersion
        ...
    }
    ...
}

Be the first to comment

Leave a Reply

Your email address will not be published.


*