Maven builds on Android project using a library project causing duplicate R class errors

1.3k Views Asked by At

I have an Android project that depends on an android library (apklib) project. The projects builds fine within Eclipse but my command line build using maven fails complaining of duplicate R class (the R class from my android library project).

Inside my target folder I have three subdirectories.

  1. classes : the compiled class files (as usual).
  2. generated-sources: the generated R.java for both the main project and the library project.
  3. unpack : the contents of my library project including the manifest, the resource xml files and the generated R.java file.

Is the presence and contents of the 'unpack' folder to be expected? The R.java file within it is causing the duplicate R class build failure.

2

There are 2 best solutions below

1
On BEST ANSWER

I would suggest to use the latest version of the Android Maven Plugin (3.0.0) and look how the samples for apklib usage are set up. That will solve your problem.

1
On

I had setup the library project's pom.xml incorrectly. I was explicitly including the generated java files under build/resources (artifact of having copied the pom.xml file from another project). Removing that eliminated the duplicate R.java file in the unpack directory. The unpack directory does exist and matches the structure posted in the question.

BTW, the libraryprojects sample failed if I ran 'mvn compile', but works fine for 'mvn install'. I am a maven n00b, so this may be reasonable.