自动更新AndroidManifest版本号

最近,我需要自动执行AndroidManifest.xml文件中versionName元素的更新。 运行构建时,需要对此打上时间戳记并使用正确的版本号进行更新。 我们将maven作为构建的一部分,使用了一些插件。 我们要使用POM的版本号,以便可以使用诸如maven-release-plugin或maven版本插件之类的工具。 当这些文件运行时,新版本号应反映在内置的APK中。

以下是添加到pom构建部分中的魔术,可以解决此问题。

<plugins>
   <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <version>1.8</version>
      <executions>
         <execution>
            <id>parse-version</id>
               <goals>
                  <goal>parse-version</goal>
               </goals>
               <phase>validate</phase>
          </execution>
       </executions>
    </plugin>
    <plugin>
       <groupId>com.google.code.maven-replacer-plugin</groupId>
       <artifactId>maven-replacer-plugin</artifactId>
       <version>1.4.1</version>
       <executions>
         <execution>
            <id>replace-version</id>
            <phase>validate</phase>
            <goals>
               <goal>replace</goal>
            </goals>
         </execution>
       </executions>
       <configuration>
          <file>AndroidManifest.xml</file>
          <replacements>
              <replacement>
                 <token>0.0.0</token>                                   <value>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}.${maven.build.timestamp}</value>
              </replacement>
          </replacements>
          <quiet>false</quiet>
       </configuration>
   </plugin>
</plugins>

您可以将其添加为配置文件的一部分,并且仅当您在Jenkins上进行构建或发布时才启用它。 您的AndroidManifest.xml应将versionName值设置为0.0.0,并且在启用配置文件的情况下运行构建时,它将用pom的版本替换它,并添加时间戳。

翻译自: https://www.javacodegeeks.com/2014/03/update-the-androidmanifest-version-number-automatically.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值