您的位置:首页 > 移动开发 > Android开发

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

2014-04-30 14:22 477 查看
根据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.csfreebird
Created project directory: mvn_example1
Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/src/org/csfreebird
Added file mvn_example1/src/org/csfreebird/MainActivity.java
Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/res
Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/bin
Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/libs
Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/res/values
Added file mvn_example1/res/values/strings.xml
Created directory /home/dean/work/gitlab_cloud/android/example/mvn_example1/res/layout
Added file mvn_example1/res/layout/main.xml
Added file mvn_example1/AndroidManifest.xml
Added file mvn_example1/build.xml
Added 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 libs
rm: cannot remove ‘build.properties’: No such file or directory
启动模拟设备后,运行下面的命令编译和部署:mvn clean install
mvn android:deploy
部署成功后,会看到模拟设备上出现程序图标。点击运行,成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: