gpt4 book ai didi

android - 如果选择签名 v2,则生成的 APK 未签名

转载 作者:行者123 更新时间:2023-12-04 23:54:23 25 4
gpt4 key购买 nike

我正在尝试为我的应用程序生成一个签名的 APK,如果我只使用签名 V1,它就可以工作。当我使用签名 V2 然后使用 keytool 检查 apk 时,输出是:

keytool -list -printcert -jarfile app-release.apk
Not a signed jar file

这是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 {
try {
Properties props = getProps('./local.properties')
storeFile file(props.getProperty('RELEASE_STORE_FILE', ''))
keyAlias props.getProperty('RELEASE_KEY_ALIAS', '')
keyPassword props.getProperty('RELEASE_STORE_PASSWORD', '')
storePassword props.getProperty('RELEASE_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.")
}
}
}

defaultConfig {
...
// Only productionRelease flavour uses signingConfigs.release;
// other flavours(i.e. productionDebug, developmentDebug, developmentRelease)
// use signingConfigs.debug
// https://stackoverflow.com/questions/30898611/gradle-signing-flavors-with-different-keys-on-android
signingConfig signingConfigs.release
}
buildTypes {
release {
...
}
debug {
...
signingConfig signingConfigs.debug
}
}
// Dimensions: environment can be one of [development, production]
flavorDimensions "environment"
productFlavors {
development {
...
signingConfig signingConfigs.debug
...
}
production {
dimension "environment"
}
}
...
}

我还从头开始创建了一个新的 Android 项目,它也有同样的问题。

请注意,我有另一个 Android 项目可以生成一个同时选择 V1 和 V2 的签名 APK。

为什么添加签名 V2 会导致生成未签名的 APK?

最佳答案

Signature v2是在Android 7.0(24)引入的,所以当你的minSdkVersion为24或更高时,像这样同时启用v1和v2:

signingConfigs {
debug {
v1SigningEnabled true
v2SigningEnabled true
}
}

签名的 apk 不会有 v1,它只是用 v2 签名。这可以通过 apksigner 像这样验证:

java -jar apksigner.jar verify -v your-signed-apkfile.apk

enter image description here

否则keytool无法识别signature v2,所以提示Not a signed jar file。而只有签名v2的签名apk也是一个可用apk,它只能安装在Android 7.0或更高版本上。

如果你想同时用v1和v2签名,你应该修改minSdkVersion为23或更低。

希望对您有所帮助。

关于android - 如果选择签名 v2,则生成的 APK 未签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58878407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com