How to avoid AndoridManifest overriding with maven

528 Views Asked by At

I have a project almost equals to the android-quickstart archetype:

mvn archetype:generate \
-DarchetypeArtifactId=android-quickstart \
-DarchetypeGroupId=de.akquinet.android.archetypes \
-DarchetypeVersion=1.0.11 \
-DgroupId=your.company \
-DartifactId=my-android-application

I added an aar dependency to the pom.xml:

<dependency>
  <groupId>com.my.company</groupId>
  <artifactId>my-lib</artifactId>
  <version>0.6.41-SNAPSHOT</version>
  <type>aar</type>
</dependency>

And configured the android-maven-plugin to merge the manifest:

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <configuration>
                <mergeManifests>true</mergeManifests>
            </configuration>
            <version>${android.plugin.version}</version>
            <extensions>true</extensions>
        </plugin>
    </plugins>
</pluginManagement>

Then I do mvn clean install.

I thought that this was going to merge the two manifests and put the result straight into the apk (in my-app/target/my-app.apk/AndroidManifest.xml). But instead it is overriding my original AndroidManifest.xml (in my-app/AndroidManifest.xml).

Is there any way to leave the original AndroidManifest.xml intact (like Gradle does in Android Studio)?

1

There are 1 best solutions below

6
On BEST ANSWER

UPDATE:

Since android-maven-plugin 4.1.0, this is the default behavior, and additional configuration is not needed.

Add these lines to your configuration:

<androidManifestFile>${project.build.directory}/AndroidManifest.xml</androidManifestFile>
<sourceManifestFile>${project.basedir}/AndroidManifest.xml</sourceManifestFile>
<updatedManifestFile>${project.build.directory}/AndroidManifest.xml</updatedManifestFile>

This should copy your original manifest first, then update the copied file.