1、源码下载位置:http://maven.outofmemory.cn/com.android.tools.ddms/ddmlib/22.9.1/
2、依赖的jar包:common-22.9.1.jar、guava-15.0.jar、kxml2-2.3.0.jar
3、用eclipse导出包;
4、由于项目特殊要求,将adb的端口改为5039,然后在cmd中adb功能正常,但是ddms中就是不能发现设备,最后研究adb的services后发现属性:host:track-devices
This is a variant of host:devices which doesn't close the connection. Instead, a new device list description is sent each time a device is added/removed or the state of a given device changes (hex4 + content). This allows tools like DDMS to track the state of connected devices in real-time without polling the server repeatedly.
这个服务是以上的host:devices的一个变种,客户端和ADB服务器的连接会一致保持,当有增加/移除设备或者设备状态改变的时候会主动的往连接上的客户端发送新的设备列表信息(4字节16进制长度+内容)。这样做的话就可以允许DDMS这些工具来实时跟踪所有连接上来的设备的状态,而不需要客户端每次都去连接ADB服务器获取对应信息。
5、参看test_track_devices.c了解到,当adb服务起来后,client去connect 5039,即可,此处逻辑让我纠结好久,不知eclipse和adb怎么联系起来的
6、DDMS工具就是D:\tools\adt-bundle-windows-x86_64-20140702\sdk\tools\ddms.bat
就可启动ddms,查看了解到ddmslib.jar
7、ddmslib.jar源码解析待续。。
当我们改了adb.exe的端口号后,ddmslib也得改,否则服务端xxx,ddms则是5037,怎么连得上了;
com.android.ddmlib.AndroidDebugBridge
private String[] getAdbLaunchCommand(String option) {
List<String> command = new ArrayList<String>(4);
command.add(mAdbOsLocation);
if (sAdbServerPort != DEFAULT_ADB_PORT) {
command.add("-P"); //$NON-NLS-1$
command.add(Integer.toString(sAdbServerPort));
}
command.add(option);
return command.toArray(new String[command.size()]);
}
======================================>>>>>>>>
private static int getAdbServerPort() {
// check system property
Integer prop = Integer.getInteger(SERVER_PORT_ENV_VAR);
.............................................
// when system property is not set or is invalid, parse environment property
try {
String env = System.getenv(SERVER_PORT_ENV_VAR);
if (env != null) {
return validateAdbServerPort(env);
}
}
..................................................................
// use default port if neither are set
return DEFAULT_ADB_PORT;
}
因而当改了adb的port后还得在环境变量中新建ANDROID_ADB_SERVER_PORT,变量值为你的port
8、其他应用如ddms的截屏功能
工程
9、adb相关文章:http://blog.youkuaiyun.com/yinlijun2004/article/details/7031443
http://blog.youkuaiyun.com/zhubaitian/article/details/41723093
http://blog.youkuaiyun.com/vichie2008/article/details/40823531
http://www.jizhuomi.com/android/environment/215.html
http://blog.youkuaiyun.com/new_abc/article/details/7467537