How to disable the new Autofill feature from Android Oreo for espresso tests

adb shell pm disable com.google.android.gms/com.google.android.gms.autofill.service.AutofillService

This should disable the autofill service. It is same as turning off autofill service in the system settings manually. It at least worked on the emulator. But this needs root access.

Another way to disable the autofill service is to change the autofill_service settings.

adb shell settings put secure autofill_service null


Based on documentation, you can disable Autofill services using AutofillManager#disableAutofillServices() API:

If the app calling this API has enabled autofill services they will be disabled.

Usage:


    val autofillManager: AutofillManager = context.getSystemService(AutofillManager::class.java)
    autofillManager.disableAutofillServices()

You can do this in @Before step of your test.