java.lang.IllegalArgumentException: menu item with ID 2131558727 doesn't have a MediaRouteActionProvider

if you are building a release apk with minifyEnabled true, add those lines to your proguard file

-keep class android.support.v7.app.MediaRouteActionProvider{
  *;
}
-keep class androidx.mediarouter.app.MediaRouteActionProvider{
*;
}

On file menu/main.xml (or other XML containing your menu) replace this:

app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"

By this:

app:actionProviderClass="androidx.mediarouter.app.MediaRouteActionProvider"