简体   繁体   English

尝试使用jarsigner.exe手动签名android软件包并使用adb.exe安装

[英]Trying to manually sign android package with jarsigner.exe and install with adb.exe

I've been trying to use the jarsigner.exe and adb.exe to manually sign an android package and install it on a API V8 emulator. 我一直在尝试使用jarsigner.exe和adb.exe手动签署一个android程序包并将其安装在API V8模拟器上。 I created a simple HelloAndroid project and it would generate a signed HelloAndroid.apk using the debug.keystore located in the user's .android directory. 我创建了一个简单的HelloAndroid项目,它将使用位于用户.android目录中的debug.keystore生成一个已签名的HelloAndroid.apk。 When launching from Eclipse, it builds and installs the apk on the emulator without a problem. 从Eclipse启动时,它会毫无问题地在模拟器上生成并安装apk。

I used the android tools to export an unsigned application package to a separate directory. 我使用android工具将未签名的应用程序包导出到单独的目录。 I signed and zipAligned the package and used adb to install it but received the error: 我对包进行了签名和zipAligned,并使用了adb来安装它,但是收到了以下错误消息:

Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

I used the following command to sign it. 我使用以下命令对其进行签名。

jarsigner -verbose -keystore c:\users\jhwong\.android\debug.keystore
     -storepass android -keypass android -digestalg SHA-1 -sigalg SHA1withRSA
     -sigfile CERT -signedjar temp\HelloWorld2.apk
      temp\HelloWorld.unsigned.apk androiddebugkey
   adding: META-INF/MANIFEST.MF
   adding: META-INF/CERT.SF
   adding: META-INF/CERT.RSA
  signing: res/layout/main.xml
  signing: AndroidManifest.xml
  signing: resources.arsc
  signing: res/drawable-hdpi/icon.png
  signing: res/drawable-ldpi/icon.png
  signing: res/drawable-mdpi/icon.png
  signing: classes.dex

That did not give me any errors and just to makes sure I ran: 那没有给我任何错误,只是确保我运行了:

jarsigner -verify -verbose temp\HelloWorld2.apk

It showed the jar was verified and each file signed and part of the manifest. 它表明该罐子已通过验证,并且每个文件都已签名以及清单的一部分。

I ran zipalign -v 4 temp\\HelloWorld2.apk temp\\HelloWorld3.apk which finished without an error. 我运行了zipalign -v 4 temp\\HelloWorld2.apk temp\\HelloWorld3.apk ,完成时没有错误。 Then used adb install -r temp\\HelloWorld3.apk . 然后使用adb install -r temp\\HelloWorld3.apk

I've seen several related threads and articles suggesting these directions but I'm perplexed as to why it doesn't work manually verses using Eclipse to build the signed package. 我看过一些相关的线程和文章提出了这些指导,但是对于为什么它不能手动工作的原因我感到困惑,因为他们使用Eclipse构建了签名包。 I've even taken the package built from Eclipse and was able to use adb.exe to install it so I've narrowed it to signing the package. 我什至已经采用了从Eclipse构建的软件包,并且能够使用adb.exe来安装它,因此我将其范围缩小为对软件包进行签名。 I've tried keystores that I've generated from the keytool but they didn't work as well which is why I tried the debug.keystore. 我尝试了从keytool生成的密钥库,但是它们不能正常工作,这就是为什么我尝试了debug.keystore的原因。

I'd appreciate any advice if they noticed anything wrong with my jarsigner code. 如果他们发现我的jarsigner代码有任何问题,我将不胜感激。

We had this exact same problem. 我们有同样的问题。 Try using the following parameter values: 尝试使用以下参数值:

jarsigner ... -digestalg SHA1 -sigalg MD5withRSA ...

By the way, using explicit sigalg and digestalg seems to be mandatory with JDK 7. 顺便说一下,在JDK 7中似乎必须使用显式sigalg和摘要。

To sign apks using JDK 1.7 one has to use these keywords "-sigalg MD5withRSA -digestalg SHA1 " 要使用JDK 1.7签名apk,必须使用这些关键字"-sigalg MD5withRSA -digestalg SHA1 "

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. 原因:从JDK 7开始,默认的签名算法已更改,要求您在签名APK时指定签名并摘要算法(-sigalg和-digestalg)。

Command: 命令:

jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore [keystorefile]
[originalapk] alias_name

If you're using JDK 7, try 如果您使用的是JDK 7,请尝试

jarsigner -sigalg SHA1withRSA -digestalg SHA1

If you get 如果你得到

jarsigner error: java.security.SignatureException: private key algorithm is not compatible with signature algorithm

then try 然后尝试

jarsigner -sigalg MD5withRSA -digestalg SHA1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM