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

时间:2014-02-23 23:45:19

标签: gradle android-studio

我正在尝试设置gradle以在Android Studio 0.4.5中创建Google Play商店版本。在gradle设置中,我使用的是默认的gradle包装器。我使用Project Properties对话框来设置签名配置和'release'构建类型。我只有一个构建模块。以下是生成的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

我需要做些什么来设置正确的gradle?

提前完成。

1 个答案:

答案 0 :(得分:12)

首先在SigningConfigs阻止之前定义buildTypes。另外,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')
}