stevebot
stevebot

Reputation: 24035

Maven and Android natures not playing nice together

I have an existing Android project in Eclipse which I recently decided I need to convert to a Maven enabled project so that I can build an AAR. By clicking Configure -> Convert to Maven Project, I was able to get a POM added. I then added a parent POM as well, and POM's for any dependent library projects. I added the android-maven plugin and set the packaging type to AAR.

However, once I ran Maven install, I instantly received errors. The libs, assets and res directories were expected by the android-maven plugin to be in the src/main directory. As was the AndroidManfiest. If I moved these files and fixed these errors, Maven was able to build my AAR.

Now I am left with some choices; either convert my project to the module based structure (e.g. src/main) or leave it in the Eclipse structure. Neither of these is convenient.

I believe the best possibility might be to preserve the Eclipse structure, so I can run and build my project in Eclipse. For building Maven, I believe that I am going to have to add some build scripting to essentially copy my project to another location, set the android-maven project structure, and then build and install my AAR.

Has anyone faced this situation, and what was your outcome? If no one answers, I will document my solution which involves some Ant scripting.

Upvotes: 0

Views: 203

Answers (1)

stevebot
stevebot

Reputation: 24035

The answer ended up being that additional Gradle configuration was necessary with the android-maven-plugin. This let us specify a custom location for various directories and files in our Android project.

An example,

<sourceDirectory>src/</sourceDirectory>
        <plugins>
             <plugin>
                <groupId>com.simpligility.maven.plugins</groupId>
                <artifactId>android-maven-plugin</artifactId>
                 <extensions>true</extensions>
                    <configuration>
                        <attachNativeArtifacts>true</attachNativeArtifacts>
                        <nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
                        <assetsDirectory>${project.basedir}/assets</assetsDirectory>
                        <resourceDirectory>${project.basedir}/res</resourceDirectory>
                        <androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
                        <failOnNonStandardStructure>false</failOnNonStandardStructure>
                    </configuration>
            </plugin>

This allowed for us to build an AAR without having to change project structure around.

Upvotes: 2

Related Questions