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: How to Set Up Android SDK and NDK For Your Unreal Engine Development Environment | Unreal Engine 5.1 Documentation
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