vittochan
vittochan

Reputation: 685

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: ... 

Upvotes: 29

Views: 50498

Answers (4)

massivemadness
massivemadness

Reputation: 120

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
    }
    // ...
}

Upvotes: 3

Gabriele Mariotti
Gabriele Mariotti

Reputation: 363737

In your top-level file use:

ext {
    compileSdkVersion = 26
}

In your module/build.gradle file use:

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  ...
}

Upvotes: 48

Tara
Tara

Reputation: 700

Change your .gradle android part to this

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "your App id"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Upvotes: -2

Stoica Mircea
Stoica Mircea

Reputation: 782

In build.gradle you need to write compilesdkversion under android tag as in this example:

android { .. compileSdkVersion 26 // 26 is an example ..}

By the way. You can build that module as library then import it into your project as .aar file.

Upvotes: -1

Related Questions