是否有可能安装的IntelliJ Android项目使用Maven的工作? [英] Is it possible to setup IntelliJ Android project to work with maven?

查看:134
本文介绍了是否有可能安装的IntelliJ Android项目使用Maven的工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用的IntelliJ Android项目Maven的依赖关系的工作。有没有人成功地使用的IntelliJ上工作,使用Maven的一个Android项目?

I want to work with maven dependencies in IntelliJ Android project. Has anybody successfully used IntelliJ to work on an Android project that uses maven?

推荐答案

我用的IntelliJ IDEA(目前v11.0.2,打造111.277)双方的Ubuntu 11.10和Mac OS X 10.7.3的工作基于Maven的Andr​​oid项目,和在大多数情况下效果很好。有关使用的IntelliJ与Android和Maven一个好处是,所有的支持已经内置了 - 没有多余的IDE插件安装

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.

作为可以打开的IntelliJ一个良好的工作的Andr​​oid Maven项目的例子,您可以使用开放源代码的 Gaug.es为Android 应用程序通过GitHub的(不是所有的开发商在GitHub上使用的IntelliJ,我个人 - Eclipse也是用来工作在这个项目上)。

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).

有关平稳运行的第一步显然是要确保您的项目建立正确只用普通的Maven在命令行 - 尽管这个问题不直接问这个,我建议这些pre必备的最低限度:

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:

  • 在Java 6中
  • 的Maven v3.0.3
  • Android的Maven的插件 V3.1.1
  • 在Android的SDK R16(如果你R15之前下载了SDK,你可能会更好过的摧毁了整个事情,重新下载这一切,作为目录布局发生了变化)
  • Java 6
  • Maven v3.0.3
  • android-maven-plugin v3.1.1
  • Android SDK r16 (if you downloaded your SDK before r15, you're probably better off nuking the entire thing and downloading it all again, as the directory layout has changed)

如果你能 MVN安装项目的父POM,你就可以进入到实际工作与它的IntelliJ。

If you can mvn install the parent pom of your project, you're good to move on to actually working with it with IntelliJ.

  • 如果这是第一次用的IntelliJ开盘项目,你仍然可以打开它作为一个项目,你只需要选择打开项目对话框中的父pom.xml文件。
  • 确认的IntelliJ知道在哪里了Java SDK是。的IntelliJ,即使它在Java的运行,不自动检测SDK的位置。你要告诉它。进入项目结构平台设置软件开发工具包,然后编辑Java SDK的,如果它显示为红色,给它你的Java 6 SDK的路径。
  • 在同一项目结构对话窗口,将项目SDK 到适当的Andr​​oid版本,并在项目设置项目编译器输出到任何目录下你喜欢的名字 - 需要做一个'请'这个值,但还覆盖到您的子模块sensiibly指向Mav​​en的目标目录。
  • 双击检查所有的Maven的信息已经被解析的IntelliJ。你应该有一个 Maven项目设置页。按重新导入所有的Maven项目按钮(看起来像两个箭头互相追逐)。如果的IntelliJ提示您启用自动导入,去了。你现在应该已经上市了 Maven项目标签下至少一个模块,更多,如果你有一个集成测试的项目也是如此。
  • If this is the first time opening the project with IntelliJ, you can still open it as a project, you just need to select the parent pom.xml file in the 'Open Project' dialog.
  • Ensure IntelliJ knows where the Java SDK is. IntelliJ, even though it's running on Java, doesn't auto-detect the location of the SDKs. You have to tell it. Go 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.
  • In the same 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.
  • Double-check that all the Maven information has been parsed by IntelliJ. You should have a 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.

在这一点上,你应该有一个相当有意义的IDE体验。东西应该工作:

At this point, you should have a fairly meaningful IDE experience. Stuff that should work:

  • 在不应该有code红色下划线标注为没有显而易见的原因。
  • 在所有进口的(无论是从Android SDK中,Java的,你自己的code或apklibs)应该得到承认。需要注意的是apklib支持只能排在晚期的IntelliJ IDEA V10.5。
  • 重构操作。
  • 强制再生R.java文件应正确地刷新下目标/生成,源/ R /... - 但这似乎只当目标/生成,源/ R 已设置为源路径,即已经被Maven的产生,并通过的IntelliJ进口工作。最小的命令行选择是执行 MVN机器人:产生-源从受影响模块的文件夹中的命令行
  • 在IDE中做项目的'制作'技术的工作原理,但同样可能会失败出于同样的原因。我引用我所有的构建使用MVN 安装在命令行。
  • There should be no code underlined in red for no readily apparent reason.
  • All imports (whether from the Android SDK, Java, your own code or from apklibs) should be recognised. Note that apklib support only came in with late IntelliJ IDEA v10.5.
  • Refactor operations.
  • 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.
  • Doing a 'Make' of the project within the IDE technically works, but again might fail for the same reason. I invoke all my builds using the mvn package or install at the command line.

东西,可能无法正常工作:

Stuff that might not work:

  • 从IDE中运行单独的集成测试(死亡与 ClassNotFoundException的:junit.textui.ResultPrinter

如果的IntelliJ会很困惑,下面的步骤通常会得到你回到正轨:

If IntelliJ gets confused, the following steps will normally get you back on track:

  • MVN全新安装在命令行
  • 重新导入所有的Maven项目按钮
  • mvn clean install on the command line
  • Hit the Reimport All Maven Projects button

一些建议:

  • 您的Maven的pom.xml文件应该是真理的来源,为您的项目配置。尽量减少你的项目做的IntelliJ的具体配置设置 - 它的一些将被处下一次从Maven的POM设置重新导入得到一扫而光 - 并尽量避免犯的IntelliJ项目文件到源代码控制

希望帮助!

这篇关于是否有可能安装的IntelliJ Android项目使用Maven的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆