【问题标题】:What kind of pitfals exist for the Android APK signing?Android APK 签名存在哪些陷阱?
【发布时间】:2012-02-03 01:38:34
【问题描述】:

免责声明:我知道签署 APK 的基础知识,但我只有一个项目存在问题,并且仅在使用 Microsoft Windows 作为操作系统进行签名时出现问题。

我正在使用 Maven 构建我的 APK 并使用 maven-jarsigner-plugin 对其进行签名:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jarsigner-plugin</artifactId>
    <executions>
      <execution>
        <id>signing</id>
        <goals>
          <goal>sign</goal>
        </goals>
        <phase>package</phase>
        <inherited>true</inherited>
        <configuration>
          <archive>target/${project.build.finalName}.apk</archive>
          <sigfile>CERT</sigfile>
          <keystore>${env.HOME}/.keystore</keystore>
          <storepass>${env.KEY_STOREPASS}</storepass>
          <keypass>${env.KEY_KEYPASS}</keypass>
          <alias>${env.KEY_ALIAS}</alias>
        </configuration>
      </execution>
    </executions>
  </plugin>

现在我的一个项目在尝试安装和启动应用程序时出现以下错误:

1360 KB/s (2057872 bytes in 1.477s)
        pkg: /data/local/tmp/FX-602P-Droid-5.0.0.apk
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]

正如我在第一句话中所说:使用 Mac OS X 签名时效果很好。仅在使用 Windows 7 签名时会失败。

在调用Maven时使用--debug我看到jarsigner调用ok并且没有报错:

[INFO]
[INFO] --- maven-jarsigner-plugin:1.2:sign (signing) @ FX-602P-Droid ---
[DEBUG] org.apache.maven.plugins:maven-jarsigner-plugin:jar:1.2:
[DEBUG]    org.apache.maven:maven-plugin-api:jar:2.0.6:compile
[DEBUG]    org.apache.maven:maven-project:jar:2.0.6:compile
[DEBUG]       org.apache.maven:maven-settings:jar:2.0.6:compile
[DEBUG]       org.apache.maven:maven-profile:jar:2.0.6:compile
[DEBUG]       org.apache.maven:maven-model:jar:2.0.6:compile
[DEBUG]       org.apache.maven:maven-artifact-manager:jar:2.0.6:compile
[DEBUG]          org.apache.maven:maven-repository-metadata:jar:2.0.6:compile
[DEBUG]       org.apache.maven:maven-plugin-registry:jar:2.0.6:compile
[DEBUG]       org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
[DEBUG]          junit:junit:jar:3.8.1:compile
[DEBUG]          classworlds:classworlds:jar:1.1-alpha-2:compile
[DEBUG]    org.apache.maven:maven-artifact:jar:2.0.6:compile
[DEBUG]    org.codehaus.plexus:plexus-utils:jar:1.5.15:compile
[DEBUG] Created new class realm plugin>org.apache.maven.plugins:maven-jarsigner-plugin:1.2
[DEBUG] Importing foreign packages into class realm plugin>org.apache.maven.plugins:maven-jarsigner-plugin:1.2
[DEBUG]   Imported:  < project>net.sourceforge.uiq3:FX-602P-Droid:5.0.0
[DEBUG] Populating class realm plugin>org.apache.maven.plugins:maven-jarsigner-plugin:1.2
[DEBUG]   Included: org.apache.maven.plugins:maven-jarsigner-plugin:jar:1.2
[DEBUG]   Included: junit:junit:jar:3.8.1
[DEBUG]   Included: org.codehaus.plexus:plexus-utils:jar:1.5.15
[DEBUG]   Excluded: org.apache.maven:maven-plugin-api:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-project:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-settings:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-profile:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-model:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-artifact-manager:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-repository-metadata:jar:2.0.6
[DEBUG]   Excluded: org.apache.maven:maven-plugin-registry:jar:2.0.6
[DEBUG]   Excluded: org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1
[DEBUG]   Excluded: classworlds:classworlds:jar:1.1-alpha-2
[DEBUG]   Excluded: org.apache.maven:maven-artifact:jar:2.0.6
[DEBUG] Configuring mojo org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-jarsigner-plugin:1.
2, parent: sun.misc.Launcher$AppClassLoader@214c4ac9]
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-jarsigner-plugin:1.2:sign' with basic configurator -->
[DEBUG]   (f) alias = krischik
[DEBUG]   (f) archive = C:\Work\uiq3\Java\FX-602P-Droid\target\FX-602P-Droid-5.0.0.apk
[DEBUG]   (f) arguments = []
[DEBUG]   (f) keypass = Atlan.
[DEBUG]   (f) keystore = C:\Users\martin.krischik/.keystore
[DEBUG]   (f) processAttachedArtifacts = true
[DEBUG]   (f) processMainArtifact = true
[DEBUG]   (f) project = MavenProject: net.sourceforge.uiq3:FX-602P-Droid:5.0.0 @ C:\Work\uiq3\Java\FX-602P-Droid\pom.xml
[DEBUG]   (f) removeExistingSignatures = false
[DEBUG]   (f) sigfile = CERT
[DEBUG]   (f) skip = false
[DEBUG]   (f) storepass = !AtlanRhodan!
[DEBUG]   (f) verbose = false
[DEBUG] -- end configuration --
[DEBUG] Verarbeite C:\Work\uiq3\Java\FX-602P-Droid\target\FX-602P-Droid-5.0.0.apk
[DEBUG] 'cmd.exe /X /C "C:\opt\Java\jdk\1.7.0\bin\jarsigner.exe -keystore C:\Users\martin.krischik/.keystore -storepass '*****' -keypass '*****' -sigfile CERT C:\Work\u
iq3\Java\FX-602P-Droid\target\FX-602P-Droid-5.0.0.apk krischik"'
[INFO] 1 Archiv(e) verarbeitet
[INFO]

还有什么问题?

PS:我刚刚注意到C:\opt\Java\jdk\1.7.0\bin\jarsigner.exe — jarsigner 从 1.6 到 1.7 有变化吗?为什么 Maven 会在 1.6 项目中使用 1.7 签名者?

【问题讨论】:

标签: android maven java-7 jarsigner


【解决方案1】:

查找 1.7 的使用信息非常棘手,但一旦找到它就相当简单了:

keytool 包括:

-sigalg SHA1withDSA -keyalg DSA -keysize 1024

jarsigner 包括:

-sigalg SHA1withDSA -digestalg SHA1

(1024 是最大值并且有效,更少可能会起作用)

【讨论】:

  • 不完全是jarsigner error: java.security.SignatureException: private key algorithm is not compatible with signature algorithm
  • 我在使用这些设置时遇到了与 Martin 相同的错误。将 keytool 参数更改为 -sigalg MD5withRSA -keyalg RSA -keysize 1024 对我有用。
  • Baqueta,如果你想使用原始密钥而不生成新密钥怎么办?我和马丁有同样的问题
【解决方案2】:

解决方案是将这个添加到maven-jarsigner-plugin的&lt;configuration&gt;

<arguments>
  <argument>-sigalg</argument><argument>MD5withRSA</argument>
  <argument>-digestalg</argument><argument>SHA1</argument>
</arguments>

Ant already has direct support 用于此,但 Maven 插件没有。

【讨论】:

  • 您是否为 jarsigner 插件创建了错误报告/功能请求甚至补丁...
  • 没有。我这里没有账号。但类似的问题已经存在jira.codehaus.org/browse/MJARSIGNER-21,但不建议用蚂蚁的方式修复它:-(
  • @Manfred Moser:这不是 jarsigner 错误,而是 Android 不受欢迎的功能。
  • @Martin: 不,这是 maven-jarsigner-plugin 中缺少的功能
  • @Manfred Moser:怎么会?我虽然 maven-jarsigner-plugin 插件不仅用于签署 android 应用程序。
【解决方案3】:

Baqueta 的解决方案也适用于我。

在 keytool 中使用这些参数:

-sigalg MD5withRSA -keyalg RSA -keysize 1024 

我仍在 jarsigner 中使用:

-sigalg MD5withRSA -digestalg SHA1

感谢您,终于在使用 Java 7 的设备上编译并安装了 APK!

【讨论】:

    【解决方案4】:

    谢谢...它帮助我纠正了签名问题...

    jarsigner -verbose -sigalg SHA1withRSA -digestalg
    keytool -sigalg MD5withRSA -keyalg RSA
    

    最后别忘了zipalign

    我使用了类似的keytooljarsigner 方法,问题得到了解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-11
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 2015-07-07
      • 1970-01-01
      相关资源
      最近更新 更多