Unreal 5.1 package project for Android error org.codehaus.groovy.vmplugin.v7.Java7 and java.lang.UnsupportedClassVersionError

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)

image

image

----- 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

10 Likes

Thank you. Unfortunately, you can not do everything this way. For example, there are no command tools in version 8 to choose from. There is only “latest” in the menu. With this it also works. What is important to fix this bug is the right Java version. If you already have another installed you have to enter the jre of Android Studio 4.0 in “Location of Java” (see screenshot above). For me it was: C:\Program Files\Android\Android Studio\jre

1 Like

My goodness THANK YOU! I have been trying to get past this for two weeks now. After uninstalling URE5 and all Android studio. Fresh start it worked. I didn’t have to change the sdkmanager.bat file at all? I don’t understand why it gives you all that in the Unreal Documentation? Anyways thanks again!

Thank you so much! :joy:

Hello, thank you for this very helpful information. After successfully packaging and installing the apk in UE 5.1 in all 4 formats (ASTC, DXT, ETC2, & MULTI) and within all 4 binary configurations (DebugGame, Development, & Shipping) the app crashes a few seconds after it is loaded on my android device = Lenovo MH10 with Android 10 OS.

Would you happen to know if there are any other settings that should be checked in order to resolve this issue?

salute. After a week of head-scratching, your way solved my issue :+1:

Thank you!

Had to download JDK 8.0.382 from azul and it finally worked.

Hello, thank you so much for this post. Certinely has saved me a lot of time! Unfurtantly even though i followed the steps i still get an error saying

“ERROR: Android toolchain NDK r25c not supported; please use NDK r21 to NDK r23 (NDK r21b recommended)”

Now i can install the older NDK and get further, but then run in to another issue. Oh though there mus be something else at foot here in my set up as you are successfully compiling with r25B.

Guys, i have found solution which works for me:
-Go to ProjectName\Intermediate\Android\arm64\gradle\gradle\wrapper
-there you locate gradle-wrapper.properties
-Open it in text file and at the bottom of the file there should be: “distributionUrl=https://services.gradle.org/distributions/gradle-version-all.zip”
There you need to look at the version of gradle it uses.
-go to Gradle | Releases.
-locate your version of gradle and click on “User manual”
-on the left side click on “Compatibility notes”
-There you will find what java version it requires to run gradle
-Download that version of java and install it inside AndroidStudio jre file
-Package it/Deploy it on your android phone and play

My version of unreal is 5.1.1, gradle version is 6.1.1 and java version is 13.0.2

2 Likes

thanks. that was truly helpful.
just in case, im using 5.2 and 5.3 and you can go down to sdk 29 (thank god, since htc vive has that as maximum).
i use ndk : android-29 and sdk “matchndk”
also ive been using ndk 25.1.89xxxx for a long time. i think that’ s the one listed in the android setup script so i left that one.
i found the jdk from here are easy to install, just unzip. wonderful for testing. Archived OpenJDK GA Releases
though the ideal is the sdk in the android/jre folder

i ran into this error when compiling in case someone else needs it

htc had some java libraries compiled for v 55 and but java in the android folder is 52.
i found with the previous post and this link that i could use version 11 How to check Java version used to compile a class | dev cases
and that solved my issueS. (god i wish android were simpler).