Android and maven: maven dependency issue in apk

I am currently working on an Android project using Maven as a build tool. However, I have a problem with enabling dependencies to be more specific: none of the dependencies listed in my pom file are packaged in apk. This leads to ClassDefNotFound errors when trying to run the application on my emulator (the basic ClassNotFound exception is thrown in the Dalvik bootloader).

I am using the 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 (12/01/20110112-1712)
  • Maven (2.2.1)

This is my pom file

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>android-test</groupId> <artifactId>android-test</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>apk</packaging> <name>android-test</name> <properties> <android-platform>10</android-platform> <android-emulator>Android-2.3.3</android-emulator> <android-sdk-path>C:\Program Files\Android\android-sdk</android-sdk-path> <maven-android-plugin-version>2.8.4</maven-android-plugin-version> <maven-compiler-plugin-version>2.3.2</maven-compiler-plugin-version> <android-version>2.3.1</android-version> <spring-android-version>1.0.0.M2</spring-android-version> <jackson-version>1.7.2</jackson-version> </properties> <build> <sourceDirectory>src</sourceDirectory> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>maven-android-plugin</artifactId> <version>${maven-android-plugin-version}</version> <configuration> <sdk> <platform>${android-platform}</platform> <path>${android-sdk-path}</path> </sdk> <emulator> <avd>${android-emulator}</avd> </emulator> <deleteConflictingFiles>false</deleteConflictingFiles> <undeployBeforeDeploy>true</undeployBeforeDeploy> </configuration> <extensions>true</extensions> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>${maven-compiler-plugin-version}</version> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>${android-version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.android</groupId> <artifactId>spring-android-rest-template</artifactId> <version>${spring-android-version}</version> </dependency> <dependency> <!-- Using Jackson for JSON marshaling --> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-mapper-asl</artifactId> <version>${jackson-version}</version> </dependency> </dependencies> <repositories> <!-- For testing against latest Spring snapshots --> <repository> <id>org.springframework.maven.snapshot</id> <name>Spring Maven Snapshot Repository</name> <url>http://maven.springframework.org/snapshot</url> <releases><enabled>false</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> <!-- For developing against latest Spring milestones --> <repository> <id>org.springframework.maven.milestone</id> <name>Spring Maven Milestone Repository</name> <url>http://maven.springframework.org/milestone</url> <snapshots><enabled>false</enabled></snapshots> </repository> </repositories> </project> 

And my Android manifest file:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="ae.test.android" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="10" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

As far as I can tell, this should be the right setup. The problem is that when I try to build this project, I get:

Unable to add source folder Duplicate files on same path inside APK

I found this on SO, and although the solution (changing the default output folder for eclipse to bin instead of target ) really fixed the error, this does not solve the dependency problem. My created android files are not included in the target folder, so the solution does not suit me.

Does anyone else have experience setting up Android and Maven, and if so, could you help me?

Thank you very much in advance!

+4
source share
3 answers

I skipped using Maven integration for Android Development Tools (0.2.5) because the eclipse auto-build process took a long time. In this case, I can leave my default output folder <project>/target/classes .

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

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

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

It was a bitter pill that I had to learn (I am not native English and I hope this sentence makes sense).

+3
source

Use <scope>compile</scope> for your dependencies that are not provided by the target system (e.g. Android files on the Android system), otherwise maven will not put the .class files from your dependencies in apk.

+3
source

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

+3
source

Source: https://habr.com/ru/post/1345446/


All Articles