我正在获取Gradle DSL方法未找到错误?

时间:2018-10-11 09:14:12

标签: android android-studio gradle

我正在开发新闻应用程序,并且遇到以下错误。

Gradle DSL method not found: 'compileSdkVersion()'
Possible causes: The project 'app' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 3.2.0 and sync project The project 'app' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file The build file may be missing a Gradle plugin.
Apply Gradle plugin. 

我已经遵循了堆栈溢出的所有可能解决方案,但是并不能解决我的问题。

在我的build.gradle下:

apply plugin: 'com.android.application'

android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
        signingConfigs {
            config {
                keyAlias 'key0'
                keyPassword 'Adilnoz1992'
                storeFile file('yodgor.jks')
                storePassword 'Aziyoda1990'
            }
        }
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.edgar.komilov.news"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        flavorDimensions "default"
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }


dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.picasso:picasso:2.3.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.android.gms:play-services-ads:17.0.0'
    implementation 'com.google.firebase:firebase-core:11.8.0'
}
apply plugin: 'com.google.gms.google-services'

在我的根build.gradle下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {

        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:3.2.0'



        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

2 个答案:

答案 0 :(得分:0)

将您的依赖项更改为:

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0' // should have the same version as appcompat
implementation 'com.google.firebase:firebase-core:16.0.4'

您根build.gradle中的google服务可以:

classpath 'com.google.gms:google-services:4.1.0'

还要在compileSdkVersion 28块内添加android

android {
    compileSdkVersion 28
    defaultConfig {
    ...
    ..

然后尝试。

答案 1 :(得分:0)

删除}上方的多余花括号compileSdkVersion 28并将其添加到dependencies块上方,如下所示

apply plugin: 'com.android.application'

android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
    signingConfigs {
            config {
            keyAlias 'key0'
            keyPassword 'Adilnoz1992'
            storeFile file('yodgor.jks')
            storePassword 'Aziyoda1990'
        }
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.edgar.komilov.news"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        flavorDimensions "default"
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        signingConfig signingConfigs.config
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.picasso:picasso:2.3.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.google.android.gms:play-services-ads:17.0.0'
    implementation 'com.google.firebase:firebase-core:11.8.0'
}
apply plugin: 'com.google.gms.google-services'