For recording the app's screen, you will need to create virtual display via MediaProjection and then use MediaRecorder for recording.
You can checkout the android compose app that I've posted on github recording the game play for tictactoe game.