Using pure Java libs, in a Android Maven project

By : TacB0sS
Source: Stackoverflow.com
Question!

I have an Android Maven project, which uses pure Java libs, I've struggled with it for hours, the last few days, and no matter what I do, I constantly end up getting the following error:

[INFO] d:\Development-Android\SDKs\Android\platform-tools\aapt.exe [package, -f, -M, D:\Development-Android\Workspaces\Android-Workspace\S-O-D\AndroidManifest.xml, -S, D:\Development-Android\Workspaces\Android-Workspace\S-O-D\res, --auto-add-overlay, -A, D:\Development-Android\Workspaces\Android-Workspace\S-O-D\target\generated-sources\combined-assets\assets, -I, d:\Development-Android\SDKs\Android\platforms\android-7\android.jar, -F, D:\Development-Android\Workspaces\Android-Workspace\S-O-D\target\s-o-d-1.0.0.ap_]
[ERROR] Cannot add source folder
com.android.sdklib.build.DuplicateFileException: Duplicate files at the same path inside the APK
    at com.android.sdklib.build.ApkBuilder.doAddFile(ApkBuilder.java:716)
    at com.android.sdklib.build.ApkBuilder.processFileForResource(ApkBuilder.java:762)
    at com.android.sdklib.build.ApkBuilder.addSourceFolder(ApkBuilder.java:587)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.jayway.maven.plugins.android.phase09package.ApkBuilder.addSourceFolder(ApkBuilder.java:244)
    at com.jayway.maven.plugins.android.phase09package.ApkMojo.doAPKWithAPKBuilder(ApkMojo.java:341)
    at com.jayway.maven.plugins.android.phase09package.ApkMojo.createApkFile(ApkMojo.java:249)
    at com.jayway.maven.plugins.android.phase09package.ApkMojo.execute(ApkMojo.java:207)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

After long while of trying, I was able to understand that the duplicates referred to, are the duplicate files in the output directories, one of the Android android-classes folder, and maven output classes folder.

So before I even go on about it, I've tried to find out (but I was unable to find an answer) does the Android Maven plugin, support the importing of pure Java jars?

Ho, yes, VERY IMPORTANT, do clean install, and not only install!!!

Thanks in advance,

Adam Zehavi.

By : TacB0sS


Answers

The link from Ricardo is good.

Adding

By : William




Well, it took me about forever to fully understand this error to work around it, and also to enable debugging from Eclipse shortcut.

So without any guarantees here is a general solution, which so far works for me very nicely, and I didn't encounter any problems so far:

I have a parent pom:

By : TacB0sS


This video can help you solving your question :)
By: admin