The newer sdkmanager from the Command-Line Tools package now supports JDK versions newer than 8: https://stackoverflow.com/a/65782803/1268612
Would be good to switch to the new JDK 18 and the new command-line sdkmanager.
There's an example here that may be helpful in getting this set up:
https://github.com/karlhorky/android-rs-examples/blob/2eac6325a61980657d1952fe430619aaf1776c01/hello-world-no-studio/download.sh
Related: Also opened this over here: edvinasbartkus/react-native-detox-github-actions#22