Androidx Activity OnBackPressedCallback Interface Issue

You're mixing stable releases (appcompat:1.0.2 and the fragment:1.0.0 it depends on) with alpha releases. Only Fragment 1.1.0 alpha versions of FragmentActivity depend on androidx.activity's ComponentActivity and therefore include the addOnBackPressedCallback method.

You need to specifically include androidx.fragment:fragment:1.1.0-alpha05 or switch your AppCompat dependency to androidx.appcompat:appcompat:1.1.0-alpha03 (which transitively depends on Fragment 1.1.0-alpha05).


As of August 2019 this is all I needed instead of loading other dependencies as the top answer androidx.appcompat:appcompat:1.1.0-rc01