hello everyone I had the same problem in ue5.1 and I solved it.
- make sure that you are using JDK 8u77 (1.8.0_302) also check that its JDK, not JRE
-make sure that you set JAVA_HOME and ANDROID_HOME
-make sure that you are using android studio 4.0 - Use NDK 25.1.8937393 for unreal
-here are some images of my settings




