Android SDK开发常用工具的使用及其异常处理

由于以下操作都是命令操作,所以在执行以下操作之前确保环境变量 ANDROID_HOME 指向的是正确的Android SDK的路径:

一、启动Android SDK Manager:

android

 

二、启动Android Device Monitor:

monitor

 

三、启动UI Automator Viewer:

uiautomatorviewer

 

四、启动hierarchyviewer

hierarchyviewer

 

 

有的时候启动UI Automator Viewer失败,会提示“unexpected error while parsing input invalid uiautomator hierarchy file”,忘记截图了。。。具体什么原因,暂时未知,以后补充,解决方法:

rm -rf ~/.android/monitor-workspace/

 

五、aapt工具的使用,以下截图来自百度百科:

第五部分其余内容参考:http://blog.csdn.net/g19920917/article/details/20244937

5.1

 aapt d[ump] [--values] WHAT file.{apk} [asset [asset ...]]
   badging          Print the label and icon for the app declared in APK.
   permissions      Print the permissions from the APK.
   resources        Print the resource table from the APK.
   configurations   Print the configurations in the APK.
   xmltree          Print the compiled xmls in the given assets.
   xmlstrings       Print the strings of the given compiled xml assets.

 

5.2、查看apk包的packageName、versionCode、applicationLabel、launcherActivity、permission等各种详细信息

aapt dump badging <file_path.apk>

效果图如下:

5.3、查看权限

aapt dump permissions <file_path.apk>

 

 

5.4、查看资源列表

aapt dump resources <file_path.apk>

 

一般都会输出很多的信息,如要全部查看,请用下面这两句:
aapt dump resources <file_path.apk> > sodino.txt
sodino.txt
这样会把所有的信息通过重定向符">"输出到sodino.txt文件中,然后再打开该文件即可查看。


5.5、查看apk配置信息

aapt dump configurations <file_path.apk>

 

5.6、查看指定apk的指定xml文件。

aapt dump xmltree <file_path.apk> res/***.xml

 

以树形结构输出的xml信息。

aapt dump xmlstrings <file_path.apk> res/***.xml

 

输出xml文件中所有的字符串信息。

Android设备连接出现问题时,可以使用如下命令解决:

adb kill-server && adb devices

 

5.7、由于此处代码量比较大,本人写成批处理形式了。(本段代码未验证)

使用aapt生成R.java
rem 测试的工程目录下必须得有gen文件夹,否则会提示:Unable to open class file R.java:No such file or directory
%aapt% package -f -m -J %GEN% -S %RES% -I %ANDROID_JAR% -M %ANDROID_MANIFEST_XML%

使用aapt生成资源包文件
%aapt% package -f -M %ANDROID_MANIFEST_XML% -S %RES% -A %ASSETS% -I %ANDROID_JAR% -F %RESOURCE%

%GEN%:存放的R.java文件夹路径。
%RES%:res文件夹路径。
%ANDROID_JAR%:引用的android.jar路径。
%ANDROID_MANIFEST_XML%:工程AndroidManifest.xml绝对路径。
%ASSETS%:asset文件夹路径。
%RESOURCE%:生成的resouces.arsc存放路径。

 

 

rm -rf ~/.android/monitor-workspace/

posted @ 2016-07-15 22:00  HuijunZhang  阅读(4803)  评论(0编辑  收藏  举报
中国