Ubuntu 14.04 Android 使用Maven一 使用例子工程
时间:2014-04-30 22:31:40
收藏:0
阅读:412
前文描述的是在SDK下用Ant开发, 本文在此基础上尝试用Maven开发。
这里需要用到maven-android-plugin。
本文主要参考官方文档: https://code.google.com/p/maven-android-plugin/wiki/GettingStarted
首先从这里下载例子工程:https://code.google.com/p/maven-android-plugin/wiki/Samples,保存到本地jayway-maven-android-plugin-samples-4d8d535/
进入该目录的子目录:helloflashlight
运行mvn clean compile, 编译报错后会提示要安装一些Android SDK, 用下面的命令:
/opt/android-sdk-linux/tools/android update sdk --no-ui --all --force
之后再运行mvn clean compile, 编译成功。
现在首先启动虚拟设备
android avd然后选中我之前创建的mt680, 启动之。
现在退回到jayway-maven-android-plugin-samples-4d8d535 目录, 运行命令
mvn clean install
经过较长的等待,会看到一些测试成功了,一些失败了。可能是我的mt680太老了吧。
[INFO] [INFO] Android SDK ApiDemos - Parent ..................... SUCCESS [ 0.324 s] [INFO] Android SDK ApiDemos - Application ................ SUCCESS [ 26.921 s] [INFO] Android SDK ApiDemos - Instrumentation Test ....... SUCCESS [ 25.250 s] [INFO] HelloFlashlight ................................... SUCCESS [ 1.275 s] [INFO] MorseFlash - Parent ............................... SUCCESS [ 0.004 s] [INFO] MorseFlash - Library .............................. SUCCESS [ 35.338 s] [INFO] MorseFlash - App .................................. SUCCESS [ 4.753 s] [INFO] MorseFlash - Instrumentation Test ................. FAILURE [ 13.121 s] [INFO] Scala Application ................................. SKIPPED [INFO] Library Projects Parent ........................... SKIPPED [INFO] Library Projects - AAR 1 .......................... SKIPPED [INFO] Library Projects - APKLIB 1 ....................... SKIPPED [INFO] Library Projects - APKLIB 2 ....................... SKIPPED [INFO] Library Projects - Main App ....................... SKIPPED [INFO] Library Projects - Instrumentation Tests .......... SKIPPED [INFO] Library Projects - AAR Consumption ActionBarSherlock SKIPPED [INFO] Android NDK - Aggregator .......................... SKIPPED [INFO] Android NDK - Native Sample ....................... SKIPPED [INFO] Android NDK - Java With Native Dependency ......... SKIPPED [INFO] Android NDK - Java With Native Dependency x86 Only SKIPPED [INFO] Android NDK - Native Static Library ............... SKIPPED [INFO] Android NDK - Native Code including Static Library SKIPPED [INFO] Android NDK - Java With Native Statically Linked Dependency SKIPPED [INFO] Android NDK - Java With Native Library ............ SKIPPED [INFO] Android NDK - Java Transient Dependency ........... SKIPPED [INFO] Android NDK - Java Native Mixed Sample ............ SKIPPED [INFO] Android NDK - Native APKLIB Sample ................ SKIPPED [INFO] Android NDK - apklib With Native APKLIB Dependency SKIPPED [INFO] Android NDK - Java With Native APKLIB Dependency .. SKIPPED [INFO] Android NDK - Java Native Mixed with APKLIB Dependency Sample SKIPPED [INFO] Android Support V4 Demos .......................... SKIPPED [INFO] Tictactoe - Parent ................................ SKIPPED [INFO] tictactoe - Library ............................... SKIPPED [INFO] tictactoe - App ................................... SKIPPED [INFO] Android Maven Plugin Samples - Aggregator ......... SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:49 min [INFO] Finished at: 2014-04-29T20:54:10+08:00 [INFO] Final Memory: 31M/352M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.8.2:internal-integration-test (default-internal-integration-test) on project morseflash-instrumentation: emulator-5554_MT680_unknown_sdk : Tests failed on device. -> [Help 1]
现在进入子项目helloflashlight目录中, 运行mvn install, 结果在targets目录下生成了apk文件,然后运行命令安装到设备中:
adb install target/helloflashlight.apk
或者用下面的命令:
mvn android:deploy
现在模拟设备上已经看到图标了:
运行后可以看到几个不同颜色的按钮, 点击按钮窗口颜色可以切换。
评论(0)