Maven command to create an Android project

Source: Internet
Author: User

1. Create a project with the Android tool.

Android Create project \
--target <target_ID> \
--name <your_project_name> \
--path path/to/your/project \
--activity <your_activity_name> \
--package <your_package_namespace>
Target is the ' build target ' for your application. It corresponds to a Android platform library (including any add-ons, such as Google APIs) that's would like to build yo ur project against. To see a list of available targets and their corresponding IDs, execute:android list targets.
Name is the name of the for your project. This is optional. If provided, this name would be the used for your APK filename when you build your application.
Path is the location of the your project directory. If The directory does not exist, it is created for you.
Activity is the name of the your default activity class. This class file is created for inside<path_to_your_project>/src/<your_package_namespace_path>/. This would also is used for your apk filename unless you provide a name.
Package was the package namespace for your project, following the same rules as-packages in the Java programming Langua Ge.
For example: Create a name:myandroidmavenapp; Path:e:\app\myapp; Activity:mainactivity Package:com.example.mvnandroid's Android project.
Android Create Project
--target 1
--name Myandroidmavenapp
--path E:\app\myapp
--activity mainactivity
--package com.example.mvnandroid
Note: If the Android Home and Android tool is already configured in the system environment

2. Create a Pom.xml file in the project root directory,

<?xml version= "1.0" encoding= "UTF-8"?>
<project xmlns= "" xmlns:xsi= "Http://" xsi: schemalocation= "" >

<path>${env. Android_home}</path>

3. The project created in the command produced some files that were not needed when using Android Maven plugin.

Rm-r bin Build.xml Libs

4. Build the Project

To the root directory of the project Myandroidmavenapp:

MVN clean Install

Errors that may occur:

1. Failed to execute goal in Project Amvn_test:could not resolve dependencies for project Com.example.mvnandroid:amvn_te S
droid:jar:4.1 in Central (HTTP://REPO.MAVEN.APACHE.ORG/MAVEN2)

<span style= "White-space:pre" > </span><dependency>
Reason: Dependency in Version = 4.1 is too high, not found. To be modified. 2.3.3 is possible.

1. Create the project:


After the command executes you will see that MAVEN has generated a directory named My-app, which is the artifactid you specified in the command, and you will find the following standard project structure:

2.Build Project MVN Clean Compile
1. Enter on the command line: CD My-app Enter, enter under Project path
2. Enter MVN package return and the command line will print a variety of actions
Run a program
JAVA-CP Target/my-app-1.0-snapshot.jar

3. Run the Maven tool

Although it is difficult to list a very comprehensive table, here you can first list the most common default life cycle stages:

Validate: Verify that the project is correct and that all required resources are available.
Compile: Compile the source code for the project.
Test: Use the appropriate unit test framework for testing the compiled source code. These tests do not need to be packaged and deployed.
Package: Packages compiled code into a ready-to-publish format, such as a jar.
Integration-test: If necessary, package processing and publishing to an environment where integration testing is possible.
Verify: Run all checks to verify that the package is valid and meets quality standards.
Install: The package is installed in the local repository, can be used as a dependency of other projects.
Deploy: Execute in an integrated or release environment, copying the final version of the package to a remote repository, so that other developers or projects can be shared.
Clean: Clears the previously built artifacts (in Maven, the packages generated by the project are called artifact).
Site: Generates a document site for the project.

MVN Clean Dependency:copy-dependencies Package
This command clears the project first, then copies the dependencies, finally packages the project, and, of course, executes the previous phase of the phase before packaging. such as Compile,test.
Build site
MVN site
This phase generates project information based on the Pom.xml configuration. You can see the resulting document in the Target/site directory.

4. Package and run MVN clean packages

After the project is compiled and tested, the next important step is packaging. The package type is not specified in the Pom, and with the default package type jar, we can simply execute the command mvn the clean package. Similarly, MAVEN performs compile, test, and so on before packaging. Here we see that the Jar:jar task is responsible for packaging, which is actually the jar target of the jar plugin to package the project master code into a file named Hello-world-1.0-snapshot.jar, which is also located in the target/output directory. It is named according to Artifact-version.jar rules, and if necessary, we can also use Finalname to customize the name of the file, this is not expanded here, the book will be explained in detail later.



Command execution

{% highlight xml%}
MVN Clean Package

Packaged, but not deployed.
MVN clean Install

Package, deploy, and run.
MVN Clean Package Android:redeploy Android:run

This command is usually used for apps that are already installed on the phone, but the signatures are different, so we packaged and used the redeploy command to remove and redeploy the existing app, and finally run the app with the Run command.
MVN Android:redeploy Android:run

Do not package, redeploy and run the generated package.
MVN Android:deploy Android:run

Deploying and running a generated package, unlike redeploy, deploy does not delete existing deployment and application data.

MVN Clean install-prelease,channel-91

Packaged signature, the channel for channel-91 APK
{% Endhighlight%}

So file processing:
    mvn install:install-file- Dgroupid=com.voole.vooleglib-dartifactid=libvooleglib-dversion=v1-dfile=d:\maven\bf\playproxylib\libs\armeabi\
&NBSP;MVN install:install-file-dgroupid=com.voole.vooleglib-dartifactid=libvooletoken-dversion=v1-dfile=d:\ maven\bf\playproxylib\libs\armeabi\ 
mvn Install:install-file-dgroupid=com.voole.vooleglib-dartifactid=gifview- Dversion=1.0-dfile=d:\maven\bf\voolebf1.0\libs\gifview.jar-dpackaging=jar-dgeneratepom=true

MVN install:install-file-dgroupid=com.voole.vooleglib-dartifactid=common-codec-dversion=1.4-dfile=d:\maven\bf\ Voolebf1.0\libs\commons-codec-1.4.jar-dpackaging=jar-dgeneratepom=true

MVN install:install-file-dgroupid=com.voole.vooleglib-dartifactid=alipay-dversion=1.4-dfile=d:\maven\bf\ Voolebf1.0\libs\alipay.jar-dpackaging=jar-dgeneratepom=true

MVN Install:install-file-dgroupid=com.voole.vooleglib-dartifactid=universal-image-loader-dversion=1.9.3-dfile=d : \maven\bf\vooleframe\libs\universal-image-loader-1.9.3.jar-dpackaging=jar-dgeneratepom=true

MVN Install:install-file-dgroupid=com.voole.vooleglib-dartifactid=android-support-v4-dversion=1.7.0_65-dfile=d : \maven\bf\vooleframe\libs\android-support-v4.jar-dpackaging=jar-dgeneratepom=true

Download the sample code that can be supplied to the package test

Download Https:// Address


Https:// Study Address

Maven command to create an Android project

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.