6

嘿,我很难在发布模式下构建和签署 apk。我可以使用 maven 创建 apk,但是当我尝试上传它时,Google playstore 说我需要在发布模式下构建。

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.kannact4.gladstonesign</groupId>
 <artifactId>gladstonesign</artifactId>
 <version>1.0.0-SNAPSHOT</version>
 <packaging>apk</packaging>
 <name>Android Maven Example</name>


 <profiles>
  <profile>
    <id>release</id>
     <activation>
      <property>
        <name>performRelease</name>
        <value>true</value>
      </property>
    </activation>
    </profile>
    </profiles>
 <dependencies>
  <dependency>
   <groupId>com.google.android</groupId>
   <artifactId>android</artifactId>
   <version>2.2.1</version>
   <scope>provided</scope>
  </dependency>
 </dependencies>
 <build>
  <finalName>unaligned-gladstonesign</finalName>
  <sourceDirectory>src</sourceDirectory>

  <pluginManagement>
   <plugins>
    <plugin>
     <groupId>com.jayway.maven.plugins.android.generation2</groupId>
     <artifactId>android-maven-plugin</artifactId>
     <version>3.1.1</version>
     <extensions>true</extensions>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jarsigner-plugin</artifactId>
        <version>1.2</version>
        <configuration>
          <keystore>C:\Project\Eclipse workspace\apk_key</keystore>
          <alias>gs3key</alias>
          <storepass>****</storepass>
          <keypass>****</keypass>
          <verbose>true</verbose>
          <certs>true</certs>
        </configuration>
        </plugin>
   </plugins>
  </pluginManagement>
  <plugins>
   <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <configuration>
     <sdk>
      <platform>17</platform>
     </sdk>
    </configuration>
   </plugin>
  </plugins>
 </build>
</project> 

谁能帮助我如何在构建模式下发布它?

4

1 回答 1

13

您的 apk 需要签名和压缩对齐。因此,您应该首先将jarsigner执行“绑定”到阶段,然后在您的 android 插件package中进行第二次配置。zipalign请参阅http://www.simligility.com/2010/07/sign-zipalign-and-to-market-to-market-with-maven/

<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>${sign.keystore}</keystore>
            <alias>${sign.alias}</alias>
            <storepass>${sign.storepass}</storepass>
            <keypass>${sign.keypass}</keypass>
            <verbose>true</verbose>
        </configuration>
    </execution>
</executions>
</plugin>


<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<inherited>true</inherited>
<configuration>
    <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>
</plugin>
于 2013-05-23T08:07:25.767 回答