我正在尝试设置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?
提前完成。
答案 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')
}