建立一個android maven application

來源:互聯網
上載者:User

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.2.0</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是可以的

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.