我可以使用与附带证书不同的证书重新签署 .apk 吗?
如果我有 apk,我可以删除当前签名以及如何使用不同的 .keystore 文件重新签名并仍然安装应用程序吗?
更新:我设法让它与 Jorgesys 的解决方案一起使用,之前我搞砸的地方是我解压了 .apk,然后在删除 META-INF 文件夹后重新压缩它,并将文件扩展名改回为.apk。我应该做的只是用 winzip 打开它并删除 winzip 中的文件夹。
If I have an apk can I remove the current signing and some how re-sign it with a different .keystore file and still have the application install?
Update: I managed to get it to work with Jorgesys' solution and where I messed up before was that I unzipped the .apk then rezipped it after removing the META-INF folder and changed the file extension back into .apk. What I should have done is simply opened it with winzip and delete the folder inside of winzip.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
试试这个
希望有帮助
try this
hope it helps
如果您正在寻找快速简单的解决方案,可以使用 Google 的
apksigner
命令行 工具,该工具在版本 24.0.3 及更高版本中可用。您可以在 Android 开发者网站上找到有关 apksigner 工具的更多信息。
https://developer.android.com/studio/command-line/apksigner.html
或者,您也可以使用开源 apk-resigner 脚本
开源 apk-resigner 脚本 https://github.com/onbiron/apk-resigner
您所要做的就是下载脚本并输入:
If you are looking for a quick simple solution, you can use Google's
apksigner
command line tool which is available in revision 24.0.3 and higher.You can find more information about apksigner tool, at the developer Android site.
https://developer.android.com/studio/command-line/apksigner.html
Or, alternatively, you may use an open-source apk-resigner script
Open Source apk-resigner script https://github.com/onbiron/apk-resigner
All you have to do is, download the script and just type:
请注意,如果您使用 v2 签名架构(如果您使用 build- AS 中的工具 24.0.3+)您不能只从 APK 中删除 META-INF 文件夹,因为 v2 将其签名数据添加到 zip 元块中。
然而,Google 在 build-tools 24.03 (Android 7) 中引入的新 apksigner 是能够放弃 APK。您只需重复签名命令即可使用新的密钥库/证书进行签名(旧的密钥库/证书将被删除)。
无耻插件:如果你想要一个更简单的工具,可以签署多个apk并具有更好的日志输出,请使用: https://github.com/patrickfav/uber-apk-signer(在后台使用 Google 的 apksigner.jar)
Note if you use v2 signing schema (which you will automatically if you use build-tools 24.0.3+ in AS) you cannot just remove the META-INF folder from the APK since v2 adds its signing data to a zip meta block.
Google's new apksigner introduced in build-tools 24.03 (Android 7) is however able to resign APKs. You can just repeat the signing command to sign with a new keystore/cert (the old ones will be removed).
Shameless plug: if you want a easier tool that can sign multiple apks and has better log output use: https://github.com/patrickfav/uber-apk-signer (uses Google's apksigner.jar in the background)
签名发布:$1.apk -> $1_release.apk”
GeneralMills 和 GoogleApps#2012
第 1 步:删除任何先前的签名
将 .apk 的扩展名更改为 .zip
打开并删除文件夹 META-INF
将扩展名更改为 .apk
或者
命令:
• zip [原始apk]
例子:
• zip "$1".apk -d
第 2 步:使用release.keystore 签名..
命令:
• jarsigner –verbose –keystore [keystorefile] –signedjar [unalignedapk] [originalapk] alias_name
例子:
• C:\Program Files\Java\jdk1.6.0_43\bin> jarsigner -verbose -keystore release.keystore -signedjar "$1"_unaligned.apk "$1".apk release
步骤 3:对齐
命令:
• zipalign -f 4 [unalignedapk] [releaseapk]
例子:
• C:\Users\G535940\Downloads\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\too
ls>zipalign -f 4 "$1"_unaligned.apk "$1"_release.apk
步骤 4:清理
命令:
• rm 4 [未对齐的apk]
例子:
• rm "$1"_unaligned.apk
其他命令可能有帮助:
使用 keytool 生成新密钥
keytool -genkey -alias -keystore
列出密钥
keytool -list -keystore
用于为 Facebook 功能生成 keyhash 的命令
:
• keytool -exportcert -alias alias_name -keystore [keystorefile] | keytool -exportcert -alias alias_name -keystore [keystorefile] | keytool -exportcert -alias openssl sha1 - 二进制 | openssl base64
示例:
• C:\Program Files\Java\jdk1.6.0_43\bin>keytool -exportcert -alias release -keyst
orerelease.keystore|打开l sha1-二进制| openssl base64
注意:
为了签署我们的 APK,我们将 JDK 从 1.7 降级到 1.6.0_43 更新。
原因:
从 JDK 7 开始,默认签名算法已更改,要求您在签署 APK 时指定签名和摘要算法(-sigalg 和 -digestalg)。
命令:
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [密钥库文件]
[原始apk] 别名
Signing for release: $1.apk -> $1_release.apk"
GeneralMills&GoogleApps#2012
Step 1: Removing any previous signing
Change the extension of your .apk to .zip
Open and delete the folder META-INF
Change the extension to .apk
Or
Command:
• zip [originalapk]
Example:
• zip "$1".apk -d
Step 2: Signing with release.keystore..
Command:
• jarsigner –verbose –keystore [keystorefile] –signedjar [unalignedapk] [originalapk] alias_name
Example:
• C:\Program Files\Java\jdk1.6.0_43\bin> jarsigner -verbose -keystore release.keystore -signedjar "$1"_unaligned.apk "$1".apk release
Step 3: Aligning
Command:
• zipalign -f 4 [unalignedapk] [releaseapk]
Example:
• C:\Users\G535940\Downloads\adt-bundle-windows-x86\adt-bundle-windows-x86\sdk\too
ls>zipalign -f 4 "$1"_unaligned.apk "$1"_release.apk
Step 4: Cleaning up
Command:
• rm 4 [unalignedapk]
Example:
• rm "$1"_unaligned.apk
Additional Commands might help:
To generate new key with keytool
keytool -genkey -alias -keystore
To list keys
keytool -list -keystore
Command to generate a keyhash for the Facebook features
Command:
• keytool -exportcert -alias alias_name -keystore [keystorefile] | openssl sha1 -binary | openssl base64
Example:
• C:\Program Files\Java\jdk1.6.0_43\bin>keytool -exportcert -alias release -keyst
ore release.keystore |opens l sha1 -binary | openssl base64
Note:
To sign our apks we have downgraded JDK from 1.7 to 1.6.0_43 update.
Reason:
As of JDK 7, the default signing algorithim has changed, requiring you to specify the signature and digest algorithims (-sigalg and -digestalg) when you sign an APK.
Command:
jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [keystorefile]
[originalapk] alias_name
上述所有解决方案都有效。请注意为什么重新压缩后它不起作用:
.apk 中的某些文件需要保持存储状态(压缩率为 0%)。这是因为Android将使用内存映射(mmap)来读取内容而不解压到内存中。此类文件是 .ogg 和一些图标。
All the solutions above work. Just a note why it didn't work for you when you re-zipped:
Some of the files inside the .apk need to remain stored (compression at 0%). This is because Android will use memory mapping (mmap) to read the contents without unpacking into memory. Such files are .ogg and some of the icons.
假设您的密钥存储在
keys.keystore
中,您可以运行:来确定密钥的别名。然后运行:
使用名为
your_key_alias
的密钥重新签名your_app.apk
。从 JDK 8 开始,额外的
-sigfile CERT
选项似乎是必需的。Assuming your keys are stored in
keys.keystore
, you can run:to determine the alias of your key. Then run:
to re-sign
your_app.apk
with the key namedyour_key_alias
.The extra
-sigfile CERT
option seems to be necessary as of JDK 8.