我想有我的Gradle构建创建一个发布签名apk文件使用Gradle。
我不确定代码是否正确,或者我在做gradle构建时是否缺少一个参数?
这是build.gradle/build.gradle中的一些代码。节文件:
android {
...
signingConfigs {
release {
storeFile(file("release.keystore"))
storePassword("******")
keyAlias("******")
keyPassword("******")
}
}
}
Gradle构建成功完成,在我的build/apk文件夹中,我只看到…-release-unsigned.apk和…-debug-unaligned.apk文件。
对如何解决这个问题有什么建议吗?
现在几乎所有的平台都提供了某种密匙环,所以没有理由留下明文密码。
我提出了一个简单的解决方案,使用Python密匙环模块(主要是配套的控制台脚本密匙环)和Groovy ['do', 'something'].execute()特性的最小包装:
def execOutput= { args ->
def proc = args.execute()
proc.waitFor()
def stdout = proc.in.text
return stdout.trim()
}
使用这个函数,signingConfigs部分变成:
signingConfigs {
release {
storeFile file("android.keystore")
storePassword execOutput(["keyring", "get", "google-play", storeFile.name])
keyAlias "com.example.app"
keyPassword execOutput(["keyring", "get", "google-play", keyAlias])
}
}
在运行gradle assemblerrelease之前,你必须在你的keyring中设置密码,只有一次:
$ keyring set google-play android.keystore # will be prompted for the passwords
$ keyring set google-play com.example.app
释放快乐!
我有几个问题,我把下面的行放在错误的地方:
signingConfigs {
release {
// We can leave these in environment variables
storeFile file("d:\\Fejlesztés\\******.keystore")
keyAlias "mykey"
// These two lines make gradle believe that the signingConfigs
// section is complete. Without them, tasks like installRelease
// will not be available!
storePassword "*****"
keyPassword "******"
}
}
确保你把signingConfigs部分放在了android部分:
android
{
....
signingConfigs {
release {
...
}
}
}
而不是
android
{
....
}
signingConfigs {
release {
...
}
}
很容易犯这个错误。