6

Hey I am having a hard time building and signing apk in release mode. I am able to create the apk using maven but when I try to upload it, Google playstore says that I need to build in release mode.

here is my 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> 

Can anyone help me with how to release it in the build mode?

Nemin
  • 1,907
  • 6
  • 24
  • 37

1 Answers1

13

Your apk needs to be signed and zipaligned. So you should first 'bind' the jarsigner execution to the package phase and in an 2nd time configure zipalign in your android plugin. see http://www.simpligility.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>
willome
  • 3,062
  • 19
  • 32
  • the more recent android-maven-plugin as opposed to maven-android-plugin requied the definition of false inside the element in order to run, it seems it is disabled by default! – PiersyP Jun 13 '14 at 16:14
  • Add https://timestamp.geotrust.com/tsa to jarsigner -tag to timestamp and thereby avoid timestamp warning. – JohnyTex Jun 22 '16 at 10:36