【发布时间】:2013-06-22 12:42:24
【问题描述】:
我有一个使用 Maven 构建的 Android 应用程序。
使用 buildnumber-maven-plugin 和 maven-resources-plugin 我将 maven 项目版本和 git commit hash 插入到 AndroidManifest 中。
buildnumber-maven-plugin 的create 目标在validate 阶段运行,maven-resources-plugin 的resources 目标在initialize 阶段运行。
通过命令行(使用mvn install)构建时,一切正常,并且构建号正确显示在生成的清单中。
但是,当通过 Android Studio 或 IntelliJ 构建时,清单中不存在 git commit hash(Maven 属性未替换为实际值),但 maven 项目版本存在。
为什么?
仅供参考:Android Studio 在 Make 之前运行 Maven 阶段 process-resources,因此它应该可以工作。
在命令行上,我使用的是 Maven 3.0.3,因此可能是版本问题(尽管我无法找出 IntelliJ 使用的版本)。
这是我的 POM 的构建元素:
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/filtered-manifest</targetPath>
<includes>
<include>AndroidManifest.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>${maven.buildnumber.version}</version>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<shortRevisionLength>6</shortRevisionLength>
<revisionOnScmFailure>000000</revisionOnScmFailure>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.version}</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<androidManifestFile>${project.build.directory}/filtered-manifest/AndroidManifest.xml</androidManifestFile>
</configuration>
</plugin>
</plugins>
</build>
我的 AndroidManifest 文件中的 versionName 是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.somecompany"
android:versionCode="1"
android:versionName="${project.version}-${buildNumber}" >
从命令行 ${project.version} 和 ${buildNumber} 都正确填写了它们的值,从 IntelliJ ${buildNumber} 不是并且只是显示为“${buildNumber}”:这表明(因为我已设置revisionOnScmFailure) 插件根本无法运行。
我已尝试将 create 目标更改为在 initialize 阶段运行(以防 IntelliJ 跳过 validate),但这没有任何区别。
【问题讨论】:
-
这个问题有进展吗?
-
遗憾的是我还没有;作为解决方法,您可以使用 IntelliJ 的 maven“安装”任务而不是“制作”
标签: android maven intellij-idea android-manifest android-studio