0

Since updating a very old project to android-maven-plugin version 4.1.0 I have following error when signing my apk for release:

unable to sign jar: java.util.zip.ZipException: invalid entry compressed size

My maven signing config in pom:

  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jarsigner-plugin</artifactId>
            <version>1.2</version>
            <executions>
              <execution>
                <id>signing</id>
                <goals>
                  <goal>sign</goal>
                </goals>
                <phase>package</phase>
                <inherited>true</inherited>
                <configuration>
                  <archiveDirectory></archiveDirectory>
                  <includes>
                    <include>target/*.apk</include>
                  </includes>
                  <keystore>keystore/keystore</keystore>
                  <storepass>sjdjjfdf</storepass>
                  <keypass>sjdjjfdf</keypass>
                  <alias>v110</alias>
                  <arguments>
                    <argument>-sigalg</argument>
                    <argument>MD5withRSA</argument>
                    <argument>-digestalg</argument>
                    <argument>SHA1</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.simpligility.maven.plugins</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
              <sign>
                <debug>false</debug>
              </sign>
              <zipalign>
                <skip>false</skip>
                <verbose>true</verbose>
                <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
                <outputApk>${project.build.directory}/${project.artifactId}-release-v${project.version}.apk</outputApk>
              </zipalign>
            </configuration>
            <executions>
              <execution>
                <id>alignApk</id>
                <phase>install</phase>
                <goals>
                  <goal>zipalign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

After investigation I found out that:

  • The different size was due to the META-INF folder in generated debug apk.
  • This was due to an automatic signing of the debug apk.

Did someone have this problem and find a solution for it?

Related post, but not linked to pom and maven config:

jarsigner: unable to sign jar: java.util.zip.ZipException: invalid entry compressed size (expected 463 but got 465 bytes)

Community
  • 1
  • 1
L. G.
  • 9,642
  • 7
  • 56
  • 78
  • Added this question for documentation purpose as I couldn't find any questions and this subject and searched a solution for quite a while... – L. G. Mar 12 '15 at 10:11
  • Any special reason using such an old version? [Current 1.4](http://maven.apache.org/plugins/maven-jarsigner-plugin/) – khmarbaise Mar 12 '15 at 11:19
  • No, this was an old project with version 1.2. I upgraded to version 1.4 after the post. – L. G. Mar 12 '15 at 13:22

1 Answers1

1

After searching to remove META-INF files from the jar generation in release profile, I found out the the easiest solution is to add <removeExistingSignatures>true</removeExistingSignatures> to maven-jarsigner-plugin config:

  <profiles>
    <profile>
      <id>release</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jarsigner-plugin</artifactId>
            <version>1.2</version>
            <executions>
              <execution>
                <id>signing</id>
                <goals>
                  <goal>sign</goal>
                </goals>
                <phase>package</phase>
                <inherited>true</inherited>
                <configuration>
                  <!-- Remove debug signature added to the apk automatically since x android plugin version -->
                  <removeExistingSignatures>true</removeExistingSignatures>
                  <archiveDirectory></archiveDirectory>
                  <includes>
                    <include>target/*.apk</include>
                  </includes>
                  <keystore>keystore/keystore</keystore>
                  <storepass>sjdjjfdf</storepass>
                  <keypass>sjdjjfdf</keypass>
                  <alias>v110</alias>
                  <arguments>
                    <argument>-sigalg</argument>
                    <argument>MD5withRSA</argument>
                    <argument>-digestalg</argument>
                    <argument>SHA1</argument>
                  </arguments>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.simpligility.maven.plugins</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <inherited>true</inherited>
            <configuration>
              <sign>
                <debug>false</debug>
              </sign>
              <zipalign>
                <skip>false</skip>
                <verbose>true</verbose>
                <inputApk>${project.build.directory}/${project.artifactId}-${project.version}.apk</inputApk>
                <outputApk>${project.build.directory}/${project.artifactId}-release-v${project.version}.apk</outputApk>
              </zipalign>
            </configuration>
            <executions>
              <execution>
                <id>alignApk</id>
                <phase>install</phase>
                <goals>
                  <goal>zipalign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
L. G.
  • 9,642
  • 7
  • 56
  • 78