Ubuntu 14.04 Android 使用Maven二 创建自己的Maven工程

来源:互联网 发布:手机文字排版软件 编辑:程序博客网 时间:2024/06/16 10:05

根据https://code.google.com/p/maven-android-plugin/wiki/GettingStarted 介绍,有两种方法可以创建Maven工程。

第一种方法是用archetype, 但是我使用了之后,发现archetype产生的项目编译时有一个依赖找不到,不管了,先换其他方法。

第二种方法就是使用android命令行创建项目,然后复制例子代码工程的pom文件并修改,

Ubuntu 14.04 设置Android开发环境 描述了如何用命令行创建项目

Ubuntu 14.04 Android 使用Maven一 使用例子工程介绍了例子工程helloflashlight


先创建一个项目mvn_example1

android create project --target android-10 --name mvn_example1 --path mvn_example1 --activity MainActivity --package org.csfreebirdCreated project directory: mvn_example1Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/src/org/csfreebirdAdded file mvn_example1/src/org/csfreebird/MainActivity.javaCreated directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/resCreated directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/binCreated directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/libsCreated directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/res/valuesAdded file mvn_example1/res/values/strings.xmlCreated directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/res/layoutAdded file mvn_example1/res/layout/main.xmlAdded file mvn_example1/AndroidManifest.xmlAdded file mvn_example1/build.xmlAdded file mvn_example1/proguard-project.txt

现在复制heelloflashlight的pom.xml文件到该项目目录下, 然后修改其中的一些配置:

  <groupId>org.freebird</groupId>  <artifactId>example1</artifactId>  <version>1.0.0</version>  <packaging>apk</packaging>  <name>mvn_example1</name>
设置platform版本为10,这里使用的是API Level,也可以使用platform level: 2.3.3, 具体可以通过命令android list targets, 不过这里目前还只能设置16, 设置10部署会失败,暂时不明白原因。
    <plugins>      <plugin>        <groupId>com.jayway.maven.plugins.android.generation2</groupId>        <artifactId>android-maven-plugin</artifactId>        <configuration>          <sdk>            <!-- platform as api level (api level 16 = platform 4.1)-->            <platform>10</platform>          </sdk>        </configuration>      </plugin>    </plugins>

删除掉ant相关的文件:

mvn_example1$ rm -r bin build.xml build.properties libsrm: cannot remove ‘build.properties’: No such file or directory

启动模拟设备后,运行下面的命令编译和部署:

mvn clean installmvn android:deploy

部署成功后,会看到模拟设备上出现程序图标。

点击运行,成功。




0 0
原创粉丝点击