title: GradleException: Android tasks have already been created for multi module shared versions
body: <p>Trying to follow <a href="https://jeroenmols.com/blog/2019/06/12/modularizationtips/" rel="nofollow noreferrer">Jeroen Mols modularization sample</a>, he specifies a nice technique to allow all modules to share version numbers. In the top level project build.gradle, add this:</p>
  
  <pre><code>subprojects {
      afterEvaluate { project -&gt;
          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
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Now any module level build.gradle files do not need to specify these fields. However I get: </p>
  
  <p><code>GradleException: Android tasks have already been created.</code></p>
  
  <p>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.</p>