dan*_*anb 8 android maven android-manifest android-maven-plugin
我有maven目标update-manifest在我的项目中工作,并根据我打包的配置文件更新我想要更改的属性; 不幸的是,它会更改源代码管理中的清单.我希望它能够更改打包的清单,但只保留主版本.我没有看到AndroidManifest的一个版本目标/我可以指向它.我正在使用android-maven插件版本3.2
yor*_*rkw 20
如果使用manifestVersionCode或manifestVersionName之类的配置来更新清单,那么它就是如何设计和运行的,它会将更改写入原始的AndroidManifest.xml.
看起来你真正需要的是过滤器清单而不是更新清单.资源过滤是android-maven-plugin支持并经常使用的另一种使用场景.
示例AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp"
android:versionCode="${app.version.code}"
android:versionName="${app.version.name}">
... ...
Run Code Online (Sandbox Code Playgroud)
示例pom.xml:
<!-- value to be substituted in manifest -->
<properties>
<app.version.code>1</app.version.code>
<app.version.name>1.0.0-SNAPSHOT</app.version.name>
</properties>
... ...
<build>
<resources>
<!-- filter manifest and put filtered file in target/filtered-manifest/ -->
<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>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<!-- tell build process to use filtered manifest -->
<androidManifestFile>${project.build.directory}/filtered-manifest/AndroidManifest.xml</androidManifestFile>
</configuration>
</plugin>
... ...
Run Code Online (Sandbox Code Playgroud)
现在android-maven-plugin将使用过滤的AndroidManifest.xml并保持原始的AndroidManifest.xml不变.
希望这可以帮助.
更新:
你也可能需要这个:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
jel*_*ies 10
我建议使用maven-android-plugin的manifest-update目标来实现这个目的:
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<!-- This is for maven update properties in AndroidManifest file. Working outside eclipse. -->
<executions>
<execution>
<id>update-manifest</id>
<phase>process-resources</phase>
<goals>
<goal>manifest-update</goal>
</goals>
<configuration>
<manifest>
<versionCode>${project.codeVersion}</versionCode>
<versionName>${project.version}</versionName>
</manifest>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
您还需要定义project.codeVersion:
<properties>
<project.codeVersion>1</project.codeVersion>
</properties>
Run Code Online (Sandbox Code Playgroud)
并且maven将更新您的AndroidManifest.xml:
Run Code Online (Sandbox Code Playgroud)[INFO] --- android-maven-plugin:3.3.2:manifest-update (update-manifest) @ myapp --- [INFO] Attempting to update manifest d:\dsv\project\MyApp\AndroidManifest.xml [INFO] Setting android:versionName to 0.0.4 [INFO] Setting android:versionCode to 1 [INFO] Made changes to manifest file, updating d:\...\MyApp\AndroidManifest.xml
有关更多信息Android的:清单更新的目标在这里,你可以找到一些有用的参数那里.
重要说明:此解决方案仅适用于命令行,m2e-android尚不支持插件执行(请参阅此问题).
| 归档时间: |
|
| 查看次数: |
10259 次 |
| 最近记录: |