Maven 命令 建立 android項目

1.用android tool 建立項目。html

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 tooljava

 
2.在項目根目錄中建立一個pom.xml文件,android


[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> git

3. 在命令中建立的項目生產了一些文件, 在用android maven plugin 的時候, 有些文件是不須要的。github


rm -r bin build.xml build.properties libsweb

4.構建項目apache

到項目MyAndroidMavenApp 的根目錄:app

mvn clean install框架


可能出現的錯誤:less

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 學習地址                

相關文章
相關標籤/搜索