无法在额外的属性扩展上获取属性'compileSdkVersion',因为它不存在Open File

vit*_*han 13 android android-studio build.gradle android-gradle-plugin gradle-plugin

我将从GitHub下载的项目作为模块导入到我的Android Studio项目中."导入模块..."向导工作正常,但当Adroid Studio尝试重建项目时,它返回给我这个错误:

Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist Open File
Run Code Online (Sandbox Code Playgroud)

该错误与导入模块的"build.gradle"文件中的此行相关:

compileSdkVersion rootProject.compileSdkVersion
Run Code Online (Sandbox Code Playgroud)

我试图在项目"build.gradle"中添加"ext"部分,如下所示:

ext {
    compileSdkVersion 26
}
Run Code Online (Sandbox Code Playgroud)

但是这样我收到一个新的错误:

Gradle DSL method not found: 'compileSdkVersion()' Possible causes: ... 
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 28

在您的顶级文件中使用:

ext {
    compileSdkVersion = 26
}
Run Code Online (Sandbox Code Playgroud)

在您的module/build.gradle文件中使用:

android {
  compileSdkVersion rootProject.ext.compileSdkVersion
  ...
}
Run Code Online (Sandbox Code Playgroud)

  • 什么是“顶级文件”? (6认同)