I have the maven goal update-manifest working in my project and updating the attributes I want changed based on the profile I'm packaging with; Unfortunately it changes the manifest that is in source control. I would like it to change the manifest that is packaged, but leave the master version alone. I don't see a version of AndroidManifest under target/ that I can point it at. I am using the android-maven plugin version 3.2
If you use configurations like manifestVersionCode or manifestVersionName to update manifest, this is how it is designed and supposed to work, it writes the changes to the original AndroidManifest.xml.
It seems what you really need is filter manifest rather than update manifest. Resource filtering is another use scenario supported by android-maven-plugin and frequently used.
Sample 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}">
... ...
Sample 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>
... ...
Now android-maven-plugin will use the filtered AndroidManifest.xml and leave the original AndroidManifest.xml unchanged.
Hope this helps.
Update:
you might need this too:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
</plugin>
I recommend to use manifest-update goal of maven-android-plugin to accomplish this:
<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>
You need to define also project.codeVersion
:
<properties>
<project.codeVersion>1</project.codeVersion>
</properties>
And maven will update your AndroidManifest.xml:
[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
More information about android:manifest-update goal here, you can find some useful parameters there.
Important note: This solution only works from command line, plugin execution is not yet supported by m2e-android (see this issue).
© 2022 - 2024 — McMap. All rights reserved.