[英]Adding release keys in the experimental Gradle plugin for Android
Hey I am having some issues adding a signing my release build variant. 嘿,我在添加签名我的发布版本变体时遇到了一些问题。 Currently I am using the experimental gradle 2.5 with the new android gradle plugin version 0.1.0.
目前我正在使用实验gradle 2.5和新的android gradle插件版本0.1.0。
build.gradle: 的build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 15
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.testcom.test"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 14
versionCode = 1
versionName = "1.0"
}
compileOptions.with {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
}
android.ndk {
...
}
android.signingConfigs {
signed {
keyAlias = "meow"
keyPassword = "**"
storeFile = file("meow-key.keystore")
storePassword = "**"
}
}
android.buildTypes {
release {
isMinifyEnabled = false
proguardFiles += file('proguard-rules.pro')
signingConfig = signingConfigs.signed
}
debug {
isDebuggable = true
isJniDebuggable = true
}
}
// You can modify the NDK configuration for each variant.
components.android {
binaries.afterEach { binary ->
binary.mergedNdkConfig.cppFlags.add(
"-DVARIANT=\"" + binary.name + "\"")
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
My root build.gradle: 我的root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle-experimental:0.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
The error that I am getting when running ./gradlew assembleRelease
is: 我在运行
./gradlew assembleRelease
时遇到的错误是:
> Exception thrown while executing model rule: model.android.buildTypes > named(release)
> Attempt to read a write only view of model of type 'java.lang.Object' given to rule 'model.android.buildTypes'
Has anyone had a similar issue with the experimental gradle plugin? 有没有人与实验gradle插件有类似的问题? Help would be greatly appreciated.
非常感谢帮助。 :)
:)
This workaround works for me and does not require -Dorg.gradle.model.dsl=true 此解决方法适用于我,不需要-Dorg.gradle.model.dsl = true
model {
def signConf
android.buildTypes {
release {
signingConfig = signConf
}
}
android.signingConfigs {
create("signed") {
keyAlias = "meow"
keyPassword = "**"
storeFile = file("meow-key.keystore")
storePassword = "**"
storeType = "jks"
signConf = it
}
}
}
However, it only works if you only have one signingConfig. 但是,它仅在您只有一个signingConfig时才有效。
You should be able to add the release keys with a script like this: 您应该能够使用如下脚本添加发布密钥:
model {
android.buildTypes {
release {
signingConfig = $("android.signingConfigs.signed")
}
}
android.signingConfigs {
create("signed") {
keyAlias = "meow"
keyPassword = "**"
storeFile = file("meow-key.keystore")
storePassword = "**"
storeType = "jks"
}
}
}
Currently it seems to be a bug in the plugin. 目前它似乎是插件中的一个错误。
You need to specify -Dorg.gradle.model.dsl=true
when you run your gradle command. 运行gradle命令时,需要指定
-Dorg.gradle.model.dsl=true
。
Also you should have an issue with proguard. 你也应该对proguard有疑问。 In this case you can use
new File("path/to/proguard-rules.pro")
instead of file('proguard-rules.pro')
在这种情况下,您可以使用
new File("path/to/proguard-rules.pro")
而不是file('proguard-rules.pro')
The right way to do this with the latest version of the Android plugin ( 0.6.0-alpha3 ) is as follows: 使用最新版本的Android插件( 0.6.0-alpha3 )执行此操作的正确方法如下:
android.signingConfigs {
create("release") {
storeFile = file("../keys.keystore")
storePassword = "st0r3pa$$"
keyAlias = "SecretKey"
keyPassword = "k3ypa$$"
}
}
android.buildTypes {
release {
signingConfig = $.android.signingConfigs.get("release")
}
}
In Gradle 2.9 which is used by this version of the plugin, the declared rules can depend on each other using a special syntax: $.<path-to-element>
. 在此版本插件使用的Gradle 2.9中,声明的规则可以使用特殊语法相互依赖:
$.<path-to-element>
。 The trick is to create the signing config as usual, then assign it to a field in a different rule using this syntax. 诀窍是像往常一样创建签名配置,然后使用此语法将其分配给不同规则中的字段。 Gradle will realize that the signing configuration is an input dependency and will let you access it.
Gradle将意识到签名配置是一个输入依赖项,并允许您访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.