I’m getting the same error on a lot of my tests:
java.lang.NoClassDefFoundError: Failed resolution of:
Landroid/view/autofill/AutofillManager$AutofillCallback;
Basically my code introduces android.view.autofill.AutofillManager.AutofillCallback
, but AutofillCallback is only available on API 26 and up.
I’m guessing this is the cause of the error. Is there a way to get around this for the tests? Put in another way, is there a way to only conditionally import the AutofillManager
and AutofillCallback
for specific Build versions?
Here is how I'm introducing the AutofillManager
and AutofillCallback
.
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// ... other code not shown
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
{
final AutofillManager autofillManager = getContext().getSystemService(AutofillManager.class);
if (autofillManager != null && autofillManager.isAutofillSupported())
{
autofillManager.registerCallback(new AutofillManager.AutofillCallback()
{
@Override
public void onAutofillEvent(@NonNull View view, int event)
{
super.onAutofillEvent(view, event);
// other code not shown
}
});
}
}