Android Programming: Pushing the Limits -- Chapter 1: Fine-Tuning Your Development Environment

ADB命令
Application Exerciser Monkey
Gradle
ProGuard
代码重用
版本控制
静态代码分析
代码重构
开发者模式
 

ADB命令:

@、adb help:查看adb命令。

@、adb devices:列出所有连接的安卓设备和模拟器。

@、adb push <local> <remote> 把计算机里的文件拷贝到设备中。

adb push e:\test.xml /sdcard/files.ldb/

@、adb pull <remote> <local> 把设备中的文件拷贝到计算机里

@、adb devices:可以查看连接设备的序列号(serial number)

@、adb {–s <serial number>} logcat

@、adb logcat <tag>:<priority>

举例:

在自定义类中定义一个日志标签,如:

private static final String LOG_TAG = “MyActivity”;

然后在此自定义类中的代码中使用此标签记录日志,如:

Log.d(LOG_TAG, “adb logcat test”);

这样就可以在命令行中使用MyActivity这个标签进行日志过滤,命令格式:

adb logcat MyActivity:* *:S

注:*:S不能少,*:S表示让logcat不展示其它日志(原文:*:S,which tells logcat to silence all messages.)。

@、使用adb命令,实现通过Wifi连接设备。注:安卓设备与计算机使用同一Wifi。

1、  首先使用USB连接设备与计算机;

2、  在命令行中输入以下命令

adb devices //确认下连接的设备,可以看到序列号。

adb tcpip 5555  //以TCP/IP模式重启设备的adb进程,并监听5555端口(adb默认端口)

adb connect <IP>  //通知计算机的adb Service 连接 IP 地址,其中IP为设备的IP。

adb devices //再次确认连接的设备,此时可看到一个<IP>:5555 的设备。

3、  这样拔掉USB线后,依然可以使用此设备进行调试。

4、  当重启设备,或者使用 adb usb 命令,设备的adb进程又恢复USB模式。

 

@、adb shell 可以对设备使用命令行操作,类似于在Linux上操作一样。

@、adb shell am <options> 可以启动设备上的Service,Intent等。

@、adb shell pm <options> 可以对设备中的功能,权限进行查看、安装等操作。

具体了解adb命令,可查看http://developer.android.com/tools/help/adb.html

 

Application Exerciser Monkey:

@、一个命令行工具,能够通过生成伪随机事件来模拟用户操作对应用进行stress test。

@、命令:adb shell monkey –p <package name> <event count>

@、通过Monkeyrunner进行regression testing。You can find the API for the Monkeyrunner at http://developer.android.com/tools/help/monkeyrunner_concepts.html#APIClasses

 

Gradle:

The user guide for the new Gradle build system can be found at

http://tools.android.com/tech-docs/new-build-system/user-guide

 

ProGuard:

@、一个集成在Android SDK的工具,在发布应用时,可用此工具打乱代码(obfuscate your code),这样可增加应用被反编译的难度。使用方法:在build.gradle文件中添加:

buildTypes {

release {

runProguard true

proguardFile getDefaultProguardFile(‘proguard-android.txt’)

}

}

@、可以优化代码,去除无用的代码,减小发布应用的大小。

 

代码重用:

@、使用JAR包,一般用于引用第三方的代码。使用方法:把JAR包拷贝到libs目录下,然后再build.gradle文件中添加:

dependencies{

         compile files(‘libs/XXX.jar’) // XXX为要引用的JAR包名称。

}

@、使用library project,常用于一个工程里的多个应用,服务端和客户端等之间共享一些工具类,通用视图等。使用方法,在工程中新建一个module,类型选择Android Library;然后在其它模块的build.gradle文件中添加:

dependencies{

         compile project(‘:libraries:XXX’) // XXX为创建的library project的名称。

}

 

版本控制:

@、git:

1、  https://git-scm.com/

2、  Version Control with Git 一本介绍git的书。

@、创建自己的gitolite服务器,这样就可以远程访问Git respositories。

You can find the documentation and download for gitolite at

http://gitolite.com/gitolite

An excellent quick installation guide can be found at

http://gitolite.com/gitolite/qi.html

@、使用现成的服务器,比如GitHub http://github.com

@、代码检查工具Gerrit

You can find out more about Gerrit and download the server at

https://code.google.com/p/gerrit (新地址:https://www.gerritcodereview.com/)

 

静态代码分析:

@、使用Android SDK自带的lint工具进行代码分析。使用方法:在Android Studio的project视图中,右键 >> Analyze >> Inspect Code…

 

代码重构:

@、通过Refactor功能,实现静态变量提取,方法提取,方法签名变化等功能。详细信息请查看:http://www.jetbrains.com/idea/features/refactoring.html

 

开发者模式:

@、Android 4.2及以后版本系统,开发人员菜单被隐藏,开启方法:进入“关于手机” >> “版本号(Build Number)”点击7次 >> 返回上一层,可看到开发人员菜单。

 

posted @ 2016-06-20 19:04  liDB  阅读(210)  评论(0编辑  收藏  举报