Yakir Yehuda
Yakir Yehuda

Reputation: 720

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!

Upvotes: 2

Views: 2103

Answers (2)

Avi
Avi

Reputation: 866

In the beginning of build.gradle of project2 add the following line:

evaluationDependsOn(':project1')

Then the evaluation you wrote will work.

Upvotes: 0

Gabriele Mariotti
Gabriele Mariotti

Reputation: 364201

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
    }

    //...
}

Upvotes: 10

Related Questions