MonkeyDevice

 分类:Android, Java 阅读 (1,212)  No Responses »
1月 302018
 

  MonkeyDevice用于控制安卓设备或者安卓模拟器,发送UI事件、发送广播、获取设备信息、安装删除应用和运行应用等。

  一般情况下使用MonkeyRunner.waitForConnection()可获取此类的实例,如下:

  下面是MonkeyDevice提供的一些方法列表:

Methods 描述 描述
void broadcastIntent (string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, iterable flags)

Broadcasts an Intent to this device, as if the Intent were coming from an application.

描述
void drag (tuple start, tuple end, float duration, integer steps)

Simulates a drag gesture (touch, hold, and move) on this device’s screen.

描述
object getProperty (string key)

Given the name of a system environment variable, returns its value for this device. The available variable names are listed in the detailed description of this method.

描述
object getSystemProperty (string key)

. The API equivalent of adb shell getprop <key>. This is provided for use by platform developers.

描述
void installPackage (string path)

Installs the Android application or test package contained in packageFile onto this device. If the application or test package is already installed, it is replaced.

描述
dictionary instrument (string className, dictionary args)

Runs the specified component under Android instrumentation, and returns the results in a dictionary whose exact format is dictated by the component being run. The component must already be present on this device.

描述
void press (string name, dictionary type)

Sends the key event specified by type to the key specified by keycode.

描述
void reboot (string into)

Reboots this device into the bootloader specified by bootloadType.

void removePackage (string package)

Deletes the specified package from this device, including its data and cache.

描述
object shell (string cmd)

Executes an adb shell command and returns the result, if any.

描述
void startActivity (string uri, string action, string data, string mimetype, iterable categories dictionary extras, component component, flags)

Starts an Activity on this device by sending an Intent constructed from the supplied arguments.

描述
MonkeyImage takeSnapshot()

Captures the entire screen buffer of this device, yielding a MonkeyImage object containing a screen capture of the current display.
描述
void touch (integer x, integer y, integer type)

Sends a touch event specified by type to the screen location specified by x and y.

描述
void type (string message)

Sends the characters contained in message to this device, as if they had been typed on the device’s keyboard. This is equivalent to callingpress() for each keycode in message using the key event type DOWN_AND_UP.

描述
void wake ()

Wakes the screen of this device.

描述

gradle打印依赖树

 分类:Android, Java 阅读 (11,889)  No Responses »
1月 132018
 

  本文适用于OSX和Linux系统,Windows系统用户可用来参考

  在Android Studio中进行了三方库的前期测试调研工作,然后要把工程转移到Android系统工程中,使用Android.mk进行编译,所有的三方jar包只能手动添加到工程中了。在使用Android Studio的dependency的时候除了显示添加到其中的三方库,三方库可能还会调用其他的依赖库,那怎么才能知道到底用了哪些库呢,只能使用gradle了。

  在命令行cd到工程所在的根目录,然后使用如下命令打印as工程中的库的依赖关系,其中app为要查看的模块的名称

  如果执行成功的话就会打印一大堆信息,其中一部分内容就是不同的gradle任务的类库依赖关系,类似如下形式:

已经下载的类库存在哪里?

  默认情况下gradle下载的文件在用户目录下的.gradle目录中,可以通过如下命令进行该目录

  然后通过find命令查找你想要的库就可以了,比如要查gson的jar包,可以用如下命令:

 

 Posted by on 2018-01-13

LeakCanary入门教程

 分类:Android, Java 阅读 (940)  No Responses »
1月 122018
 

首先在gradle中添加库的依赖,如下:

releaseImplementation依赖库是用于在release包中,只有LeakCanary的各种方法的壳,但是没有具体的实现,防止在给用户的release包中也进行内存检测操作。

然后新建一个Application类,并在此Application类的onCreate中加入以下代码

打开一个Activity,在关闭的时候如果有内存泄漏,LeakCanary将会在通知栏显示图片,点击图标即可看到详细的内存泄漏报告,如下图所示:

 Posted by on 2018-01-12

打包apk时出现Cannot recover key的错误

 分类:Android, Java 阅读 (4,158)  打包apk时出现Cannot recover key的错误已关闭评论
11月 252017
 

出现这种错误一般是输入的keystore的密钥有问题了

重新输入一下打包的密钥就可以了

 Posted by on 2017-11-25
11月 212017
 

需要安装的库(下载代码前):

sudo apt-get install curl

sudo apt-get install git

需要安装的库(编译前):

sudo apt-get install git git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev

sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev

sudo apt-get install lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown

sudo apt-get install lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown

sudo apt-get install lib32readline-gplv2-dev

sudo apt-get  install libxml2-utils

 Posted by on 2017-11-21
11月 142017
 

使用adb shell getprop即可获得Android系统的版本号,如下:

另外直接执行adb shell getprop还可以获得更多的系统属性,如下是我机器显示的结果:

 

 Posted by on 2017-11-14
9月 152017
 

我们可以使用adb shell dumpsys 来查看android设备中的相关服务信息,dumpsys后的参数为相关服务的名称。

比较常用的如:

那么我们如何查看其他我们可以dump的服务名称呢?答案是使用如下的命令即可获得android设备中的所有运行的服务列表

如下,是在我三星手机上运行命令获得的服务列表:

 

9月 142017
 

使用以下命令可以查看android设备的屏幕尺寸

如果两个命令都不能执行就只能自己写程序来获得尺寸了

 Posted by on 2017-09-14