gpt4 book ai didi

android - 如何使用 Maven 在 Release模式下构建 apk

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:00:34 25 4
gpt4 key购买 nike

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

这是我的 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>

任何人都可以帮助我如何在构建模式下发布它吗?

最佳答案

您的 apk 需要签名和 zipaligned。因此,您应该首先将 jarsigner 执行“绑定(bind)”到 package 阶段,并在第二次配置 zipalign 在您的 android 插件中。见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>

关于android - 如何使用 Maven 在 Release模式下构建 apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16699487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com