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

本文介绍了在Ubuntu 14.04上使用Maven创建Android工程的两种方法。由于使用archetype创建时遇到依赖问题,作者选择了使用android命令行创建项目,然后复制并修改例子工程的pom文件。通过这种方式,成功创建并运行了一个名为mvn_example1的项目。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据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

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

点击运行,成功。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值