Appium报错解决

1、Appium启动会话报错

使用手机OPPO Andorid 11的版本

An unknown server-side error occurred while processing the command. 
Original error: Error executing adbExec. 
Original error: 'Command ''D:\\Program Files (x86)\\android-sdk-windows\\platform-tools\\adb.exe' 
-P 5037 -s 3654ae33 shell pm clear com.android.settings' exited with code 255'; 
Stderr: 'Exception occurred while executing 'clear':
 
 java.lang.SecurityException: adb clearing user data is forbidden.
 at com.android.server.pm.ColorClearDataProtectManager.interceptClearUserDataIfNeeded(ColorClearDataProtectManager.java:87)
 at com.android.server.pm.OppoBasePackageManagerService$OppoPackageManagerInternalImpl.interceptClearUserDataIfNeeded(OppoBasePackageManagerService.java:481)
 at com.android.server.am.ActivityManagerService.clearApplicationUserData(ActivityManagerService.java:4659)
 at com.android.server.pm.PackageManagerShellCommand.runClear(PackageManagerShellCommand.java:2154)
 at com.android.server.pm.PackageManagerShellCommand.onCommand(PackageManagerShellCommand.java:239)
 at android.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
 at android.os.ShellCommand.exec(ShellCommand.java:44)
 at com.android.server.pm.PackageManagerService.onShellCommand(PackageManagerService.java:23384)
 at android.os.Binder.shellCommand(Binder.java:936)
 at android.os.Binder.onTransact(Binder.java:820)
 at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4603)
 at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:4852)
 at com.android.server.pm.OppoPackageManagerService.onTransact(OppoPackageManagerService.java:167)
 at android.os.Binder.execTransactInternal(Binder.java:1166)
 at android.os.Binder.execTransact(Binder.java:1130)'; Code: '255'

在这里插入图片描述
OPPO 手机要开启两项权限
在这里插入图片描述
这个问题是由于手机权限没有完全开通,除了打开“USB调试功能” 还有几个设置需要开启
小米手机需要打开了“USB调试(安全设置)",这个功能会允许通过USB调试修改权限或者模拟点击的功能
在这里插入图片描述

2、UiAutomator exited unexpectedly with code 0, signal null

在这里插入图片描述
添加 ‘automationName’ = ‘UiAutomator2’
还有一种情况是虚拟设备的情况,不一定是Android 11版本,这样可以参考以下链接:
https://blog.csdn.net/px551/article/details/104555485