命令相关-Aapt

aapt相关

要使用aapt命令前提是要把它加入到环境变量中

如:%SDK_HOME%\build-tools\33.0.0\

查看apk有哪些权限

1
aapt d permissions app-release.apk

lint相关

从命令行运行lint

  • 在Windows上

    1
    gradlew lint
  • 在Linux或Mac上

    1
    ./gradlew lint

如果项目包含“构建变体”,而您只想对某个特定的构建变体运行 lint 任务,您必须大写变体名称并在其前面加上 lint 前缀。

1
gradlew lintDebug

检查无用资源

  • AS 上 【推荐使用】

    1
    Analyze -> Run Inspection by Name -> 输入:Unused resources -> 跳出弹框选择范围即可
  • 命令方式

    1
    lint --check UnusedResources <project dir>

keytool 相关

查看apk的签名

首先用解压软件解压出META-INF目录下的CERT.RSA文件

1
keytool -printcert -file D:\Desktop\CERT.RSA

查看keystore的签名

1
keytool -list -keystore D:\Desktop\app_key

查看keystore的签名

1
keytool -list -v -keystore e:\debug.keystore -storepass xxx(密匙)

keytool得到的应用签名和安全码.png

其中的MD5去掉冒号就是”微信签名工具“得到的那串32位数(第三方参数文档中的”应用签名”)

SHA1(对应第三方参数文档中”安全码“)

去掉冒号的js代码:”CD:B0:3E:73:53:2B:C2:A2:54:5D:2E:75:67:74:BB:92”.replace(/:/g,””)

查看AS自带签名文件

Android Studio自带签名文件路径:(密码:android)

C:\Users\Administrator\.android\debug.keystore

1
keytool -list -v -keystore C:\Users\Administrator\.android\debug.keystore

MonkeyRunner

执行键盘录制

配置bat脚本,设置jdk环境

monkeyrunner.bat 设置到环境变量中:把D:\Android\SDK\tools\bin添加到环境变量中;同时更改环境变量为jdk8

配置python脚本

record.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env monkeyrunner
# Copyright 2010, The Android Open Source Project#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at#
# http://www.apache.org/licenses/LICENSE-2.0#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from com.android.monkeyrunner import MonkeyRunner as mr
from com.android.monkeyrunner.recorder import MonkeyRecorder as recorder
device = mr.waitForConnection()
recorder.start(device)

playback.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env monkeyrunner  
# Copyright 2010, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from com.android.monkeyrunner import MonkeyRunner
# The format of the file we are parsing is very carfeully constructed.
# Each line corresponds to a single command. The line is split into 2
# parts with a | character. Text to the left of the pipe denotes
# which command to run. The text to the right of the pipe is a python
# dictionary (it can be evaled into existence) that specifies the
# arguments for the command. In most cases, this directly maps to the
# keyword argument dictionary that could be passed to the underlying
# command.
# Lookup table to map command strings to functions that implement that
# command.
CMD_MAP = {
'TOUCH': lambda dev, arg: dev.touch(**arg),
'DRAG': lambda dev, arg: dev.drag(**arg),
'PRESS': lambda dev, arg: dev.press(**arg),
'TYPE': lambda dev, arg: dev.type(**arg),
'WAIT': lambda dev, arg: MonkeyRunner.sleep(**arg)
}
# Process a single file for the specified device.
def process_file(fp, device):
for line in fp:
(cmd, rest) = line.split('|')
try:
# Parse the pydict
rest = eval(rest)
except:
print 'unable to parse options'
continue
if cmd not in CMD_MAP:
print 'unknown command: ' + cmd
continue
CMD_MAP[cmd](device, rest)
def main():
file = sys.argv[1]
fp = open(file, 'r')
device = MonkeyRunner.waitForConnection()
process_file(fp, device)
fp.close();
if __name__ == '__main__':
main()

执行录制脚本

1
monkeyrunner d:\replay\record.py

wait: 用来插入下一次操作的时间间隔,点击后即可设置时间,单位是秒

Press a Button:用来确定需要点击的按钮,包括menu、home、search,以及对按钮的press、down、up属性

Type Something:用来输入内容到输入框

Fling:用来进行拖动操作,可以向上、下、左、右,以及操作的范围

Export Actions:用来导出脚本,不需要后缀名,也可以添加后缀名

Refresh Display:用来刷新手机界面,估计只有在断开手机后,重新连接时才会用到

点击“export actions”保存录制脚本到 d:\replay\r

执行回放脚本

1
monkeyrunner d:\replay\playback.py d:\replay\r

其中r是上面录制的脚本文件

MonkeyRunner相关问题

如果录制脚本的时候报SWT folder '..\framework\x86_64' does not exist.错误:

那么打开 monkeyrunner.bat 更改:

1
2
3
.set frameworkdir=lib (纠正)==》set frameworkdir=..\lib 

.Dcom.android.monkeyrunner.bindir=..\framework -jar %jarpath% %* (纠正)==》Dcom.android.monkeyrunner.bindir=..\..\platform-tools -jar %jarpath% %*