BlueRoseNote/03-UnrealEngine/Moible/Android常用命令.md

175 lines
7.0 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Android常用命令
date: 2025-06-17 14:09:07
excerpt:
tags:
rating: ⭐
---
# Adb
adb 是 Android 的调试工具,非常强大,熟悉一些 adb 的命令能够让效率加倍。
## 安装 Apk
adb install APK_FILE_NAME.apk
## 启动 App
安装的 renderdoccmd 是没有桌面图标的,想要自己启动的话只能使用下列 adb 命令:
```bash
adb shell am start org.renderdoc.renderdoccmd.arm64/.Loader -e renderdoccmd "remoteserver"
```
adb 启动 App 的 shell 命令模板:
```bash
adb shell am start PACKAGE_NAME/.ActivityName
```
这个方法需要知道 App 的包名和 Activity 名,包名很容易知道,但是 Activity 如果不知道可以通过下列操作获取:
首先使用一个反编译工具将 apk 解包(可以使用之前的[apktools](https://imzlp.com/notes/#apk%E7%9A%84%E5%8F%8D%E7%BC%96%E8%AF%91%E4%B8%8E%E7%AD%BE%E5%90%8D))
```bash
apktool.bat d -o ./renderdoccmd_arm64 org.renderdoc.renderdoccmd.arm64.apk|
```
然后打开 `org.renderdoc.renderdoccmd.arm64` 目录下的 `AndroidManifest.xml` 文件,找到其中的 `Application` 项:
```xml
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.renderdoc.renderdoccmd.arm64" platformBuildVersionCode="26" platformBuildVersionName="8.0.0">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature android:glEsVersion="0x00030000" android:required="true"/>
<application android:debuggable="true" android:hasCode="true" android:icon="@drawable/icon" android:label="RenderDocCmd">
<activity android:configChanges="keyboardHidden|orientation" android:exported="true" android:label="RenderDoc" android:name=".Loader" android:screenOrientation="landscape">
<meta-data android:name="android.app.lib_name" android:value="renderdoccmd"/>
</activity>
</application>
</manifest>
```
其中有所有注册的`Activity`,没有有界面的 apk 只有一个 Activity所以上面的 renderdoccmd 的主 Activity 就是`.Loader`
如果说有界面的 app则会有多个则可以从 `AndroidManifest.xml` 查找 `Category` 或者根据命名 (名字带`main` 的 Activity)来判断哪个是主 Activity。一般都是从 lanucher 开始,到 main或者有的进登陆界面。
> PS使用 UE 打包出游戏的主 Activity 是`com.epicgames.ue4.SplashActivity`,可以通过下列命令启动。
```bash
adb shell am start com.imzlp.GWorld/com.epicgames.ue4.SplashActivity
```
## 传输文件
使用 adb 往手机传文件:
```bash
adb push 1.0_Android_ETC2_P.pak /sdcard/Android/data/com.imzlp.TEST/files/UE4GameData/Mobile422/Mobile422/Saved/Paks
adb push FILE_NAME REMOATE_PATH
```
从手机传递到电脑:
```bash
adb pull /sdcard/Android/data/com.imzlp.TEST/files/UE4GameData/Mobile422/Mobile422/Saved/Paks/1.0_Android_ETC2_P.pak A.Pak
adb pull REMOATE_FILE_PATH LOCAL_PATH
```
## Logcat
使用 `logcast` 可以看到 Android 的设备 Log 信息。
```bash
adb logcat
```
会打印出当前设备的所有信息,但是我们调试 App 时不需要看到这么多,可以使用 `find` 进行筛选(注意大小写严格区分)
```bash
adb logcat | find "GWorld"
adb logcat | find "KEY_WORD"
```
查看 UE 打包的 APP 所有的 log 可以筛选:
```bash
adb logcat | find "UE4"
```
如果运行的次数过多积累了大量的 Log可以使用清理
```bash
adb logcat -c
```
输出到文件:
```bash
adb logcat > c:\Users\loujiajie\Desktop\log.txt
```
## 从设备中提取已安装的 APK
注意:执行下列命令时需要检查手机是否开放开发者权限,手机上提示的验证指纹信息要允许。
```bash
# 查看链接设备
$ adb devices
List of devices attached
b2fcxxxx unauthorized
# 列出手机中安装的所有 app
$ adb shell pm list package
# 如果提示下问题,则需要执行 adb kill-server
error: device unauthorized.
This adb servers $ADB_VENDOR_KEYS is not set
Try 'adb kill-server' if that seems wrong.
Otherwise check for a confirmation dialog on your device.
# 正常情况下会列出一堆这样的列表
C:\Users\imzlp>adb shell pm list package
package:com.miui.screenrecorder
package:com.amazon.mShop.android.shopping
package:com.mobisystems.office
package:com.weico.international
package:com.github.shadowsocks
package:com.android.cts.priv.ctsshim
package:com.sorcerer.sorcery.iconpack
package:com.google.android.youtube
# 找到指定 app 的的 apk 位置
$ adb shell pm path com.github.shadowsocks
package:/data/app/com.github.shadowsocks-iBtqbmLo8rYcq2BqFhJtsA==/base.apk
# 然后将该文件拉取到本地来即可
$ adb pull /data/app/com.github.shadowsocks-iBtqbmLo8rYcq2BqFhJtsA==/base.apk
/data/app/com.github.shadowsocks-iBtqbmLo8rYcq2BqFhJtsA==/...se.apk: 1 file pulled. 21.5 MB/s (4843324 bytes in 0.215s)
```
## 刷入 Recovery
下载[Adb](https://ue5wiki.com/wiki/6fa72650/index/Adb.7z),然后根据具体情况使用下列命令(如果当前已经在 bootloader 就不需要执行第一条了)。
```bash
adb reboot bootloader
# 写入 img 到设备
fastboot flash recovery recovery.img
fastboot flash boot boot.img
# 引导 img
fastboot boot recovery.img
```
## 端口转发
可以通过 adb 命令来指定:
```bash
# PC to Device
adb reverse tcp:1985 tcp:1985
# Device to PC
adb forward tcp:1985 tcp:1985
```
- [Android 上超级好用的前端调试方法adb reverse](http://blog.xiaoyu.im/post_678.html)
## 根据包名查看 apk 位置
可以使用以下 adb 命令:
```bash
$ adb shell pm list package -f com.tencent.tmgp.fm
package:/data/app/com.tencent.tmgp.fm-a_cOsX8G3VClXwiI-RD9wQ==/base.apk=com.tencent.tmgp.fm
```
最后一个参数是包名, 输出的则是 apk 的路径。
## 查看当前窗口的 app 的包名
使用以下 adb 命令:
```bash
adb shell dumpsys window w | findstr \/ | findstr name=
mSurface=Surface(name=SideSlideGestureBar-Bottom)/@0xa618588
mSurface=Surface(name=SideSlideGestureBar-Right)/@0x619b646
mSurface=Surface(name=SideSlideGestureBar-Left)/@0xea02007
mSurface=Surface(name=StatusBar)/@0x7e4962d
mAnimationIsEntrance=true mSurface=Surface(name=com.tencent.tmgp.fm/com.epicgames.ue4.GameActivity)/@0x43b30a0
mSurface=Surface(name=com.tencent.tmgp.fm/com.epicgames.ue4.GameActivity)/@0xa3481e
mAnimationIsEntrance=true mSurface=Surface(name=com.vivo.livewallpaper.monster.bmw.MonsterWallpaperService)/@0x53e44ae
```
其中的 `mAnimationIsEntrance=true mSurface=Surface(name=` 之后,到 `/` 之前的字符串就是我们的 app 包名。
# MuMu打开ABD方法
1. CMD CD到MuMu安装目录下例如`E:\Program Files\Netease\MuMu Player 12\shell`
2. 在命令提示符窗口内输入adb.exe connect 127.0.0.1:XXXXX之后点击回车。注XXXXX为模拟器端口号请参考打开的模拟器问题诊断内展示端口号或MuMu多开器12内的adb端口后再输入。
1. 在MuMu多开器右上角的ADB图标点击就可以显示端口。
2.