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


我正在尝试设置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?

提前完成。


8216
2018-02-23 23:45


起源

也许你使用的Android插件版本太旧了?你能表现出来吗? buildscript 带来Android插件的块? - Peter Niederwieser


答案:


首先定义你的 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')
}

12
2018-02-24 04:27



谢谢。这就像一个魅力。我发现使用Android Studio项目属性对话框来设置signingConfigs并放置了签名会令我感到沮丧 后 build.gradle文件中的buildTypes。我应该把它作为一个bug提交谷歌。 - NLam
是吗 ?肯定是一个bug,所以团队将会了解这一点,并能够在下一个版本中解决它。 - pyus13