我想把我的项目迁移到gradle.我的一个项目有多种产品风格,每种产品都必须在其发布版本中使用不同的signingConfig进行签名.所以这就是我到目前为止所尝试的:
buildscript {
...
}
apply plugin: 'android'
android {
compileSdkVersion 17
buildToolsVersion '17'
signingConfigs {
flavor1 {
storeFile file("keystore")
storePassword "secret"
keyAlias "aliasForFlavor1"
keyPassword "secretFlavor1"
}
flavor2 {
storeFile file("keystore")
storePassword "secret"
keyAlias "aliasForFlavor2"
keyPassword "secretFlavor2"
}
}
productFlavors {
flavor1 {
signingConfig signingConfigs.flavor1
}
flavor1 {
signingConfig signingConfigs.flavor2
}
}
}
dependencies {
...
}
Run Code Online (Sandbox Code Playgroud)
当我运行时,signingConfig我得到一个gradle build和以下错误消息:
No such field: signingConfigs for class: com.android.build.gradle.internal.dsl.GroupableProductFlavorFactory
Run Code Online (Sandbox Code Playgroud)
所以我假设productFlavors.*gradle脚本的一部分不是放置代码签名配置的正确位置.
我有一个项目,我有几个特定于设备的产品口味,每个口味需要用不同的配置签名:
productFlavors {
nexus7 {
signingConfig signingConfigs.nexus7
}
nexus4 {
signingConfig signingConfigs.nexus4
}
}
Run Code Online (Sandbox Code Playgroud)
这在构建"发布"变体时非常有用.但是,当使用'debug'变体时(例如,当我构建Nexus4Debug时),Gradle使用默认的android调试密钥.在我的情况下,我高度依赖这些构建以正确的方式签名,如果使用默认调试密钥签名,我的应用程序相对无用.任何人都知道是否有办法为每个变体指定签名配置?
我知道我可以按照构建类型来做,la:
buildTypes {
debug {
signingConfig signingConfigs.nexus4
}
}
Run Code Online (Sandbox Code Playgroud)
但这限制了我总是使用相同的签名配置来调试两种风格的版本.
PS - 了解这是一个有点边缘用例的地方.这是一个企业项目,我们在许多不同的Nexus设备上测试自定义ROM和系统签名的应用程序.
我需要构建一个使用我们的应用程序签名密钥签名的 APK 进行内部测试,并构建一个使用我们的上传密钥签名的应用程序包,以便在提交到 Google Play 时使用。如何build.gradle根据我构建的是 APK 还是应用程序包来配置使用不同的密钥?
我正在尝试为我的应用程序生成一个签名的 APK,如果我只使用签名 V1,它就可以工作。当我使用签名V2然后用keytool检查apk时,输出是:
keytool -list -printcert -jarfile app-release.apk
Not a signed jar file
Run Code Online (Sandbox Code Playgroud)
这是 build.gradle:
def getProps(path) {
Properties props = new Properties()
props.load(project.rootProject.file(path).newDataInputStream())
return props
}
android {
...
signingConfigs {
debug {
try {
Properties props = getProps('./local.properties')
storeFile file(props.getProperty('DEBUG_STORE_FILE', ''))
keyAlias props.getProperty('DEBUG_KEY_ALIAS', '')
keyPassword props.getProperty('DEBUG_STORE_PASSWORD', '')
storePassword props.getProperty('DEBUG_STORE_PASSWORD', '')
v1SigningEnabled true
v2SigningEnabled false // enabling this generates unsigned apk
}
catch (ex) {
throw new InvalidUserDataException("You should define RELEASE_STORE_FILE, RELEASE_KEY_ALIAS, RELEASE_STORE_PASSWORD in local.properties.")
}
}
release { …Run Code Online (Sandbox Code Playgroud) 我正在使用带有 gradle 2.2 的 Android Studio RC。我在我的构建变体部分有几个变体,我可以选择我想要构建的一个。例如,为匈牙利或德国建造。
我在 gradle 脚本中启动了一些任务,例如根据风格/变体更改名称。但此刻的脚本遍历所有构建变种,像这样:
android.applicationVariants.each { variant ->。
所以我的问题是:我怎样才能从 android studioBuild Variants部分只获取选定的变体并在 gradle 脚本中使用它,以便删除循环?
我需要使用特定的签名配置来签署产品风格。我在 stackoverflow 上找到了一些参考资料,例如this和this。它适用于我的风味发布版本,但不适用于调试版本。我在 gradle 中有这样的配置:
...
signingConfigs {
release {
storeFile file("../config/keystores/release_keystore")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
debug {
storeFile file("../config/keystores/debug.keystore")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
other {
storeFile file("../config/keystores/other")
storePassword "mysecurepassword"
keyAlias "myultrasecurealias"
keyPassword "myreallysecurekeypassword"
}
}
flavorDimensions "dim"
productFlavors {
production {
dimension "dim"
}
other {
dimension "dim"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
productFlavors.other.signingConfig signingConfigs.other
productFlavors.production.signingConfig signingConfigs.release
}
debug {
productFlavors.other.signingConfig signingConfigs.other
productFlavors.production.signingConfig …Run Code Online (Sandbox Code Playgroud) android code-signing gradle build.gradle android-gradle-plugin