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

时光怂恿深爱的人放手 提交于 2019-12-04 16:59:52

问题


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

回答1:


In your top-level file use:

ext {
    compileSdkVersion = 26
}

In your module/build.gradle file use:

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



回答2:


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.




回答3:


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'
        }
    }
}


来源:https://stackoverflow.com/questions/47653560/cannot-get-property-compilesdkversion-on-extra-properties-extension-as-it-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!