简体   繁体   English

如何在eclipse中构建Maven Android项目

[英]How to build a Maven Android project in eclipse

I am testing the code here : https://github.com/nkzawa/socket.io-client.java . 我在这里测试代码: https//github.com/nkzawa/socket.io-client.java Under features there is this sweet sounding line : "Android is fully supported". 在功能下有一个甜美的声音线:“完全支持Android”。 But being completely new to maven I can make neither head nor tail of the instructions. 但对于maven而言,我完全不是新手,我既不会做出指示的头部也不能指示尾部。 How do I build a basic Android test project with this code? 如何使用此代码构建基本的Android测试项目? Simply adding the source code from the repo to my project is showing lot of errors. 只需将repo中的源代码添加到我的项目中就会显示很多错误。 If there is a command line way of doing this that would be fine too. 如果有一个命令行方式这样做也没关系。

The Android for Maven Eclipse connector is an Maven Eclipse (m2e) plug-in that adds maven support for Android Developer Tools (ADT) and the Maven Android Plugin. Android for Maven Eclipse连接器是一个Maven Eclipse(m2e)插件,它为Android Developer Tools(ADT)和Maven Android插件添加了maven支持。 It brings the power of Maven dependency management into the ADT. 它将Maven依赖管理的强大功能带入了ADT。

  1. Before you start 在你开始前

    You will need Eclipse Indigo or Juno installed. 您需要安装Eclipse Indigo或Juno。

  2. Install Android Connector 安装Android连接器

    • You can install the Android Connector for Maven via the Eclipse Marketplace. 您可以通过Eclipse Marketplace安装Android Connector for Maven。 Select Help -> Eclipse Marketplace... and search for "android m2e". 选择Help - > Eclipse Marketplace ...并搜索“android m2e”。

    • Click the Install button next to the Android Connector for Maven that appears and follow the path through the wizard dialog to install the plug-in and its dependencies (including the Android Development Toolkit and the Maven for Eclipse m2e plug-in). 单击出现的Android Connector for Maven旁边的Install按钮,然后按照向导对话框中的路径安装插件及其依赖项(包括Android Development Toolkit和Maven for Eclipse m2e插件)。 Accept the terms-and-conditions and click Finish. 接受条款和条件,然后单击“完成”。

    • Once you restart your Eclipse workspace you should be ready to start using the Android Connector. 重新启动Eclipse工作区后,您应该已准备好开始使用Android Connector。

  3. Create Eclipse project 创建Eclipse项目

    • If you already have an Android project please make sure you have created a POM for your project using version 3.0.0 or greater of the maven-android-plugin. 如果您已有Android项目,请确保使用版本3.0.0或更高版本的maven-android-plugin为您的项目创建了一个POM。

    • Then right-click on your project and select Configure -> Convert to Maven Project. 然后右键单击您的项目并选择Configure - > Convert to Maven Project。


If you are starting with a new project you can use the Maven Android archetypes to create Android projects completely within Eclipse: 如果您从一个新项目开始,您可以使用Maven Android原型在Eclipse中完全创建Android项目:

1. Create a new Maven Project (File -> New -> Project... then select Maven -> Maven Project).
2. When prompted to Select Archetype click Add Archetype...
3. In the dialog that appears enter "de.akquinet.android.archetypes" for Archetype Group Id.
4. In Archetype Artifact Id enter "android-quickstart".
5. In Archetype Version enter "1.0.10" and continue.
6. When prompted enter your desired project group and artifact ID, version and, optionally, set the "platform" property for the Android version (defaults to '16').
7. Click Finish

Either way you should end up with an Eclipse project looking something like this: 无论哪种方式,您最终都应该看到类似这样的Eclipse项目:

在此输入图像描述

Steps to build a Maven Android project in eclipse 在eclipse中构建Maven Android项目的步骤

  1. Install m2e(mavel plugin) to your ecplise. 将m2e(mavel插件)安装到你的ecplise。
  2. Right click Create Maven project 右键单击“创建Maven项目”
  3. Click next and in Catalog select Android 单击下一步,然后在目录中选择Android
  4. Give group id com.example and Artifact id Project name 给group id com.example和Artifact id Project name
  5. click finish. 点击完成。

Typically you do this by importing an "Existing Maven Project". 通常,您可以通过导入“现有Maven项目”来执行此操作。 You get this option in the Import dialog when you have installed m2e. 安装m2e后,您可以在“导入”对话框中获得此选项。 For Android you will additionally need the Android Connector before doing the import. 对于Android,在进行导入之前,您还需要安装Android连接器。 Here it gets nasty. 这里很讨厌。 You can install the connector from Window -> Preferences -> Maven -> Discovery -> Open Catalog . 您可以从Window - > Preferences - > Maven - > Discovery - > Open Catalog安装连接器。

To be honest I had no luck with this connector yet. 说实话,我还没有运气这个连接器。 So the second option is (you don't even need m2e here): 所以第二种选择是(你甚至不需要m2e):

  • Install Maven 安装Maven
  • Open the command line and navigate to your downloaded sources where the pom.xml is located 打开命令行并导航到pom.xml所在的已下载源
  • run mvn eclipse:eclipse to create eclipse project files 运行mvn eclipse:eclipse创建eclipse项目文件
  • Import it as "Existing Project into Workspace" in the import dialog. 在导入对话框中将其作为“现有项目导入工作区”导入。
  1. install m2e plug-in your eclipse. 安装m2e插件你的日食。
  2. install android m2e plug-in. 安装android m2e插件。
  3. create new maven project. 创建新的maven项目。
  4. select archtype:android-quickstart by typing android in filter. 通过在filter中键入android来选择archtype:android-quickstart。
  5. finish you will get maven android project. 完成后你将获得maven android项目。 and add this plugin in pom 并在pom中添加此插件

    org.eclipse.m2e lifecycle-mapping 1.0.0 com.jayway.maven.plugins.android.generation2 android-maven-plugin [3.8.2,) consume-aar org.eclipse.m2e生命周期映射1.0.0 com.jayway.maven.plugins.android.generation2 android-maven-plugin [3.8.2,)consume-aar

  6. finally update the project by rightclicking on project->maven->update project. 最后通过右键单击project-> maven-> update project来更新项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM