Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: use one version number for all modules

I'm building a complex project with multiple modules that gets build together to create a distributed sdk. My purpose is to have one variable for version major, minor and revision who I later inject into the buildConfig. Cant find how to do it.

This is what I tried so far:

project1: 
// PROJECT VERSIONS
project.ext {
    major = 1
    minor = 7
    revision = 2
}



project2:
defaultConfig {
        minSdkVersion 8
        targetSdkVersion 23
        versionCode project(':project1').ext.major 
        versionName "1.0"
    }

Thank you!

like image 408
Yakir Yehuda Avatar asked Jul 26 '26 18:07

Yakir Yehuda


1 Answers

You can configure these values in the build.gradle file in the root of the project.

Example:

ext {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.1"
    minSdkVersion = 15
    targetSdkVersion = 23
}

Then in the module/build.gradle you can use:

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        minSdkVersion  rootProject.ext.minSdkVersion
        targetSdkVersion  rootProject.ext.targetSdkVersion
    }

    //...
}
like image 150
Gabriele Mariotti Avatar answered Jul 28 '26 11:07

Gabriele Mariotti