Youtube player support fragment no longer working on Android studio 3.2 (androidx)

Just use transaction.replace. Ignore the error, it'll work. Google hasn't refactored youtube api library to androidx yet.


Just copy the original java file (com.google.android.youtube.player.YouTubePlayerFragment) to your project to the same package but different class name etc. com.google.android.youtube.player.YouTubePlayerFragmentX, and update the extends class from android.app.Fragment to androidx.fragment.app.Fragment.

The implementation is the same:

YouTubePlayerFragmentX youTubePlayerFragment = YouTubePlayerFragmentX.newInstance();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.add(R.id.youtube_fragment, youTubePlayerFragment).commit();

Tested... it's working.


I've fixed it by following the @Hosszful answer, I made it easy by just using this file, https://gist.github.com/medyo/f226b967213c3b8ec6f6bebb5338a492