1

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)?

pomber
  • 23,132
  • 10
  • 81
  • 94

1 Answers1

3

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.

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
  • [ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources (default-generate-sources) on project my-app: Manifests were not merged! -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:generate-sources (default-generate-sources) on project my-app: Manifests were not merged! – pomber Dec 04 '14 at 21:03
  • This works with no merged manifest for sure (i use this config in my project), but just for a single updated manifest. Is this the only relevant part of the error log? – WonderCsabo Dec 04 '14 at 21:24
  • Sorry, the relevant part is: Error: [my-app\target\AndroidManifest.xml] XML file not found Error: [my-app\target\AndroidManifest.xml] Failed to read manifest file. [ERROR] Manifests were not merged! – pomber Dec 04 '14 at 21:28
  • It seems the manifest was not copied. Are you using the latest android-maven-plugin? It is clear you are not, because it now has a [new groupid](http://www.simpligility.com/2014/11/android-maven-plugin-4-0-0-ships/). Be ware that this version has breaking changes, so maybe you could update to `3.9.0-rc.3` for now with the old groupId. – WonderCsabo Dec 04 '14 at 21:32
  • 1
    Great! This is documented [here](http://simpligility.github.io/android-maven-plugin/generate-sources-mojo.html#sourceManifestFile). (This page is referenced in the README in GitHub). – WonderCsabo Dec 04 '14 at 22:25
  • `android-maven-plugin` 4.1.0 is released, which uses the wanted behavior by default, no configuration is needed! – WonderCsabo Jan 14 '15 at 14:51