androidandroid-studio

android:enableOnBackInvokedCallback="true"


I am trying to build my Android application in AndroidStudio but I am getting this error:

ERROR: U:\AndroidStudioProjects\MyApp\app\src\main\AndroidManifest.xml:9:5-99:19: AAPT: error: attribute android:enableOnBackInvokedCallback not found.

(drive U: is pointing to my user home directory).

Any idea anyone what this BS message is supposed to mean? I googled left and right but the only thing I found re. android:enableOnBackInvokedCallback was that one should have a property android:enableOnBackInvokedCallback="true" defined in the application element.

Both, the application I am trying to build as well as a self-created library .aar-file that I am using do have that property specified and set to true in their respective AndroidManifest.xml-file's application element.

So, why can this then not be found? And where else, if not there is it supposed to be found then? Or what else is this error message trying to convey to me?


Solution

  • android:enableOnBackInvokedCallback was added as part of Android 14 (API 34) to support the Predictive Back Gesture as the flag that allows you to opt-in to the predictive back gesture.

    Therefore to use android:enableOnBackInvokedCallback, you need to have a compileSdk of at least 34 - the API level that it was introduced.

    As explained in the Picking your compileSdk, minSdk, and targetSdk blog post, you should always compile with the latest SDK - this will allow you to iteratively start using those new APIs. Behavior changes related to new versions of Android are only changed by changing your targetSdk, which you can do as a separate step later.