---
title: "Maven开发Android指南 5 调试"
author: "reymont"
date: "2012-12-21T14:36:54Z"
tags: []
categories: ["移动开发"]
slug: "maven-android-5"
draft: false
lastmod: "2012-12-21T14:36:54Z"
id: 1751714
url: "https://reymont.iteye.com/blog/1751714"
---

对于一个使用Maven的Android应用，调试看起来是个大问题，没有"Debug as Android application"怎么办？总不能一直用logcat（Log.*v*(*TAG,…*）吧。

 

如果阅读了《[Maven开发Android指南 4 与Eclipse整合（m2e-android ）](http://reymont.iteye.com/blog/1751587)》，那么这就不是问题了。

 

m2e-android很智能的将 Android Developer Tools (ADT)和 Maven Android Plugin结合在一起，细心的读者可以看到，左上角项目图标上面有一个M和A，分别代表着Maven和Android。

 ![](http://dl.iteye.com/upload/attachment/0078/2463/b06c5da7-1893-3800-9d97-91fb26a0f1ba.png)

正如上篇提到到的，可以"Run as Android application"，那么当然可以"Debug as Android application"

 

 

 

但是还是有些读者不满足，就是不喜欢"Debug as Android application"，那么DDMS将是你的选择。（需要安装m2e-android）

![](http://dl.iteye.com/upload/attachment/0078/2582/3e100e4a-4dec-3699-b2b2-2da1c6de7eea.png)

 

通过命令部署Android应用

cd HelloM2EAndroid

mvn android:emulator-start

mvn clean package android:deploy

 

打开Eclipse中的DDMS，选择对应的应用，点击绿色的小甲壳虫，它将会帮你抓住所有断点。

 

 

 

 

 

 

 

 

**名词解释：**

**logcat**是Android中一个命令行工具，可以用于得到程序的log信息。

The Android logging system provides a mechanism for collecting and viewing system debug output. Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command. You can use logcat from an ADB shell to view the log messages

**DDMS**的全称是Dalvik Debug Monitor Service，是 Android 开发环境中的Dalvik[虚拟机](http://baike.baidu.com/view/1132.htm)调试监控服务。它为我们提供例如：为测试设备截屏，针对特定的进程查看正在运行的线程以及堆信息、[Logcat](http://baike.baidu.com/view/4504801.htm)、广播状态信息、模拟电话呼叫、接收SMS、虚拟地理坐标等等。

Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more

 

**参考：**

[http://code.google.com/p/maven-android-plugin/wiki/Debug](http://code.google.com/p/maven-android-plugin/wiki/Debug)

[http://baike.baidu.com/view/4504801.htm](http://baike.baidu.com/view/4504801.htm)

[http://baike.baidu.com/view/2688850.htm](http://baike.baidu.com/view/2688850.htm)

[http://developer.android.com/tools/help/logcat.html](http://developer.android.com/tools/help/logcat.html)

[http://developer.android.com/tools/debugging/ddms.html](http://developer.android.com/tools/debugging/ddms.html)