错误:无法为org.gradle.api.Project类型的根项目<myproject>获取未知属性'compileSdkVersion'

时间:2017-01-31 08:36:38

标签: android android-studio android-gradle build.gradle

我正在尝试按照Android — How to add Gradle dependencies using ‘foreach’

的行构建我的依赖项文件,从build.gradle到dependencies.gradle

在执行此操作时,我已对位于 app 目录中的dependencies.gradle文件进行了必要的更改。 这是我的dependencies.gradle:

    ext {
    compileSdkVersion = 25
    buildToolsVersion = "25"
    minSdkVersion = 16
    targetSdkVersion = 25
    versionCode = 121

    // Versions
    def supportLibVersion = '25.0.1'
    def gmsVersion = '10.0.1'
    def multidexVersion = '1.0.1'

    // Libraries
    def androidLibs = [
            annotations : [group: 'com.android.support', name: 'annotations', version: supportLibVersion],
            cardview    : [group: 'com.android.support', name: 'cardview-v7', version: supportLibVersion],
            design      : [group: 'com.android.support', name: 'design', version: supportLibVersion],
            recyclerView: [group: 'com.android.support', name: 'recyclerview-v7', version: supportLibVersion],
            multidex    : [group: 'com.android.support', name: 'multidex', version: multidexVersion],
            customTabs  : [group: 'com.android.support', name: 'customtabs', version: supportLibVersion],
            percent     : [group: 'com.android.support', name: 'percent', version: supportLibVersion],
            preference  : [group: 'com.android.support', name: 'preference-v7', version: supportLibVersion]
    ]

    def googleLibs = [
            ads             : [group: 'com.google.android.gms', name: 'play-services-ads', version: gmsVersion],
            analytics       : [group: 'com.google.android.gms', name: 'play-services-analytics', version: gmsVersion],
            gcm             : [group: 'com.google.android.gms', name: 'play-services-gcm', version: gmsVersion],
            location        : [group: 'com.google.android.gms', name: 'play-services-location', version: gmsVersion],
            maps            : [group: 'com.google.android.gms', name: 'play-services-maps', version: gmsVersion],
            firbaseAuth     : [group: 'com.google.firebase', name: 'firebase-auth', version: gmsVersion],
            firebaseDatabase: [group: 'com.google.firebase', name: 'firebase-database', version: gmsVersion]
    ]
}

这是我的build.gradle:

apply plugin: 'com.android.application'
apply from: 'dependencies.gradle'
...
android {
    ...
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion
}

在运行构建或同步gradle时,它会抛出错误:

  

错误:无法获取root的未知属性'compileSdkVersion'   org.gradle.api.Project类型的项目。

现在我陷入了困境。请帮我前进。任何帮助将受到高度赞赏。

0 个答案:

没有答案