Android and maven: problem with maven dependencies in apk

By : Anzeo

I'm currently working on an Android project using Maven as the build tool. However I'm having a problem with including dependencies, to be more specific: none of the dependencies listed in my pom file are packed in the apk. This results in ClassDefNotFound errors when I'm trying to run the app on my emulator (the underlying ClassNotFound exception is thrown in the Dalvik loader).

I'm using Springsource Tool Suite ( 2.5.2.SR1), with the following plugin configuration:

  • Android Development Tools (10.0.1.v201103111512-110841)
  • Maven integration for Android Development Tools (0.2.5)
  • Maven integration for Eclipse (
  • Maven (2.2.1)

This is my pom file

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">

        <android-sdk-path>C:\Program Files\Android\android-sdk</android-sdk-path>


            <!-- Using Jackson for JSON marshaling -->

        <!-- For testing against latest Spring snapshots -->
            <name>Spring Maven Snapshot Repository</name>
        <!-- For developing against latest Spring milestones -->
            <name>Spring Maven Milestone Repository</name>


And my android manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-sdk android:minSdkVersion="10" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MainActivity"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />


As far as I can tell, this should be a correct setup. The problem now is, when I try to build this project, I get:

Cannot add source folder Duplicate files at the same path inside the APK

I found this on SO and while the solution (changing the default output folder of eclipse to bin instead of target) did solve the error, it didn't solve the dependency problem. My generated android files aren't included in the target folder so the solution is of no use to me.

Has anyone else got any experience with setting up Android and Maven and if so, could you please help me out?

Many thanks in advance!

By : Anzeo


I skipped using the Maven integration for Android Development Tools (0.2.5) because the eclipse automatically build process took to long. I could leave my default output folder to <project>/target/classes in this case.

Building my project from the command line works fine. The dependencies are included in the apk file.

Running the project from eclipse only works if I add the dependencies explicit to the eclipse project with

Project Properties -> Java Build Path -> Libraries -> Add External JARs...

That was the bitter pill I had to swallow (I am not native english and hope this sentence makes sence).

By : FrVaBe

Use <scope>compile</scope> for your dependencies wich are not provided by the target system (e.g. the android libs are provided on android systems) otherwise maven will not put the .class files from your dependencies into the apk.

By : Sneek

you can use <extractDuplicates>true</extractDuplicates\> in android-maven-plugin configuration to remove duplicate jars.

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