attribute android:forceQueryable not found in Android studio when running Espresso test
Asked Answered
S

2

13

I have recorded my android app Espresso test using android studio Record Espresso Test option in Run menu. In the end of the record I saved the test with a my own file name.

Once click the save button, IDE automatically created the file in AndroidTest directory of the app module. I right click the saved file and clicked run. Then it prompting me the following error.

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

following is the file in the above link.

<?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>

I'm using Android Studio 4.1

Please Advice.

Superaltar answered 5/11, 2020 at 15:18 Comment(4)
Might be related to github.com/android/android-test/issues/743. Can you try with version 1.3.1-alpha02 (or later) of the AndroidX Test library?Apply
I am not sure if this would help. I recently came across this issue as well. I got it work when I used androidTestImplementation 'androidx.test:rules:1.3.0-alpha03' instead of androidTestImplementation 'androidx.test:rules:1.3.1-alpha02' in my build.gradle(app). ActivityTestRule is deprecated in the newer version.Bleeding
Dear @Apply I tried didn't work. I found a solution and check it.Superaltar
Dear @hypergogeta, I tried your suggestion as well didn't work. I found a solution and check it.Superaltar
S
10

Here is what I did.

At the end of the espresso recording, I noticed Android Studio automatically adds the following library to the Gradle build.xml file of the app level.

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

The following are my other libraries I added manually by myself according to espresso setup guide in google android developers document.

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

Then I updated the above libraries to the latest versions as below(Because android studio suggested the latest versions, so I updated).

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

Then I make the versions of espresso-contrib equal to espresso-core as below

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

note, now both espresso-contrib and espresso-core having the version of 3.3.0

I removed the following libraries from my gradle build file also, haven't checked, what happened if they stay continuously. because my purpose is not to test but do a task continuously as a kind of robot program.

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

Finally, it worked, I assume the reason for the above error in the question is because of the version mismatch.

Superaltar answered 7/11, 2020 at 6:18 Comment(3)
I have to keep the Junit libraries, and this solution is not working. Hopefully is gonna be fixed in the next espresso stable versionDecreasing
This worked for me, I had espresso 3.4.0-alpha02 and after I set it to 3.3.0 the bug was gone.Beaton
@CodigoMorsa Thanks for letting everyone know.Superaltar
O
2

In my case, this configuration is working.

androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0-alpha03'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0-alpha03'
androidTestImplementation 'androidx.test:runner:1.3.1-alpha03'
androidTestImplementation 'androidx.test:rules:1.3.1-alpha03'
Oubliette answered 2/2, 2021 at 23:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.