Maven 命令 创建 android项目

1.用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 an Android platform library (including any add-ons, such as Google APIs) that you would like to build your project against. To see a list of available targets and their corresponding IDs, execute: android list targets.
name is the name for your project. This is optional. If provided, this name will be used for your .apk filename when you build your application.
path is the location of your project directory. If the directory does not exist, it will be created for you.
activity is the name for your default Activity class. This class file will be created for you inside<path_to_your_project>/src/<your_package_namespace_path>/ . This will also be used for your .apk filename unless you provide a name.
package is the package namespace for your project, following the same rules as for packages in the Java programming language.
例如:创建一个 name:MyAndroidMavenApp; path:E:\app\myapp; activity: MainActivity package: com.example.mvnandroid 的android项目。
android create project
--target 1
--name MyAndroidMavenApp
--path E:\app\myapp
--activity MainActivity
--package com.example.mvnandroid
注意:前提已经在系统环境中配置android home 和 android tool

 
2.在项目根目录中创建一个pom.xml文件,


[html] 
<?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.mvnandroid</groupId> 
    <artifactId>amvn_test</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>apk</packaging> 
    <name>amvn_t</name> 
 
    <dependencies> 
        <dependency> 
            <groupId>com.google.android</groupId> 
            <artifactId>android</artifactId> 
            <version>2.3.3</version> 
            <scope>provided</scope> 
        </dependency> 
    </dependencies> 
    <build> 
        <finalName>${project.artifactId}</finalName> 
        <sourceDirectory>src</sourceDirectory> 
        <pluginManagement> 
            <plugins> 
                <plugin> 
                    <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
                    <artifactId>android-maven-plugin</artifactId> 
                    <version>3.8.2</version> 
                    <extensions>true</extensions> 
                </plugin> 
            </plugins> 
        </pluginManagement> 
        <plugins> 
            <plugin> 
                <groupId>com.jayway.maven.plugins.android.generation2</groupId> 
                <artifactId>android-maven-plugin</artifactId> 
                <configuration> 
                    <run> 
                        <debug>true</debug> 
                    </run> 
                    <sdk> 
                        <path>${env.ANDROID_HOME}</path> 
                        <platform>10</platform> 
                    </sdk> 
                    <emulator> 
                        <avd>emulator-5554_android</avd> 
                    </emulator> 
                    <undeployBeforeDeploy>true</undeployBeforeDeploy> 
                </configuration> 
            </plugin> 
        </plugins> 
    </build> 
</project> 

3. 在命令中创建的项目生产了一些文件, 在用android maven plugin 的时候, 有些文件是不需要的。


rm -r bin build.xml build.properties libs

4.构建项目

到项目MyAndroidMavenApp 的根目录:

mvn clean install


可能出现的错误:

1.  Failed to execute goal on project amvn_test: Could not resolve dependencies for project com.example.mvnandroid:amvn_tes
droid:jar:4.1 in central (http://repo.maven.apache.org/maven2) ->


[html] 
<span style="white-space:pre">  </span><dependency> 
            <groupId>com.google.android</groupId> 
            <artifactId>android</artifactId> 
            <version>4.1</version> 
            <scope>provided</scope> 
        </dependency> 
原因:dependency中version = 4.1 太高了,没有找到。 要修改。2.3.3是可以的


1.创建项目:

mvn archetype:create -DgroupId=com.mycompany.app -DartifactId=my-app

命令执行完后你将看到maven生成了一个名为my-app的目录,这个名字就是你在命令中指定的artifactId,进入该目录,你将发现以下标准的项目结构:

2.Build 项目  mvn clean compile
 1. 在命令行上 输入 : cd my-app 回车,进入到 项目路径下
 2. 再输入 mvn package 回车这时命令行将会打印出各种动作
 //运行一个程序
 java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App

3. 运行Maven工具

虽然很难列出一张非常全面的表,但在此可先列出最普通的默认的生命周期阶段:

validate:验证工程是否正确,所有需要的资源是否可用。
compile:编译项目的源代码。 
test:使用合适的单元测试框架来测试已编译的源代码。这些测试不需要已打包和布署。
Package:把已编译的代码打包成可发布的格式,比如jar。
integration-test:如有需要,将包处理和发布到一个能够进行集成测试的环境。
verify:运行所有检查,验证包是否有效且达到质量标准。
install:把包安装在本地的repository中,可以被其他工程作为依赖来使用。
Deploy:在集成或者发布环境下执行,将最终版本的包拷贝到远程的repository,使得其他的开发者或者工程可以共享。
clean:清除先前构建的artifacts(在maven中,把由项目生成的包都叫作artifact)。
site:为项目生成文档站点。


mvn clean dependency:copy-dependencies package
这个命令将先清除项目,然后拷贝依赖,最后把项目打包,当然,在打包之前,会先执行此阶段之前的阶段.如compile,test等.
生成站点
mvn site
这个阶段生成基于pom.xml配置的项目信息。你可以在target/site目录下看到生成的文档。


4. 打包和运行  mvn clean package

将项目进行编译、测试之后,下一个重要步骤就是打包(package)。POM中没有指定打包类型,使用默认打包类型jar,我们可以简单地执行命令 mvn clean package 进行打包。类似地,Maven会在打包之前执行编译、测试等操作。这里我们看到jar:jar任务负责打包,实际上就是jar插件的jar目标将项目主代码打包成一个名为hello-world-1.0-SNAPSHOT.jar的文件,该文件也位于target/输出目录中,它是根据artifact-version.jar规则进行命名的,如有需要,我们还可以使用finalName来自定义该文件的名称,这里暂且不展开,本书后面会详细解释。


===========================================


mvn archetype:generate -DarchetypeArtifactId=android-quickstart -DarchetypeGroupId=de.akquinet.android.archetypes -DarchetypeVersion=1.0.8 -DgroupId=com.study.android -DartifactId=a1


命令执行

{% highlight xml %}
mvn clean package

打包,但不部署。
mvn clean install

打包,部署并运行。
mvn clean package android:redeploy android:run

这个命令通常用于手机上已经安装了要部署的应用,但签名不同,所以我们打包的同时使用redeploy命令将现有应用删除并重新部署,最后使用run命令运行应用。
mvn android:redeploy android:run

不打包,将已生成的包重新部署并运行。
mvn android:deploy android:run

部署并运行已生成的包,与redeploy不同的是,deploy不会删除已有部署和应用数据。

mvn clean install -Prelease,channel-91

打包签名,的渠道为channel-91的apk
{% endhighlight %}

==================
so文件处理:
 libvooleglib.so
    mvn install:install-file -DgroupId=com.voole.vooleglib -DartifactId=libvooleglib -Dversion=v1 -Dfile=D:\maven\bf\PlayProxyLib\libs\armeabi\libvooleglib.so -Dpackaging=so -DgeneratePom=true -Dclassifier=armeabi 
 
 libvooletoken.so
 mvn install:install-file -DgroupId=com.voole.vooleglib -DartifactId=libvooletoken -Dversion=v1 -Dfile=D:\maven\bf\PlayProxyLib\libs\armeabi\libvooletoken.so -Dpackaging=so -DgeneratePom=true -Dclassifier=armeabi 
 
 GifView.jar
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

commons-codec-1.4.jar
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


alipay.jar
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

universal-image-loader-1.9.3.jar
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

android-support-v4.jar  
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

下载可供给打包测试的例子代码 http://blog.csdn.net/forever_crying/article/details/8455626

下载 https://github.com/simpligility/maven-android-sdk-deployer地址

http://www.android100.org/html/201406/08/20945.html
  
  https://code.google.com/p/maven-android-plugin/wiki/GettingStarted 学习地址  
  
  
  
  
  
  
  

 

转载于:https://my.oschina.net/u/1017209/blog/488911

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值