Android : How to set up Maven in an Android Project under Eclipse

on Saturday, October 11, 2014


Basically I have been fiddling around to get an existing android project to work with maven under eclipse luna.


So here is the way the project was set up to begin with.


The project is a simple android project, which references two external .jars (those are in the libs folder and referenced via add external jars) and then also three additional selfmade libraries which are simple android project but set up to be libraries (via the Is Library checkbox in the Android project properties).


So like this:


Workspace



  • MainProject -> Android Project

    • libs

      • lib1.jar -> referenced in the build path via the add external jars

      • lib2.jar -> referenced in the build path via the add external jars





  • SelfMadeLib1 -> Android Project -> set up to be a library and is also referenced in the MainProject via the Add which is available in the Android part of the project properties

  • SelfMadeLib2 -> Android Project -> set up to be a library and is also referenced in the MainProject via the Add which is available in the Android part of the project properties

  • SelfMadeLib3 -> Android Project -> set up to be a library and is also referenced in the MainProject via the Add which is available in the Android part of the project properties


Well this was the way I always did it, but since there is maven I figured I could get around this and use maven. So I went a head and removed the self made libs, created a new workspace specifically for them.


Then I added the projects via Import... -> Existing Android Code into Workspace. After that I simply used the Maven Android plugin to convert them via Configure -> Convert To Maven Project. After fixing the referenced Java SDK (set it up to use the old 1.6_45 on my system) I could create the projects via maven and install them in my repo, so no problem there.


Next thing was to configure the existing MainProject, but this did not work. I was able to convert the project into a maven project as well (same way as above with the selfmade libs) and also add the selfmade libs via maven. They are also shown in the Maven Dependencies and I also checked that those dependencies should be included in the project (via Order and Export tab in the Java Build Path of the project properties)


However when I try to debug the whole thing it does not work because of a ClassNotFoundException which gets thrown as soon as I start the app.


So next thing I did was simply to reused the original android project and add the libs the old way (via add external jars) and this works ofc. After analysing the project I simply figured that the maven project does not have the libs because they are not shown under Android Private Libraries in the Java Build Path of the project properties.


So my question is, was anybody able to get android project to work with maven and if so how ?


0 comments:

Post a Comment