【问题标题】:Android maven build not signing applicationAndroid maven构建未签名应用程序
【发布时间】:2014-11-25 10:40:47
【问题描述】:

我一直在关注互联网上的一些帖子和资源,以让 Maven 签署我的 android apk 文件。但是当我验证 apk 文件是否已使用 jarsigner 签名时,它会说“jar 未签名”。但是,zip align 似乎可以正常工作,并且 maven 控制台输出确实显示“为 apk 启用发布版本”。

我的 pom.xml 的构建部分如下所示:

<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>

知道为什么 jarsigner 会说我的 apk 没有用上面的 pom.xml 签名吗?

【问题讨论】:

    标签: android maven maven-plugin android-maven-plugin


    【解决方案1】:

    我设法通过删除&lt;pluginManagement&gt; 元素标签使其工作,因此&lt;plugins&gt; 元素没有嵌套在&lt;pluginManagement&gt; 元素中。

    现在我的 apk 文件已签名。

    【讨论】: