After 2 days of trying multiple things, I finally was able to make an APK for Android!! I just want to share this step-by-step in case of someone has the same problem. Also the documentation is here for reference: https://docs.unrealengine.com/5.1/en-US/how-to-set-up-android-sdk-and-ndk-for-your-unreal-engine-development-environment/
1 - Uninstall Android Studio and install Android Studio 4.0 from May 28, 2020 (yes it only works with this version, this was the biggest problem! )
2 - Set the environment variables for ‘JAVA_HOME’ to use the java version inside the android studio 4. ( inside the install folder from Android Studio there is a folder ‘jre’, with java version 1.8.0_242 , that’s the only version that works! )
3 - when installing the SKD, make sure to install the ‘Android SDK Command-line Tools’ version 8.0 (this is the only version that works. do not install other versions. On the documentation there is a print screen with step-by-step)
4 - Download the NDK r25b version (this version is the ‘25.2.9519653’, do not download other versions!)
5 - modify the ‘SetupAndroid.bat’ file that is inside ‘C:/Program Files/Epic Games/UE_5.1/Engine/Extras/Android/SetupAndroid.bat’ . Change the line that says ‘cmdline-tools\latest’ to ‘cmdline-tools\8.0’ . (this file is inside the Unreal installation directory )
6 - open the cmd and run ‘D:\ANDROID_UNREAL\SDK\tools\bin\sdkmanager.bat --licenses’ ( replace ‘D:\ANDROID_UNREAL’ with the directory you saved the SDK! Its normally ‘C:\Users\MyUserName\AppData\Local\Android’ )
7 - Inside Unreal, on the options:
- chose ‘Target SDK version’ to ‘30’ (won’t work with any version below 30)
- chose ‘minimum SDK version’ to ‘26’
- chose ‘SDK API Level’ to ‘30’
- chose ‘NDK API Level’ to ‘latest’ (this one will only work with ‘latest’ if you ONLY download the correct version which is ‘25.2.9519653’)
(change the location with the location on your computer)

----- x -----
While many attempts with the wrong configurations, I received the ‘BUILD FAILED’ many times. I will write here the error messages just to help people google this forum!
When you try to package the project for Android:
UATHelper: Packaging (Android (ASTC)): Making .apk with Gradle…
UATHelper: Packaging (Android (ASTC)): To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: The Gradle Daemon.
UATHelper: Packaging (Android (ASTC)): Daemon will be stopped at the end of the build stopping after processing
UATHelper: Packaging (Android (ASTC)): java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
PackagingResults: Error: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7
UATHelper: Packaging (Android (ASTC)): Caused by: java.lang.ExceptionInInitializerError: Exception org.codehaus.groovy.GroovyBugError [in thread “Daemon worker”]
PackagingResults: Error: Exception org.codehaus.groovy.GroovyBugError [in thread “Daemon worker”]
UATHelper: Packaging (Android (ASTC)): … 128 more
UATHelper: Packaging (Android (ASTC)): FAILURE: Build failed with an exception.
UATHelper: Packaging (Android (ASTC)): * What went wrong:
UATHelper: Packaging (Android (ASTC)): Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
UATHelper: Packaging (Android (ASTC)): > Exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 [in thread “Daemon worker”]
UATHelper: Packaging (Android (ASTC)): * Try:
UATHelper: Packaging (Android (ASTC)): Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
UATHelper: Packaging (Android (ASTC)): * Get more help at https://help.gradle.org
UATHelper: Packaging (Android (ASTC)): BUILD FAILED in 5s
PackagingResults: Error: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 [in thread “Daemon worker”]
UATHelper: Packaging (Android (ASTC)): ERROR: cmd.exe failed with args /c “C:\MyGame\Intermediate\Android\arm64\gradle\rungradle.bat” :app:assembleDebug
UATHelper: Packaging (Android (ASTC)): (see C:\Users\MyUserName\AppData\Roaming\Unreal Engine\AutomationTool\Logs\E+UnrealEditor+UE_5.1\Log.txt for full exception trace)
PackagingResults: Error: cmd.exe failed with args /c “C:\MyGame\Intermediate\Android\arm64\gradle\rungradle.bat” :app:assembleDebug
UATHelper: Packaging (Android (ASTC)): AutomationTool executed for 0h 0m 52s
UATHelper: Packaging (Android (ASTC)): AutomationTool exiting with ExitCode=1 (Error_Unknown)
UATHelper: Packaging (Android (ASTC)): BUILD FAILED
PackagingResults: Error: Unknown Error
when you run ‘sdkmanager.bat --licenses’ with a Java version different than ‘1.8.0_242’ :
Exception in thread “main” java.lang.UnsupportedClassVersionError: com/android/prefs/AndroidLocationsProvider has been compiled by a more recent version of the
Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
