Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change output folder for Android R.java in Eclipse when using Maven

I have an android project setup using the maven-android plugin. This plugin adheres to maven output folders for the location of the R.java file (i.e. target/generated-sources/r).

However, when using this project in Eclipse, I can't configure aapt to rely on that folder.

Even if I manually go into the project properties and set up the folders manually, the ADT plugin goes in and resets just some of the settings (i.e. adds the /gen folder back as a source folder, and restores the output folder to /bin/classes instead of /target/classes), while leaving the maven /target/generated-sources/r folder and breaking the build of the project.

I would like to use the default Maven folder structure with the Eclipse ADT. Any ideas on how I can do this?

Thanks


Responding to the comments:

  • Yes, am using the m2e-android plugin.
  • Because ADT is still generating R.java in /gen, Eclipse is failing to compile if there still exists an R.java under target/generated-sources/r due to duplicated class definitions.
like image 313
Edward Q. Bridges Avatar asked Apr 10 '12 15:04

Edward Q. Bridges


2 Answers

Unfortunately, the Android Connector for M2E does not support moving generated folders like the ADT gen folder to other directories. This is a restriction of the ADT, although there is a ticket to explore a way around this restriction:

https://github.com/rgladwell/m2e-android/issues/68

If you'd like to stay updated, please comment on this ticket.

like image 80
Ricardo Gladwell Avatar answered Oct 23 '22 23:10

Ricardo Gladwell


This seems to be working for me:

Let the ADT keep gen as a source folder, but change the output folder for that source folder to be /target/classes.

I can build in both eclipse and using maven from the command line, and I don't get duplicate R class problems in either case. Essentially, Eclipse generates the R.java file in /gen, while maven generates it in /target/generated-sources/r, but both builds put the R.class file under /target/classes.

Note: at one point I had added /gen as an additional source directory in my pom.xml using build-helper-maven-plugin, and I had to remove that.

like image 27
Andy Dennie Avatar answered Oct 24 '22 00:10

Andy Dennie