Android APK签名存在什么样的陷阱?

Mar*_*tin 24 android jarsigner maven java-7

免责声明:我知道签署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>
Run Code Online (Sandbox Code Playgroud)

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

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]
Run Code Online (Sandbox Code Playgroud)

正如我在第一句中所说:在使用Mac OS X进行签名时,它工作正常.只有在使用Windows 7进行签名时才会失败.

--debug在调用Maven时使用我看到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]
Run Code Online (Sandbox Code Playgroud)

还有什么可能出错?

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

ATo*_*Tom 45

解决方案是将其添加到<configuration>maven-jarsigner-plugin:

<arguments>
  <argument>-sigalg</argument><argument>MD5withRSA</argument>
  <argument>-digestalg</argument><argument>SHA1</argument>
</arguments>
Run Code Online (Sandbox Code Playgroud)

Ant 已经直接支持这一点,但Maven插件没有.


Esk*_*ahn 10

找到1.7的使用信息非常棘手,但一旦发现它很简单:

对于keytool包括:

-sigalg SHA1withDSA -keyalg DSA -keysize 1024
Run Code Online (Sandbox Code Playgroud)

对于jarsigner包括:

-sigalg SHA1withDSA -digestalg SHA1
Run Code Online (Sandbox Code Playgroud)

(1024是最大值并且有效,少可能做到这一点)