我一直在关注互联网上的一些帖子和资源,让Maven签署我的安卓apk文件。但是当我验证 apk 文件是否已使用 jarsigner 签名时,它说"jar 未签名"。 但是,zip对齐似乎正在工作,并且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 ?
我设法通过删除<pluginManagement>
元素标签来使其工作,因此<plugins>
元素不会嵌套在<pluginManagement>
元素中。
现在我的apk文件已签名。