最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】uiautomator2用app_start启动app报错:uiautomator2.exceptions.BaseError package not found

app crifan 1848浏览 0评论
折腾:
【未解决】uiautomator2中如何获取到欢乐大作战游戏界面中的元素
期间,用代码:
AndroidAppMainActivity = "com.hldzz.dmw.MainActivity"
d.app_start(AndroidAppMainActivity)
结果报错:
20191122 09:21:18 autoTestAndroidGame.py:32   INFO    d.info={'currentPackageName': 'com.tencent.tmgp.hldzzsyol', 'displayHeight': 1080, 'displayRotation': 3, 'displaySizeDpX': 851, 'displaySizeDpY': 393, 'displayWidth': 2135, 'productName': 'cepheus', 'sdkInt': 29, 'naturalOrientation': False}
21:21:20.769 $ curl -X GET -d '""' 'http://127.0.0.1:51426/packages/com.hldzz.dmw.MainActivity/info'
21:21:20.827 Response (57 ms) >>>
{"description":"package \"com.hldzz.dmw.MainActivity\" not found","success":false}
<<< END
Traceback (most recent call last):
  File "/Users/crifan/.vscode/extensions/ms-python.python-2019.10.44104/pythonFiles/ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "/Users/crifan/.vscode/extensions/ms-python.python-2019.10.44104/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 432, in main
    run()
  File "/Users/crifan/.vscode/extensions/ms-python.python-2019.10.44104/pythonFiles/lib/python/old_ptvsd/ptvsd/__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/crifan/dev/dev_root/python/autoTestAndroid/autoTestAndroidGameHappyBigBattle/autoTestAndroidGame.py", line 38, in <module>
    autoTestAndroidGame()
  File "/Users/crifan/dev/dev_root/python/autoTestAndroid/autoTestAndroidGameHappyBigBattle/autoTestAndroidGame.py", line 34, in autoTestAndroidGame
    d.app_start(AndroidAppMainActivity)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/__init__.py", line 897, in app_start
    info = self.app_info(package_name)
  File "/Users/crifan/.local/share/virtualenvs/autoTestAndroidGameHappyBigBattle-F2NzwZ7Z/lib/python3.7/site-packages/uiautomator2/__init__.py", line 1243, in app_info
    raise BaseError(resp.get('description', 'unknown'))
uiautomator2.exceptions.BaseError: package "com.hldzz.dmw.MainActivity" not found
->看来mainActivity都搞错了。
-》不过也从(开启了debug的)输出
d.info={'currentPackageName': 'com.tencent.tmgp.hldzzsyol', 'displayHeight': 1080, 'displayRotation': 3, 'displaySizeDpX': 851, 'displaySizeDpY': 393, 'displayWidth': 2135, 'productName': 'cepheus', 'sdkInt': 29, 'naturalOrientation': False}
中看到了,此时正在运行的游戏的包名是:com.tencent.tmgp.hldzzsyol
所以再去搜搜:
com.tencent.tmgp.hldzzsyol
tencent hldzzsyol
hldzzsyol
和平精英(com.tencent.tmgp.pubgmhd) – 1.4.6 – 游戏 – 酷安网
应用包名:com.tencent.tmgp.pubgmhd
开发者名称:深圳市腾讯计算机系统有限公司
王者荣耀(com.tencent.tmgp.sgame) – 1.51.1.23 – 游戏 – 酷安网
应用包名:com.tencent.tmgp.sgame
com.tencent.tmgp是什么文件?_百度知道
tmgp推测是:tencent mobile game Platform=腾讯移动游戏平台=腾讯手游平台
hldzzsyol推测是:欢乐大作战 手游 online(在线)
欢乐大作战 手游在线
欢乐大作战 腾讯
‎App Store 上的“欢乐大作战-挂机策略卡牌手游”
https://apps.apple.com/cn/app/欢乐大作战-挂机策略卡牌手游/id1479527036
供应商 Guangzhou Eight Hundred Play Network Technology Co., Ltd
Copyright ©Eight Hundred Play Network Technology Co.,Ltd
欢乐大作战 腾讯游戏平台
欢乐大作战 腾讯移动游戏平台
腾讯移动游戏平台
腾讯移动游戏平台
https://games.qq.com/mobile/tencentmobilegames.htm
果然是我猜测的:tencentmobilegames=腾讯移动游戏平台
还关注了 微信公众号,结果也没找到 欢乐大作战
算了,去试试
AndroidAppMainActivity = "com.tencent.tmgp.pubgmhd.MainActivity"
结果:
问题依旧:
uiautomator2.exceptions.BaseError: package "com.tencent.tmgp.pubgmhd.MainActivity" not found
看来要找到当前安装的这个游戏的apk才行了。
weditor中运行代码,也能看到同样信息
{'currentPackageName': 'com.tencent.tmgp.hldzzsyol', 'displayHeight': 1080, 'displayRotation': 3, 'displaySizeDpX': 851, 'displaySizeDpY': 393, 'displayWidth': 2135, 'productName': 'cepheus', 'sdkInt': 29, 'naturalOrientation': False}
cepheus
最后通过微信中搜:
欢乐大作战
找到了其官方微信公众号
进入后
找到了下载
http://adv.play800.cn/down/18060
复制此条链接,在浏览器中打开即可下载~”
-》
->
➜  28.0.3 ./aapt dump badging /Users/crifan/dev/dev_tool/android/apk/欢乐大作战/sign_lsbl_android_93616402197272428_334aeee12928e137efdf711f098fe1b5.apk
package: name='com.hldzz.dmw' versionCode='20' versionName='510'
install-location:'auto'
sdkVersion:'16'
targetSdkVersion:'26'
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='com.android.vending.BILLING'
uses-permission: name='android.permission.VIBRATE'
uses-permission: name='com.hldzz.dmw.permission.JPUSH_MESSAGE'
uses-permission: name='android.permission.RECEIVE_USER_PRESENT'
uses-permission: name='android.permission.READ_PHONE_STATE'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.MOUNT_UNMOUNT_FILESYSTEMS'
uses-permission: name='com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE'
uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
application-label:'欢乐大作战'
application-label-zh:'欢乐大作战'
application-icon-120:'res/drawable-ldpi-v4/app_icon.png'
application-icon-160:'res/drawable-mdpi-v4/app_icon.png'
application-icon-240:'res/drawable-hdpi-v4/app_icon.png'
application-icon-320:'res/drawable-xhdpi-v4/app_icon.png'
application-icon-480:'res/drawable-xxhdpi-v4/app_icon.png'
application-icon-640:'res/drawable-xxxhdpi-v4/app_icon.png'
application: label='欢乐大作战' icon='res/drawable-mdpi-v4/app_icon.png' banner='res/drawable-xhdpi-v4/app_banner.png'
application-isGame
launchable-activity: name='com.hldzz.dmw.MainActivity'  label='欢乐大作战' icon=''
leanback-launchable-activity: name='com.hldzz.dmw.MainActivity'  label='欢乐大作战' icon='' banner=''
feature-group: label=''
  uses-gl-es: '0x20000'
  uses-feature-not-required: name='android.hardware.sensor.accelerometer'
  uses-feature-not-required: name='android.hardware.touchscreen'
  uses-feature-not-required: name='android.hardware.touchscreen.multitouch'
  uses-feature-not-required: name='android.hardware.touchscreen.multitouch.distinct'
  uses-feature: name='android.hardware.location'
  uses-implied-feature: name='android.hardware.location' reason='requested android.permission.ACCESS_COARSE_LOCATION permission, and requested android.permission.ACCESS_FINE_LOCATION permission'
  uses-feature: name='android.hardware.screen.landscape'
  uses-implied-feature: name='android.hardware.screen.landscape' reason='one or more activities have specified a landscape orientation'
  uses-feature: name='android.hardware.screen.portrait'
  uses-implied-feature: name='android.hardware.screen.portrait' reason='one or more activities have specified a portrait orientation'
  uses-feature: name='android.hardware.wifi'
  uses-implied-feature: name='android.hardware.wifi' reason='requested android.permission.ACCESS_WIFI_STATE permission'
main
other-activities
other-receivers
other-services
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--' 'zh'
densities: '120' '160' '240' '320' '480' '640'
native-code: 'armeabi-v7a'
结果还是:
com.hldzz.dmw.MainActivity
啊,但是为何无法启动啊?
https://github.com/openatx/uiautomator2
再去仔细看实例代码
d.app_start("com.example.hello_world")
貌似com.example.hello_world
只是app的包名,而不是 mainActivity???
那试试

AndroidAppPackageName = "com.hldzz.dmw"


d.app_start(AndroidAppPackageName)
结果:
找不到:
uiautomator2.exceptions.BaseError: package "com.hldzz.dmw" not found
后来发现之前的:
com.tencent.tmgp.pubgmhd.MainActivity
搞错了,应该是:
AndroidAppMainActivity = "com.tencent.tmgp.hldzzsyol.MainActivity"
d.app_start(AndroidAppMainActivity)
结果:
uiautomator2.exceptions.BaseError: package "com.tencent.tmgp.hldzzsyol.MainActivity" not found
那再试试:

AndroidAppPackageName = "com.tencent.tmgp.hldzzsyol"


d.app_start(AndroidAppPackageName)

结果:
是可以启动app的
【总结】
此处uiautomator2的官网文档
https://github.com/openatx/uiautomator2
写的不够好
# 默认的这种方法是先通过atx-agent解析apk包的mainActivity,然后调用am start -n $package/$activity启动
d.app_start("com.example.hello_world")
让我误以为是启动 package_name.MainActivity呢
结果搞错了,实际上是:
d.app_start(android_app_package_name)
而此处之所报错是因为:
网上下载到的,同名的游戏:欢乐大作战
和此处从微信中推荐游戏中下载到的,不是同一个app
-》估计是原游戏开发商,转到腾讯旗下了。
所以对应游戏的包名,从:
com.hldzz.dmw
变成了:
com.tencent.tmgp.hldzzsyol
所以此处用:
AndroidAppPackageName = "com.tencent.tmgp.hldzzsyol"
d.app_start(AndroidAppPackageName)
即可正常启动游戏app了。
另外,此处如果不知道当前app的包名,除了去用aapt解析:
【已解决】分析安卓游戏app欢乐大作战的主页面mainActivity
即:
aapt dump badging xxx.apk
得到包名外,还可以:
用uiautomator2的代码:
import uiautomator2 as u2


d = u2.connect()


print(d.info)
其中输出的
{'currentPackageName': 'com.tencent.tmgp.hldzzsyol' ...
 中的currentPackageName的值,也就是当前app的包名。
另外:
同样代码,除了终端中运行,weditor中也可以运行,输出结果。

转载请注明:在路上 » 【已解决】uiautomator2用app_start启动app报错:uiautomator2.exceptions.BaseError package not found

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.171 seconds, using 22.14MB memory