App-Crawler与Firebase Robo Test无法点击RecyclerView问题排查
AndroidX RecyclerView在Firebase Robo Test与App-Crawler中的测试问题
一、报错信息
1. Firebase Robo Test报错
action { 11-25 19:42:06.495: I/Robo(6000): target_action { 11-25 19:42:06.495: I/Robo(6000): action_parameters { 11-25 19:42:06.495: I/Robo(6000): directive { 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): view_position { 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): target { 11-25 19:42:06.495: I/Robo(6000): description { 11-25 19:42:06.495: I/Robo(6000): android_class_name: "android.view.ViewGroup" 11-25 19:42:06.495: I/Robo(6000): class_name: "androidx.recyclerview.widget.RecyclerView" 11-25 19:42:06.495: I/Robo(6000): component_type: 1 11-25 19:42:06.495: I/Robo(6000): identifiers { 11-25 19:42:06.495: I/Robo(6000): child_position: 1 11-25 19:42:06.495: I/Robo(6000): mode_agnostic_sequence: "0.0.0.0.0.0.0.0.0.0.2" 11-25 19:42:06.495: I/Robo(6000): mode_specific_sequence: "0.0.1.0.0.0.0.1.0.0.1" 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): input_type: 1 11-25 19:42:06.495: I/Robo(6000): resource_name: "house_intellect.nfc_reports:id/calendars_list" 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): state { 11-25 19:42:06.495: I/Robo(6000): is_enabled: true 11-25 19:42:06.495: I/Robo(6000): is_focusable: true 11-25 19:42:06.495: I/Robo(6000): is_shown: true 11-25 19:42:06.495: I/Robo(6000): visible_bounds { 11-25 19:42:06.495: I/Robo(6000): bottom: 2541 11-25 19:42:06.495: I/Robo(6000): left: 42 11-25 19:42:06.495: I/Robo(6000): right: 1038 11-25 19:42:06.495: I/Robo(6000): top: 779 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): type: 1 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.495: I/Robo(6000): } 11-25 19:42:06.496: W/Robo(6000): Notifying controller of internal platform error. 11-25 19:42:06.496: W/Robo(6000): androidx.test.tools.crawler.platform.common.InternalPlatformException: View position is set but the screen element is neither a RecyclerView or an AdapterView. 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.hybrid.HybridInteractionController.perform(HybridInteractionController.java:34) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.hybrid.HybridInteractionController.click(HybridInteractionController.java:10) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.ActionExecutor.execute(ActionExecutor.java:59) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.ActionExecutor.performAction(ActionExecutor.java:4) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.RemotePlatform.handlePerformAction(RemotePlatform.java:22) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.RemotePlatform.messageLoop(RemotePlatform.java:59) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.RemotePlatform.lambda$startCrawlAndWaitUntilFinished$0$androidx-test-tools-crawler-platform-RemotePlatform(RemotePlatform.java:1) 11-25 19:42:06.496: W/Robo(6000): at androidx.test.tools.crawler.platform.RemotePlatform$$ExternalSyntheticLambda1.run(Unknown Source:6) 11-25 19:42:06.496: W/Robo(6000): at java.lang.Thread.run(Thread.java:920)
2. App-Crawler报错
FAILED: Found 1 crash. java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/RecyclerView; FATAL EXCEPTION: ControllerMessenger Process: house_intellect.nfc_reports, PID: 13281 java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/RecyclerView; at androidx.test.espresso.contrib.RecyclerViewActions$ActionOnItemAtPositionViewAction.getConstraints(RecyclerViewActions.java:5) at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.getConstraints(ViewInteraction.java:6) at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:57) at androidx.test.espresso.ViewInteraction.a(ViewInteraction.java:96) at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:3) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.RecyclerView" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/androidx.test.tools.crawler-1/base.apk", zip file "/data/app/house_intellect.nfc_reports-2/base.apk"],nativeLibraryDirectories=[/data/app/androidx.test.tools.crawler-1/lib/x86, /data/app/house_intellect.nfc_reports-2/lib/x86, /system/lib, /vendor/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:380) at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
二、相关代码
1. RecyclerView布局代码
<androidx.recyclerview.widget.RecyclerView android:id="@+id/calendars_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="@dimen/margin_medium" android:fadeScrollbars="false" android:scrollbars="vertical" app:adapter="@{viewModel.availableCalendarsAdapter}" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" app:layout_constraintBottom_toTopOf="@id/new_calendar" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" tools:listitem="@layout/calendar_layout" />
2. Robo脚本(roboscript.json)
原脚本内容:
"actions": [ { "eventType": "DELAYED_MESSAGE_POSTED", "timestamp": 1700968034609, "actionCode": -1, "delayTime": 7000, "canScrollTo": false, "elementDescriptors": [] }, { "eventType": "VIEW_CLICKED", "timestamp": 1700968042058, "replacementText": "", "actionCode": -1, "delayTime": 0, "canScrollTo": false, "elementDescriptors": [ { "resourceId": "house_intellect.nfc_reports:id/selectedCalendar", "recyclerViewChildPosition": 0, }, { "resourceId": "my.package:id/calendars_list", }, { "resourceId": "my.package:id/bottom_sheet", } ] } ]
3. 依赖配置
implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.3.2' androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.6.0-alpha01'
三、已尝试的解决方法
- 将Robo脚本转为Espresso测试可正常运行
- 尝试多种元素定位方式
- 用RelativeLayout包裹RecyclerView
- 上述方法均无效,所有项目的RecyclerView都存在该问题
四、问题分析与解决方案
问题根源
- App-Crawler报错原因:
espresso-contrib依赖内部仍引用旧版support库的RecyclerView类,而项目已完全迁移到AndroidX,导致类加载失败。 - Firebase Robo Test报错原因:
- Robo脚本中
recyclerViewChildPosition参数放置位置错误,该参数应属于RecyclerView元素,而非子元素; - 脚本中RecyclerView的包名与实际布局不一致;
- 旧版本的Robo测试库可能对AndroidX RecyclerView的类型判断存在兼容问题,误将其识别为非RecyclerView类型。
- Robo脚本中
解决方案
1. 修复App-Crawler的类加载问题
修改espresso-contrib依赖,排除旧版support库的引用,确保使用AndroidX版本:
androidTestImplementation('androidx.test.espresso:espresso-contrib:3.6.0-alpha01') { exclude group: 'com.android.support', module: 'support-v4' exclude group: 'com.android.support', module: 'recyclerview-v7' }
同时确认gradle.properties中已开启AndroidX迁移:
android.useAndroidX=true android.enableJetifier=true
2. 修正Robo脚本的元素定位
调整elementDescriptors的顺序和参数位置,修正包名错误:
"actions": [ { "eventType": "DELAYED_MESSAGE_POSTED", "timestamp": 1700968034609, "actionCode": -1, "delayTime": 7000, "canScrollTo": false, "elementDescriptors": [] }, { "eventType": "VIEW_CLICKED", "timestamp": 1700968042058, "replacementText": "", "actionCode": -1, "delayTime": 0, "canScrollTo": false, "elementDescriptors": [ { "resourceId": "house_intellect.nfc_reports:id/calendars_list", "recyclerViewChildPosition": 0 }, { "resourceId": "house_intellect.nfc_reports:id/selectedCalendar" }, { "resourceId": "house_intellect.nfc_reports:id/bottom_sheet" } ] } ]
3. 升级Firebase测试相关依赖
确保项目中Firebase Test Lab的相关依赖为最新版本,避免因库版本过旧导致的AndroidX兼容问题。
4. 优化测试设备配置
在Firebase控制台发起测试时,选择较新版本的Android系统设备,提升对AndroidX组件的兼容性。
内容的提问来源于stack exchange,提问作者Grape On Wheels
相关产品推荐
相关产品推荐

