Build your Android project with Maven

Source: Internet
Author: User

Software Requirements:

1.JDK 1.6+

2. Android SDk(r21.1 or up-to-date, the newer version supports the higher)

3. Maven 3.1.1+

4. Add the environment to path, create a new variable android_home, and write the installation path of your SDK, for example

ANDROID_HOME:E:\INSTALLSPACE\ANDROID\ANDROID-SDK; add%android_home%\tools and%android_home%\platform-tools to the path variable.

Detect if configuration is successful, console input Android, if Android Sdk Manager appears, the configuration is successful!

Note: Maven may appear android-maven-plugin incompatible;

Eclipse BuildInstalling the MAVEN for Android plugin

There are two ways of doing this:

    • Installing the [m2e-android][1] plugin in eclipse

Installation Source: http://rgladwell.github.com/m2e-android/updates/

Installation method: Help, install new software, in the dialog box, click Add->name:m2e-android

location:http://rgladwell.github.com/m2e-android/updates/

    • In the Eclipse menu found in the Help-eclipse marketplace click, in the popup dialog, in the Search tab page, find text box to enter "Android Configuration", to search, Click Install installation.

New MAVEN Project Project
    1. Create a new MAVEN project (File-New project ... then select Maven---maven project).

    2. In the Select archetype interface, click Add archetype ...
    3. In archetype Group Id, enter "De.akquinet.android.archetypes"
    4. Enter "Android-quickstart" in archetype Artifact Id.
    5. Enter "1.1.0" in archetype Version and next
      • Propertyies:platform:16 (default) emulator:not-specified android-plugin-version 3.8.2
    6. Finish.
Run Project

Select the project you want to run, right-run As-run configurations, double-click Maven Build

Select the project path you are running in base directory,

Goals:clean Install Android:deploy Android:run

Click Run.

Command Line Build

  1. Create project with Android tool
    • Android list target
    • This shows the available Android platforms, find the flat you want To compile your application, note the target ID and recommend the highest version.
      • Execute
        • android Create Project--target <target-id>--name myapp& Nbsp;--path <path-to-workspace>/myapp--activity mainactivity--package Com.example.myfirstapp

        • replace <target-id> with an ID value that you display in the list you just displayed, and replace <path-to-workspace> with the path to which the app is stored 。

  2. In Maven's ~/.m2/setting.xml, add the following to the Profiles tab to configure the path of the Android SDK.
    •     <profile>           <id>android</id>           <properties>               <android.sdk.path>                    e:\ INSTALLSPACE\ANDROID\ANDROID-SDK               </android.sdk.path>        </properties>        </profile>

    Add to the <activeProfiles></activeProfiles> tab

    <activeProfile>android</activeProfile>

  3. Add the file Pom.xml to the app as follows:
    • <?xml version= "1.0" encoding= "UTF-8"? ><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> Com.example.myfirstapp</groupid> <artifactId>MyFirstApp</artifactId> <version>1.0.0</ version> <packaging>apk</packaging> <name>MyFirstApp</name> <dependencies> <      Dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>4.1.1.4</version> <scope>provided</scope> </dependency> </dependenci es> <build> <sourceDirectory>src</sourceDirectory> <finalname>${project.artifactid}  </finalName> <pluginManagement> <plugins> <plugin>        <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactid>android-mav En-plugin</artifactid> <version>3.8.2</version> <extensions>true</extensions&        Gt </plugin> </plugins> </pluginManagement> <plugins> <plugin> <group Id>com.jayway.maven.plugins.android.generation2</groupid> <artifactid>android-maven-plugin</  Artifactid> <configuration> <sdk> <!--platform as API level (API Level = Platform 4.1)-<platform>16</platform> </sdk> </configura tion> </plugin> </plugins> </build></project>
      The following changes are pom.xml in the
        • Modify Groupid,artifactid and Name
        • Set the version label, for example <version>0.1.0-snapshot</version>.

        • Update Android Dependency
  4. Build apk
    MVN clean Install
  5. Deploy the APK to the device
    MVN Android:deploy
  6. Run directly

Clean install Android:deploy Android:run

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.