代码之家  ›  专栏  ›  技术社区  ›  vittochan

无法获取额外属性扩展名上的属性“compileSdkVersion”,因为它不存在打开的文件

  •  24
  • vittochan  · 技术社区  · 7 年前

    我将一个从GitHub下载的项目作为模块导入到我的Android Studio项目中。 “导入模块…”向导工作正常,但当Adroid Studio尝试重建项目时,它返回了以下错误:

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

    该错误与导入模块的“build.gradle”文件中的此行有关:

    compileSdkVersion rootProject.compileSdkVersion
    

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

    ext {
        compileSdkVersion 26
    }
    

    但通过这种方式,我收到了一个新的错误:

    Gradle DSL method not found: 'compileSdkVersion()' Possible causes: ... 
    
    4 回复  |  直到 7 年前
        1
  •  43
  •   Gabriele Mariotti    7 年前

    在你的 顶层 文件使用:

    ext {
        compileSdkVersion = 26
    }
    

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

    android {
      compileSdkVersion rootProject.ext.compileSdkVersion
      ...
    }
    
        2
  •  1
  •   massivemadness    5 年前

    另一种方式:

    你的 build.gradle 在里面 顶层 单元

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

    你的 建筑格拉德尔 在里面 应用程序 单元

    android {
        def buildConfig = rootProject.extensions.getByName("ext")
    
        compileSdkVersion buildConfig.compileSdk
        buildToolsVersion buildConfig.buildTools
        defaultConfig {
            minSdkVersion buildConfig.minSdk
            targetSdkVersion buildConfig.targetSdk
        }
        // ...
    }
    
        3
  •  -1
  •   Stoica Mircea    7 年前

    内置。gradle您需要在下面编写CompileSDK版本 android 标签如本例所示:

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

    顺便说一句您可以将该模块构建为库,然后将其作为 .aar 文件

        4
  •  -1
  •   Tara    7 年前

    更改您的。格拉德尔 android 这一部分

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