[英]Can't build app on release mode - Keystore was tampered with, or password was incorrect
I'm having a problem that I can only build my app on debug mode. 我有一个问题,我只能在调试模式下构建我的应用程序。 When I try building it on release, either with Android Studio or
./gradlew assembleRelease
I get the Keystore was tampered with, or password was incorrect error message. 当我尝试使用Android Studio或
./gradlew assembleRelease
在发行版上构建它时,我发现Keystore被篡改,或者密码不正确 。
The thing is I can generate a signed, I'm only having problems with building my app on release mode. 关键是我可以生成签名,但在发布模式下构建应用程序时只会遇到问题。
Here's how I configured the release build type in my build.gradle: 这是我在build.gradle中配置发布版本类型的方法:
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(':app:assembleRelase')) {
def password = ""
if (System.console() == null) {
new SwingBuilder().edt {
dialog(modal: true,
title: "Enter password",
alwaysOnTop: true,
resizable: false,
locationRelativeTo: null,
pack: true,
show: true
) {
vbox {
label(text: "Enter password: ")
input = passwordField()
button(defaultButton: true, text: 'OK', actionPerformed: {
password = input.password
dispose()
})
}
}
}
} else {
password = System.console().readPassword("\nEnter password: ")
password = new String(password)
}
if (password.size() <= 0) {
throw new InvalidUserDataException("Empty password")
}
android.signingConfigs.release.storePassword = password
android.signingConfigs.release.keyPassword = password
}
}
The function above was supposed to ask for the key and store passwords either through a dialogue or command line, but it's being ignored. 上面的功能应该通过对话框或命令行来询问密钥并存储密码,但是被忽略了。
android {
...
signingConfigs {
config {
keyAlias 'my_alias'
keyPassword ''
storeFile file('../my_keystore.jks')
storePassword ''
}
}
buildTypes {
...
release {
minifyEnabled false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField("String", "DB_NAME", '"database.db"')
signingConfig signingConfigs.config
}
Please, I need to know if there's anything I've done wrong or if I forgot anything. 拜托,我需要知道我做错了什么还是忘记了什么。
Since Gradle Daemon has been added to Gradle, it's no longer able to use the System.console()
function unless you add the --no-daemon
flag. 由于Gradle Daemon已添加到Gradle中,因此除非添加
--no-daemon
标志,否则它将不再能够使用System.console()
函数。
As for the use of Swing features in a Gradle build process, it's not a good practice and at least for this case it doesn't work at all. 至于在Gradle构建过程中使用Swing功能,这不是一个好习惯,至少在这种情况下,它根本不起作用。
So in conclusion, the best thing to do is to create a properties file containing the alias, passwords and the keystore file path, and obviously include that file in .gitignore and make sure the keystore file is located at a directory other than the project's for safety reasons. 因此,总而言之,最好的办法是创建一个包含别名,密码和密钥库文件路径的属性文件,并将该文件显然包含在.gitignore中,并确保密钥库文件位于项目目录之外的目录中。安全原因。
The way to set the signing configuration properties from the properties file is shown in the following code: 以下代码显示了从属性文件设置签名配置属性的方法:
signingConfigs {
config {
def properties = new Properties()
file("my_properties_file.properties").withInputStream { properties.load(it) }
keyPassword = properties.getProperty("my.key.password")
storePassword = properties.getProperty("my.store.password")
keyAlias = properties.getProperty("my.key.alias")
storeFile = file(properties.getProperty("my.file.path"))
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.