生成脚本错误,找到不支持的Gradle DSL方法:';signingConfig()';

生成脚本错误,找到不支持的Gradle DSL方法:';signingConfig()';,gradle,android-studio,Gradle,Android Studio,我正在尝试设置gradle,以便在Android Studio 0.4.5中创建一个Google Play store版本。在渐变设置中,我使用默认的渐变包装器。我使用“项目属性”对话框设置签名配置和“发布”生成类型。我只有一个构建模块。以下是生成的build.gradle文件: apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion '19.0.1' defaultCon

我正在尝试设置gradle,以便在Android Studio 0.4.5中创建一个Google Play store版本。在渐变设置中,我使用默认的渐变包装器。我使用“项目属性”对话框设置签名配置和“发布”生成类型。我只有一个构建模块。以下是生成的build.gradle文件:

    apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 10
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable false
            signingConfig playstore
            proguardFile 'proguard-rules.txt'
        }
    }
    signingConfigs {
            playstore {
            keyAlias 'mykeyalias'
            storeFile file('playstore.jks')
            keyPassword 'xxxxx'
            storePassword 'xxxxx'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    compile 'com.android.support:support-v4:+'
    compile files('libs/libGoogleAnalyticsServices.jar')
}
但当gradle尝试同步时,我遇到以下错误:

Build script error, unsupported Gradle DSL method found: 'signingConfig()'!
            Possible causes could be:  
            - you are using Gradle version where the method is absent 
            - you didn't apply Gradle plugin which provides the method
            - or there is a mistake in a build script
我需要做些什么来设置正确的梯度吗


Thanx。在
构建类型
块之前,首先定义
签名配置
。另外,
playstore
方法在
signingConfigs
中,因此您必须以类似于
signingConfigs.playstore
的方式提供引用

您的最终
build.gradle
文件应如下所示:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.1'
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 10
        versionName "1.0"
    }

   signingConfigs {
            playstore {
              keyAlias 'mykeyalias'
              storeFile file('playstore.jks')
              keyPassword 'xxxxx'
              storePassword 'xxxxx'
        }
    }


    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable false
            signingConfig signingConfigs.playstore
            proguardFile 'proguard-rules.txt'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
    compile 'com.android.support:support-v4:+'
    compile files('libs/libGoogleAnalyticsServices.jar')
}

也许你使用的Android插件版本太旧了?你能展示一下引入Android插件的
buildscript
块吗?谢谢。这很有魅力。我发现我使用Android Studio项目属性对话框设置signingConfigs,并将signingConfigs放在build.gradle文件中的buildType之后,这让我很沮丧。我可能应该把它作为bug提交给谷歌,是吗?请务必提交一个bug,以便团队了解这一点,并能够在下一版本中解决它。