You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 13自定义Launcher应用无法通过Appium 2.0启动求助

解决Appium 2.0启动自定义Launcher应用的Activity错误

1. 手动验证Activity可启动性

先用adb命令直接启动目标Activity,确认系统层面能否识别:

adb shell am start -n com.your.package/.YourLauncherActivity

如果启动失败,说明即便包名和Activity名正确,也可能存在权限或Manifest配置问题;如果能正常启动,再排查Appium配置。

2. 调整Appium启动参数

Launcher属于系统级应用,需要针对性配置Desired Capabilities:

  • 添加noReset: true,避免Appium重置应用状态导致默认Launcher被切换
  • 设置appWaitActivity: "*",等待应用下的所有Activity(Launcher启动后可能存在隐性跳转)
  • 指定automationName: "UiAutomator2",Appium 2.0对该驱动的系统应用支持更稳定

示例配置(Python):

desired_caps = {
    "platformName": "Android",
    "deviceName": "your_device",
    "appPackage": "com.your.package",
    "appActivity": ".YourLauncherActivity",
    "automationName": "UiAutomator2",
    "noReset": True,
    "appWaitActivity": "*"
}

3. 检查Manifest的Launcher配置

确认自定义Launcher的Activity在AndroidManifest.xml中包含必要配置:

  • 必须声明android.intent.category.HOME、android.intent.category.DEFAULT、android.intent.category.LAUNCHER这三类Intent Filter
  • 确保android:exported="true"(Android 12+强制要求,低版本也建议配置)

示例Manifest片段:

<activity
    android:name=".YourLauncherActivity"
    android:exported="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

4. 更新并配置UiAutomator2驱动

  • 确保UiAutomator2驱动为最新版本:
appium driver update uiautomator2
  • 启动Appium服务时添加--allow-insecure=adb_shell参数,获取更高adb权限以启动系统级应用

5. 锁定设备默认Launcher

部分品牌设备(如三星)有默认应用锁定机制,手动设置后仍可能被干扰:

  • 在设备「设置-应用-默认应用-桌面」中,锁定自定义Launcher为默认
  • 用adb命令强制设置默认Launcher:
adb shell cmd package set-home-activity com.your.package/.YourLauncherActivity

内容的提问来源于stack exchange,提问作者shanmuga prasanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 20:52:13