无法使用名称中给定版本的 Maven 构建 apk
我尝试使用属性文件读取属性,以在使用 Maven 构建时将这些值设置到 apk 中。
我用过的插件 ->>>>>>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/buildNumber.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>myapk.${majorversion}.${minor_version}.${patch_version}.${maven.build.timestamp}</finalName>
文件:buildNumber.properties
major_version=01
minor_version=00
patch_version=00
这会生成 myapk.01.00.00.20120127-2010.jar 但 apk 是 myapk.${major_version}.a.${minor_version}.${patch_version}.20120127-2010.apk
让我知道我缺少什么这里..?
I have tried to use properties file to read properties to set those values into apk while building using maven.
Pluging i have used
->>>>>>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/buildNumber.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<build>
<sourceDirectory>src</sourceDirectory>
<finalName>myapk.${majorversion}.${minor_version}.${patch_version}.${maven.build.timestamp}</finalName>
File: buildNumber.properties
major_version=01
minor_version=00
patch_version=00
This generating myapk.01.00.00.20120127-2010.jar but apk is myapk.${major_version}.a.${minor_version}.${patch_version}.20120127-2010.apk
Let me know what I am missing here..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道确切的原因,但看起来properties-maven-plugin可以替换pom.xml中properties标签下正确定义的属性值,而maven只能识别pom.xml中显式定义的属性名称,如下pom 对我有用:
编辑:
从我的角度来看,maven 的预定义构建生命周期是相当排他性的,尤其是在与 ADT 等其他构建工具集成时,用于生成 apk 的 pom 版本受到很大限制,而且来自 插件文档,当前版本的 android-maven-plugin 没有提供任何用于在 apk 目标期间自定义最终 apk 名称的配置。 此处发布了类似的讨论,最终得到不是那么完美的答案。
作为最后一个镜头,android-maven-plugin 提供了在 zipalign 目标期间自定义最终 apk 名称的选项:
如果您使用 maven zipalign 您的最终 apk(我想您会这样做),这可能是一个解决方案,您将获得所有三个输出文件( .ap_ 和 .apk 和 .jar) 以默认的 ${project.version} 结尾,再加上另一个以 ${major_version} 对齐的 apk 结尾,但是只有这三个具有默认 ${project.version} 的文件才会安装在Maven 中央存储库。
I don't know the exact reason, but it looks like properties-maven-plugin can substitute the property value properly defined under properties tag in pom.xml, and maven can only recognize the properties name explicitly defined in pom.xml, the following pom works for me:
EDIT:
From my point of view, The predefined build lifecycle of maven is quite exclusive especially when integrating with other build tools like ADT, the pom version used for generating the apk is quite restricted, moreover, from the plugin documentation, current version of android-maven-plugin does not provide any configuration for customizing the final apk name during apk goal. A similar discussion was posted here end up with a not so perfect answer.
As a last shot, android-maven-plugin provide options to customize the final apk name during zipalign goal:
This could be a solution if you use maven zipalign your final apk (I suppose you do), you will get all three output files (.ap_ and .apk and .jar) end with the default ${project.version} plus another apk end with ${major_version}-aligned, however only those three with the default ${project.version} will get installed in the maven central repository.