在说明书前面描述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,
https://codeload.github.com/jayway/maven-android-plugin-samples/legacy.zip/stable
保存到本地解压到文件夹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
如今模拟设备上已经看到图标了:
执行后能够看到几个不同颜色的button, 点击button窗体颜色能够切换。
版权声明:本文博客原创文章,博客,未经同意,不得转载。