I want to work with Maven dependencies in an IntelliJ Android project. Has anybody successfully done this?
I use IntelliJ IDEA (currently v11.0.2, build 111.277) on both Ubuntu 11.10 and Mac OS X 10.7.3 for working on Maven-based Android projects, and for the most part it works well. A nice thing about using IntelliJ with Android and Maven is that all support is already built-in - there are no extra IDE plugins to install.
As an example of a good working Android Maven project that can be opened with IntelliJ, you could use the source code of the open-source Gaug.es for Android app by GitHub (not all developers at GitHub use IntelliJ, personally I do - Eclipse is also used to work on this project).
The first step for smooth running is obviously to ensure that your project builds correctly using only plain Maven at the command line - although the question doesn't directly ask about this, I'd advise these pre-requisites as a bare minimum:
If you can mvn install
the parent pom of your project, you're good to move on to actually working with it with IntelliJ.
Project Structure
, Platform Settings
, SDKs
and then edit the Java SDK if it's showing as red, giving it the path of your Java 6 SDK.Project Structure
dialog window, set the Project SDK
to the appropriate Android version, and under Project
set the Project compiler output
to whatever directory name you like - this value is required for doing a 'Make', but also overridden to by your submodules to sensiibly point to the Maven 'target' directories.Maven Projects
tab. Hit the Reimport All Maven Projects
button (looks like two arrows chasing each other). If IntelliJ prompts you to enable Auto-Import, go for it. You should now have at least one module listed under the Maven Projects
tab, more if you have an integration test project as well.At this point, you should have a fairly meaningful IDE experience. Stuff that should work:
Force regenerate R.java file
should correctly refresh the file under target/generated-sources/r/...
- but this only seems to work if target/generated-sources/r
is already set as a source path, ie has been generated by Maven, and imported by IntelliJ. The minimal command line alternative is to execute mvn android:generate-sources
from the command line in the folder of the affected module.package
or install
at the command line.Stuff that might not work:
ClassNotFoundException: junit.textui.ResultPrinter
)If IntelliJ gets confused, the following steps will normally get you back on track:
mvn clean install
on the command lineReimport All Maven Projects
buttonSome advice:
Hope that helps!