Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist Open File

I imported a project downloaded from GitHub into my Android Studio project as module. The "Import module..." wizard worked fine, but when the Adroid Studio tried to rebuild the project, it returned me this error:

Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist Open File

The error is related to this line in the "build.gradle" file of the imported module:

compileSdkVersion rootProject.compileSdkVersion

I tried to add "ext" section in the project "build.gradle" like this:

ext {
    compileSdkVersion 26
}

But in this way I receive a new error:

Gradle DSL method not found: 'compileSdkVersion()' Possible causes: ... 
like image 817
vittochan Avatar asked Dec 05 '17 12:12

vittochan


2 Answers

In your top-level file use:

ext {
    compileSdkVersion = 26
}

In your module/build.gradle file use:

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  ...
}
like image 68
Gabriele Mariotti Avatar answered Nov 11 '22 02:11

Gabriele Mariotti


Another way:

Your build.gradle in top-level module

ext {
    minSdk = 21
    targetSdk = 29
    compileSdk = 29
    buildTools = '29.0.3'
}

Your build.gradle in app module

android {
    def buildConfig = rootProject.extensions.getByName("ext")

    compileSdkVersion buildConfig.compileSdk
    buildToolsVersion buildConfig.buildTools
    defaultConfig {
        minSdkVersion buildConfig.minSdk
        targetSdkVersion buildConfig.targetSdk
    }
    // ...
}
like image 20
massivemadness Avatar answered Nov 11 '22 02:11

massivemadness