Android maven build not signing application

226 views Asked by At

I have been following a couple posts and resources off the internet to get Maven to sign my android apk file. But when I verify if the apk file has been signed using jarsigner, it says that the "jar is unsigned". However, the zip align seems to be working, and the maven console output does say "Enabling release build for apk."

The build part of my pom.xml looks as follows:

<build>
        <finalName>${project.artifactId}</finalName>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jarsigner-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>signing</id>
                            <goals>
                                <goal>sign</goal>
                                <goal>verify</goal>
                            </goals>
                            <phase>package</phase>
                            <inherited>true</inherited>
                            <configuration>
                                <removeExistingSignatures>true</removeExistingSignatures>
                                <archiveDirectory/>
                                <includes>
                                    <include>${project.build.directory}/${project.artifactId}.apk</include>
                                </includes>
                                <keystore>c:/java/android/my.keystore</keystore>
                                <alias>myalias</alias>
                                <storepass>mypass</storepass>
                                <keypass>mypass</keypass>
                                <verbose>true</verbose>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                    <artifactId>android-maven-plugin</artifactId>
                    <version>${android.plugin.version}</version>
                    <configuration>
                        <release>true</release>
                        <mergeManifests>true</mergeManifests>
                        <sign>
                            <debug>false</debug>
                        </sign>
                        <zipalign>
                            <verbose>true</verbose>
                            <inputApk>${project.build.directory}/${project.artifactId}.apk</inputApk>
                            <outputApk>${project.build.directory}/${project.artifactId}-signed-aligned.apk</outputApk>
                            <skip>false</skip>
                        </zipalign>
                    </configuration>
                    <executions>
                        <execution>
                            <id>alignApk</id>
                            <phase>package</phase>
                            <goals>
                                <goal>zipalign</goal>
                            </goals>
                        </execution>
                    </executions>
                    <extensions>true</extensions>
                </plugin>
                <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>
                                            com.jayway.maven.plugins.android.generation2
                                        </groupId>
                                        <artifactId>
                                            android-maven-plugin
                                        </artifactId>
                                        <versionRange>
                                            [3.8.0,)
                                        </versionRange>
                                        <goals>
                                            <goal>consume-aar</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore></ignore>
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.jayway.maven.plugins.android.generation2</groupId>
                <artifactId>android-maven-plugin</artifactId>
                <configuration>
                    <sdk>
                        <platform>15</platform>
                    </sdk>
                </configuration>
            </plugin>
        </plugins>
    </build>

Any ideas why jarsigner would be saying my apk is not signed with the above pom.xml ?

1

There are 1 answers

0
dleerob On

I managed to get it working by removing the <pluginManagement> element tags, so the <plugins> element was not nested inside a <pluginManagement> element.

Now my apk file is signed.