首页 > 解决方案 > 运行 Espresso 测试时在 Android Studio 中找不到属性 android:forceQueryable

问题描述

我已经使用运行菜单中的 android studio Record Espresso Test选项记录了我的 android 应用 Espresso 测试。在记录的最后,我用自己的文件名保存了测试。

单击保存按钮后,IDE 会自动在应用模块的AndroidTest目录中创建文件。我右键单击保存的文件并单击运行。然后它提示我以下错误。

/Users/dehanwijesekara/Documents/ProjectName/app/build/intermediates/packaged_manifests/debugAndroidTest/AndroidManifest.xml:24: AAPT: error: attribute android:forceQueryable not found.

以下是上述链接中的文件。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dehan.pizzago.test" >

<uses-sdk
    android:minSdkVersion="23"
    android:targetSdkVersion="29" />

<instrumentation
    android:name="androidx.test.runner.AndroidJUnitRunner"
    android:functionalTest="false"
    android:handleProfiling="false"
    android:label="Tests for com.dehan.pizzago"
    android:targetPackage="com.dehan.pizzago" />

<queries>
    <package android:name="androidx.test.orchestrator" />
    <package android:name="androidx.test.services" />
    <package android:name="com.google.android.apps.common.testing.services" />
</queries>

<uses-permission android:name="android.permission.REORDER_TASKS" />

<application
    android:debuggable="true"
    android:extractNativeLibs="false"
    android:forceQueryable="true" >
    <uses-library android:name="android.test.runner" />

    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyActivity"
        android:theme="@android:style/Theme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
    <activity
        android:name="androidx.test.core.app.InstrumentationActivityInvoker$EmptyFloatingActivity"
        android:theme="@android:style/Theme.Dialog" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
        </intent-filter>
    </activity>
</application>

我正在使用 Android Studio 4.1

请指教。

标签: javaandroidandroid-studioandroid-espressoandroid-espresso-recorder

解决方案


这就是我所做的。

在 espresso 录制结束时,我注意到 Android Studio 会自动将以下库添加到build.xml应用级别的 Gradle 文件中。

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha02'

以下是我根据google android 开发人员文档中的 espresso 设置指南手动添加的其他库。

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'

然后我将上述库更新为最新版本如下(因为android studio建议使用最新版本,所以我更新了)。

androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'

然后我使版本espresso-contrib等于espresso-core如下

androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0'

请注意,现在两者espresso-contribespresso-core具有3.3.0

我也从我的 gradle 构建文件中删除了以下库,没有检查,如果它们持续存在会发生什么。因为我的目的不是测试,而是作为一种机器人程序不断地完成一项任务。

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'

最后,它起作用了,我认为问题中出现上述错误的原因是版本不匹配。


推荐阅读