Aandroid _ integrates Maven for Android Projects

Source: Internet
Author: User

Why is Maven integration required for Android projects? Here I think of several main reasons:

Deploy the separation of roles between testers and developers so that they can get rid of setting up the android SDK environment in the eclipse development environment, directly run a command on the server, and then download its APK package, install it on your mobile phone. Developers and Android Market publishers are separated from each other by their roles. Market Publishers do not know what signatures are and so on. They also need to enter a password to run commands on the server, this process is isolated from developers. If there are only two reasons, you can use the default ant script of Android. You also hope that the class libraries required by the android project will automatically solve the dependency problem, use Maven.

Let's talk about how to integrate Maven.

First, you must have an android project generated using eclipse and ADT plug-ins. See [CREF 1448].

Then, you need to set the environment variable android_home. For Windows, you need to add the environment variable. for Mac, you can ~ /. Add the following to the bash_login file:

Export android_home =/developer/Java/Android-SDK-Mac

Download Maven-Android-SDK-deployer: http://github.com/mosabua/maven-android-sdk-deployer/archives/master

Decompress the downloaded file and run the following command to go To the decompressed directory:

MVN clean install

This command will install the JAR file of Android SDK, including Google map APIs, to your local repository. This step should not be necessary. I performed it according to the official documentation. In the future, I deleted the local repository directory and continued to use the maven Android plug-in to solve Maven errors.

Create the Pom. xml file under the root directory of the existing eclipse Android project:

<? XML version = "1.0" encoding = "UTF-8"?>

<Projectxmlns = "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> com. easymorse </groupid>

<Artifactid> Hello </artifactid>

<Version> 0.1-Snapshot </version>

<Packaging> APK </packaging>

<Name> Hello </Name>

<Dependencies>

<Dependency>

<Groupid> Android </groupid>

<Artifactid> Android </artifactid>

<Version> 2.20.r1 </version>

<Scope> provided </scope>

</Dependency>

</Dependencies>

<Build>

<Sourcedirectory> SRC </sourcedirectory>

<Plugins>

<Plugin>

<Groupid>

Com. jayway. Maven. plugins. Android. generation2

</Groupid>

<Artifactid> Maven-Android-plugin </artifactid>

<Version> 2.3.3 </version>

<Configuration>

<SDK>

<Platform> 7 </platform>

</SDK>

<Deleteconflictingfiles> true </deleteconflictingfiles>

</Configuration>

<Extensions> true </extensions>

</Plugin>

<Plugin>

<Artifactid> Maven-compiler-plugin </artifactid>

<Configuration>

<Sources> 1.5 </source>

<Target> 1.5 </Target>

</Configuration>

</Plugin>

</Plugins>

</Build>

</Project>

Note that 7 in <SDK> <platform> indicates the android SDK version of the target platform, that is, 2.1. Make adjustments as needed. For example, if you use milestone, it should be 6.

To enter the MVN command below to simplify the process, you must add the following to the settings. xml file:

<Plugingroups>

<Plugingroup> com. jayway. Maven. plugins. Android. generation2 </plugingroup>

</Plugingroups>

In this way, you can use the maven command to package and deploy in the project directory:

MVN clean install Android: deploy

Or you can package:

MVN package

Here the default will use DEBUG signature packaging, if you need to release the official version in the Android Market, you can refer to: http://code.google.com/p/maven-android-plugin/issues/detail? Id = 2

Reprinted from: http://hi.baidu.com/justtmiss/item/744e2d99d0758f8c591461c5

Reference blog: http://blog.csdn.net/forever_crying/article/details/8455626

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.