Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate classes R & BuildConfig after "Reimport All Maven Projects"

We are building our Android projects with Maven and IntelliJ IDEA. Sometimes we must execute "Reimport All Maven Projects", e.g. to update dependencies. The problem with that is that it always messes up the source folders for resources: all modules get "gen" and "target/generated-source/r" which seems to be the cause for the duplicates. So after reimporting, we need to manually delete one of those (usually the "gen" folder). Of course, we want to avoid this step. We tried several settings for the Android facet, but no luck so far.

So, how can we configure IntelliJ to do a proper Maven reimport that just works?

like image 560
Markus Junginger Avatar asked Jul 18 '13 14:07

Markus Junginger


2 Answers

According to the reply of Sven Strohschein at http://youtrack.jetbrains.com/issue/IDEA-94901 you can try to:

  1. Delete the "gen", "target" and "out" folders
  2. Revert the changes within the "ipr" and "iml" files (or just delete them all, maybe even .idea folder)
  3. Start IntelliJ 12
  4. Open the pom file
  5. Right click -> "Maven" -> "Reimport"
  6. "Build" -> "Rebuild project"

Works fo me.

like image 154
alex.dorokhov Avatar answered Oct 01 '22 03:10

alex.dorokhov


After IDEA detects and adds Android facet to module, it would start generating gen folder at usual place, but maven-android-plugin generates its own under target directory.

You need to tell IDEA to place generated files at same place where maven-android-plugin creates them.

First, use module's android facet settings and check the option to use Maven goal instead of generating by itself:

enter image description here

Then, go to module's settings and set output path same as Maven's, which is target directory:

enter image description here

Delete gen directories, Do mvn clean to clear all unnecessary files.

like image 26
S.D. Avatar answered Oct 01 '22 04:10

S.D.