Maven + Eclipse + Android 环境搭建
来源:互联网 发布:北风网大数据全套视频 编辑:程序博客网 时间:2024/06/05 15:23
1.Essentials Tools:必备工具
1.1 Android Development Tool(ADT)以及Android SDK。
这个是必须的,不用赘述。
1.2 Android Development Tools and the M2Eclipse
这个是Eclipse的插件,充当的角色是ADT及m2e之间的桥梁,由于Android项目的特性,Maven所做的操作在Android的项目上并不适用,所以这个插件相当于两个插件之间的适配器,使得m2e的插件作出的变更及其通知能够以ADT所能接受的方式通知ADT对Android的项目作出响应的变更。
进入Eclipse Marketplace.搜索android m2e ,然后点击Installer按钮即可。
本项目的Github托管地址为:
https://github.com/rgladwell/m2e-android
注意,目前该项目支持Eclipse indigo,juno,kepler三个版本。
1.3 Android Connector
这个是在Preferences->Maven->Discovery中选择Android Connector下载。
1.4 Maven-android-sdk-deployer
该项目的github托管地址为:https://github.com/mosabua/maven-android-sdk-deployer
该项目的主要作用是使得Maven Android插件能够使用Android SDK作为Dependence。
(1)Android SDK中下载部署所有你需要的platforms与add-ones.
(2)下载Github 上工程文件。
(3)使用命令行进入到工程目录下,使用mvn install安装依赖项。
(4)如果需要安装特定级别的SDK,使用如下:
- mvn install -P 1.5
- mvn install -P 1.6
- mvn install -P 2.1
- mvn install -P 2.2
- mvn install -P 2.3.3
- mvn install -P 3.0
- mvn install -P 3.1
- mvn install -P 3.2
- mvn install -P 4.0
- mvn install -P 4.0.3
- mvn install -P 4.1
- mvn install -P 4.2
- mvn install -P 4.3
- mvn install -P 4.4
如果有如下错误,说明你的SDK中可能确实相应的platforms。
2 配置
安装好m2e之后,需要选择你本地的Maven的安装路径。
在你的settings文件中也可以添加如下内容:
<span style="font-family:Microsoft YaHei;"><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>android</id>
<properties>
<android.sdk.path>
E:\dev_tool\android-sdks(android-SDK home路径)
</android.sdk.path>
</properties>
</profile>
</profiles>
<activeProfiles> <!--make the profile active all the time -->
<activeProfile>android</activeProfile>
</activeProfiles>
</settings></span>
3 工程
如果你已经有了一个安卓的工程,可以直接右击->Configure->Convert to Maven Project转换为Maven项目,其中pom文件的packaging类型需要更改为apk.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.cst.ming.android.sample</groupId>
<artifactId>sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
如果要新建一个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
注意,这里的de.akquinet.android.archetypes模板的version经常会改变,可以前往Maven的Central仓库搜索查看相应版本。
Either way you should
在编译的时候,最好在pom文件中声明一个build插件:
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.0.0</version>
<inherited>true</inherited>
<extensions>true</extensions>
<configuration>
<sdk>
<platform>7</platform>
<path>${env.ANDROID_SDK_HOME}</path>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
</plugin>
4 常见问题
(1)No Android SDK path could be found.
在settings.xml里面添加:
<profiles>
<profile>
<id>android</id>
<properties>
<android.sdk.path>
/Users/lily/android-sdk-macosx <!-- 此处为自己sdk路径 -->
</android.sdk.path>
</properties>
</profile>
</profiles>
<activeProfiles> <!--make the profile active all the time -->
<activeProfile>android</activeProfile>
</activeProfiles>
或者在系统变量中创建ANDROID_HOME变量,或者直接在pom.xml中指定android. sdk.path。
(2)[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:generate-sources(default-generate-sources) on project controltower-android: Executiondefault-generate-sources of goalcom.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:generate-sourcesfailed:
以及
Project Build Error:unknown packaging:apk
这是因为没有安装m2e android connector,可以按照如下步骤。
Preferences -> Maven -> Discovery and click "Open Catalog".然后选择 m2e android connector 安装好以后就可以解决这个问题。
(3)@Override 的代码全部都报错
默认Maven中的JAVA版本是1.5,只要修改成1.6就好了
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
(4)No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?这个错误即是找不到JDK的错误,可以使用如下方案:
l 在Eclipse的ini文件中添加如下语句:
-vm
C:\Program Files\Java\jdk1.7.0_25\bin\javaw.exe
l Window ->Preferences -> Java -> Installed JREs, 点击"Add"按钮,选择默认的"Standard VM", 点击"Next >", 点击"JRE home"右边的"Directory"选择文件夹D:\Development\Java\jdk1.7.0_25\jre,一路“确定”,回到"Installed JREs"界面,在刚添加的"jdk1.7.0_25"打上勾。再选择目录树中的"Execution Environments",点选界面左侧的"J2SE-1.7",然后在右侧点选"jdk1.7.0_25"。重启Eclipse,一切OK了。或者edit已经存在的jre,然后点击Add Extends JARS按键,添加jdk\lib\tools.jar文件,同样可以解决。
(5)导入工程后,pom.xml文件中,以下插件报错
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<sdk>
<!-- platform or api level (api level 4 = platform 1.6)-->
<platform>18</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
提示:
Plugin execution not covered by lifecycle configuration:
com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.0:consume-aar (execution:
default-consume-aar, phase: compile)
解决:
打开 'Problems'视图: 'Window' -> 'Show View' -> 'Problems'
右键点击报错的地方,选择'Quick Fix'
点击选择'Permanently mark goal generate in pom.xml as ignored in Eclipse build' -> 'Finish' -> 'OK'
修改完后,右键项目—> Maven —> Update Project
(6)dependency=[com.actionbarsherlock:library:apklib:4.1.0:compile] not found in
workspace com.actionbarsherlock.library 换了artifactId了,是actionbarsherlock,并且使用4.4.0的版本..Plugin execution not covered by lifecycle configuration:
5 常用命令
Goal
Description
android:aar
Creates an Android Archive (aar) file.
android:apk
Creates the apk file. By default signs it with debug keystore.
Change that by setting configuration parameter <sign><debug>false</debug></sign>.
android:apklib
Creates the apklib file.
apklib files do not generate deployable artifacts.
android:clean
No description.
android:deploy
Deploys the apk(s) of the current project(s) to all attached devices and emulators. Automatically skips other projects in a multi-module build that do not use packaging apk without terminating.
Deploymnet is automatically performed when running mvn integration-test (or mvn install) on a project with instrumentation tests.
android:deploy-apk
Deploys a specified Android application apk to attached devices and emulators. By default it will deploy to all, but a subset or single one can be configured with the device and devices parameters.This goal can be used in non-android projects and as standalone execution on the command line.
android:deploy-dependencies
Deploys all directly declared dependencies of <type>apk</type> in this project's pom.
Usually used in a project with instrumentation tests, to deploy the apk to test onto the device before running the deploying and running the instrumentation tests apk.
Automatically performed when running mvn integration-test (or mvn install) on a project with instrumentation tests.
android:devices
DevicesMojo lists all attached devices and emulators found with the android debug bridge. It uses the same naming convention for the emulator as used in other places in the Android Maven Plugin and adds the status of the device in the list. TODO The goal is very simple and could be enhanced for better display, a verbose option to display and to take the android.device paramter into account.
android:dex
Converts compiled Java classes to the Android dex format.
android:emma
After compiled Java classes use emma tool
android:emulator-start
EmulatorStartMojo can start the Android Emulator with a specified Android Virtual Device (avd).
android:emulator-stop
EmulatorStartMojo can stop the Android Emulator with a specified Android Virtual Device (avd).
android:emulator-stop-all
EmulatorStopeAllMojo will stop all attached devices.
android:generate-sources
Generates R.java based on resources specified by the resources configuration parameter. Generates java files based on aidl files.
android:help
Display help information on android-maven-plugin.
Call
mvn android:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
android:instrument
Runs the instrumentation apk on device.
android:internal-integration-test
Internal. Do not use.
Called automatically when the lifecycle reaches phase integration-test. Figures out whether to call goals in this phase; and if so, calls android:instrument.
android:internal-pre-integration-test
Internal. Do not use.
Called automatically when the lifecycle reaches phase pre-integration-test. Figures out whether to call goals in this phase; and if so, calls android:deploy-dependencies and android:deploy.
android:lint
LintMojo can run the lint command against the project. Implements parsing parameters from pom or command line arguments and sets useful defaults as well. Warning, if you use android.lint.enableClasspath and/or android.lint.enableLibraries the behavior of this goal will vary depending on the phase where this goal is executed. See android.lint.classpath/lintClassPath and android.lint.libraries/lintLibraries for more details.
android:manifest-update
Updates various version attributes present in the AndroidManifest.xml file.
android:monkey
Can execute tests using UI/Application Exerciser Monkey.
Implements parsing parameters from pom or command line arguments and sets useful defaults as well. This goal will invoke Android Monkey exerciser. If the application crashes during the exercise, this goal can fail the build.
A typical usage of this goal can be found at Quality tools for Android project.
android:monkeyrunner
Can execute monkey runner programs.
Implements parsing parameters from pom or command line arguments and sets useful defaults as well. This goal will invoke monkey runner scripts. If the application crashes during the exercise, this goal can fail the build.
A typical usage of this goal can be found at Quality tools for Android project.
android:ndk-build
No description.
android:proguard
Processes both application and dependency classes using the ProGuard byte code obfuscator, minimzer, and optimizer. For more information, see https://proguard.sourceforge.net.
android:pull
Copy file or directory from all the attached (or specified) devices/emulators.
android:push
Copy file to all the attached (or specified) devices/emulators.
android:redeploy
Undeploys and the deploys (= redeploys) the apk(s) of the current project(s) to all attached devices and emulators. Automatically skips other projects in a multi-module build that do not use packaging apk without terminating.
android:redeploy-apk
Reploys a specified Android application apk to attached devices and emulators. By default it will deploy to all, but a asubset or single one can be configured with the device and devices parameters. This simply tries to undeploy the APK first and then deploy it again. This goal can be used in non-android projects and as standalone execution on the command line.
android:run
Runs the first Activity shown in the top-level launcher as determined by its Intent filters.
Android provides a component-based architecture, which means that there is no "main" function which serves as an entry point to the APK. There's an homogeneous collection of Activity(es), Service(s), Receiver(s), etc.
The Android top-level launcher (whose purpose is to allow users to launch other applications) uses the Intent resolution mechanism to determine which Activity(es) to show to the end user. Such activities are identified by at least:
1 Action type: android.intent.action.MAIN
2 Category: android.intent.category.LAUNCHER
And are declared in AndroidManifest.xml as such:
<activity android:name=".ExampleActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This Mojo will try to to launch the first activity of this kind found in AndroidManifest.xml. In case multiple activities satisfy the requirements listed above only the first declared one is run. In case there are no "Launcher activities" declared in the manifest or no activities declared at all, this goal aborts throwing an error.
The device parameter is taken into consideration so potentially the Activity found is started on all attached devices. The application will NOT be deployed and running will silently fail if the application is not deployed.
android:uiautomator
Can execute tests using ui uiautomator.
Implements parsing parameters from pom or command line arguments and sets useful defaults as well. This goal is meant to execute a special java project dedicated to UI testing via UIAutomator. It will build the jar of the project, dex it and send it to dalvik cache of a rooted device or to an emulator. If you use a rooted device, refer to this thread on stack over flow.
The tests are executed via ui automator. A surefire compatible test report can be generated and its location will be logged during build.
To use this goal, you will need to place the uiautomator.jar file (part of the Android SDK >= 16) on a nexus repository.
A typical usage of this goal can be found at Quality tools for Android project.
android:undeploy
Undeploys the apk(s) of the current project(s) to all attached devices and emulators. Automatically skips other projects in a multi-module build that do not use packaging apk without terminating.
Deploymnet is automatically performed when running mvn integration-test (or mvn install) on a project with instrumentation tests.
android:undeploy-apk
Undeploys a specified Android application apk from attached devices and emulators. By default it will undeploy from all, but a subset or single one can be configured with the device and devices parameters. You can supply the package of the application and/or an apk file. This goal can be used in non-android projects and as standalone execution on the command line.
android:unpack
Unpack libraries code and dependencies into target. This can be useful for using the proguard maven plugin to provide the input jars. Although it is encouraged to use the proguard mojo of the android maven plugin.
android:zipalign
ZipalignMojo can run the zipalign command against the apk. Implements parsing parameters from pom or command line arguments and sets useful defaults as well.
- Maven + Eclipse + Android 环境搭建
- Maven + Eclipse + Android 环境搭建
- Android+Eclipse+Maven环境搭建
- Maven + Eclipse + Android 环境搭建
- Maven + Eclipse + Android 环境搭建
- android+eclipse+maven环境搭建
- Eclipse 下android +maven 环境搭建
- android + maven + eclipse 环境搭建(windows) 二
- eclipse搭建Maven环境
- maven eclipse环境搭建
- Eclipse Maven环境搭建
- Eclipse搭建Maven环境
- Eclipse+maven开发环境搭建
- eclipse环境搭建maven项目
- eclipse+Maven开发环境搭建
- Eclipse+maven开发环境搭建
- 如何搭建Eclipse+Maven环境
- eclipse maven mahout环境搭建
- netbeans 搭建php debug环境
- 深度解析什么是ARC
- 在CentOS 6.4上安装vsftpd
- 前端优化的一些点
- jar包静态依赖解析
- Maven + Eclipse + Android 环境搭建
- Android - FEATURE_NO_TITLE
- 浅谈操作系统对内存的管理
- hive客户端升级及添加hadoop超级权限
- 树莓派自动登录并自动运行软件
- Java笔记六.线程同步、线程死锁
- VELT-0.1.3开发: 生成事件
- spark读取 kafka nginx网站日志消息 并写入HDFS中
- 触发器