0

Trying to follow Jeroen Mols modularization sample, he specifies a nice technique to allow all modules to share version numbers. In the top level project build.gradle, add this:

subprojects {
    afterEvaluate { project ->
        if (project.hasProperty('android')) {

            android {
                compileSdkVersion build_versions.target_sdk

                defaultConfig {
                    minSdkVersion build_versions.min_sdk
                    targetSdkVersion build_versions.target_sdk
                    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

                    vectorDrawables.useSupportLibrary = true
                }

                compileOptions {
                    sourceCompatibility JavaVersion.VERSION_1_8
                    targetCompatibility JavaVersion.VERSION_1_8
                }
            }
        }
    }
}

Now any module level build.gradle files do not need to specify these fields. However I get:

GradleException: Android tasks have already been created.

I am not specifying android.applicationVariants, android.libraryVariants or android.testVariants like the description to this error mentions so what could I be doing wrong here? I have even tried removing the android block from every module completely and the error persists.

Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135

1 Answers1

0

Ok the issue was that I created a libraries module inside a core module instead of the same folder level. My guess is this afterEvaluate android block doesn't work for modules inside modules. So my solution was just to make sure that modules are specified at the same level.

Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135