When I try to launch a Vr project from Unreal Engine 4.7 to my Oculus Quest 2 I the following error:
The following annotation processors are not incremental: lifecycle-compiler-2.0.0.jar (androidx.lifecycle:lifecycle-compiler:2.0.0).
LogPlayLevel: Make sure all annotation processors are incremental to improve your build speed.
LogPlayLevel: Error: Z:appsrcmainjavacomepicgamesue4GameActivity.java:556: error: variable PackagedForOculusMobile is already defined in class GameActivity
LogPlayLevel: public boolean PackagedForOculusMobile = false;
LogPlayLevel: ^
LogPlayLevel: Error: Z:appsrcmainjavacomepicgamesue4GameActivity.java:559: error: method AndroidThunkJava_IsOculusMobileApplication() is already defined in class GameActivity
LogPlayLevel: public boolean AndroidThunkJava_IsOculusMobileApplication()
LogPlayLevel: ^
LogPlayLevel: Error: Z:appsrcmainjavacomepicgamesue4GameActivity.java:2840: error: variable hasVR is already defined in method onCreate(Bundle)
LogPlayLevel: boolean hasVR = false;
LogPlayLevel: ^
LogPlayLevel: Error: Z:appsrcmainjavacomepicgamesue4GameActivity.java:2842: error: variable vrIntent is already defined in method onCreate(Bundle)
LogPlayLevel: Intent vrIntent = new Intent(Intent.ACTION_MAIN, null);
LogPlayLevel: ^
LogPlayLevel: Error: Z:appsrcmainjavacomepicgamesue4GameActivity.java:2847: error: variable pkgManager is already defined in method onCreate(Bundle)
LogPlayLevel: PackageManager pkgManager = getApplicationContext().getPackageManager();
LogPlayLevel: ^
LogPlayLevel: Error: Z:appsrcmainjavacomepicgamesue4GameActivity.java:3241: error: cannot find symbol
LogPlayLevel: powerManager.addThermalStatusListener(getMainExecutor(), new PowerManager.OnThermalStatusChangedListener() {
LogPlayLevel: ^
LogPlayLevel: symbol: class OnThermalStatusChangedListener
LogPlayLevel: location: class PowerManager
LogPlayLevel: Note: Some input files use or override a deprecated API.
LogPlayLevel: Note: Recompile with -Xlint:deprecation for details.
LogPlayLevel: 6 errors
LogPlayLevel: > Task :app:compileDebugJavaWithJavac FAILED
LogPlayLevel: FAILURE: Build failed with an exception.
LogPlayLevel: * What went wrong:
LogPlayLevel: Execution failed for task ':app:compileDebugJavaWithJavac'.
LogPlayLevel: > Compilation failed; see the compiler error output for details.
LogPlayLevel: * Try:
LogPlayLevel: 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.
LogPlayLevel: * Get more help at https://help.gradle.org
LogPlayLevel: BUILD FAILED in 21s
LogPlayLevel: 32 actionable tasks: 3 executed, 29 up-to-date
LogPlayLevel: Error: ERROR: cmd.exe failed with args /c "D:DokumenteUnreal ProjectsVR2IntermediateAndroidarmv7gradlerungradle.bat" :app:assembleDebug
LogPlayLevel: (see C:Users...AppDataRoamingUnreal EngineAutomationToolLogsC+Program+Files+Epic+Games+UE_4.27Log.txt for full exception trace)
LogPlayLevel: AutomationTool exiting with ExitCode=1 (Error_Unknown)
LogPlayLevel: Completed Launch On Stage: Deploy Task, Time: 33.269529
LogPlayLevel: BUILD FAILED
PackagingResults: Error: Launch failed! Unknown Error
I use Java Version 8 right now but I also tried other versions. For example when I use Version 15 I get the error "Could not initialize class org.codehaus.groovy.reflection.ReflectionCache". I also tried it with different versions of the SDK, but nothing seems to work.
3
Answers
Android Studio comes with a version of Java I have used successfully to overcome the error you describe.
In UE4 Project Settings | Platforms | Android SDK you will see a field called "Location of JAVA." For my installation the path to Android Studio’s JRE is
C:/Program Files/Android/Android Studio/jre/
Notice that UE4 uses / instead of even on Windows.
Get rid of all independent versions of Java JDK/JRE. Only use what Android Studio provides.
Android Studio comes with a version of OpenJDK/JRE, sufficient for most Java requirements.
Also, Gradle is an issue, too. Unreal Engine installs this upon launch/packaging your game/app. If you don’t have the "exact" prerequisites, Gradle tries to download what it thinks the SDK and build tools should be, upon compiling and launching your project, and does this regardless of what Android Studio SDK and build tools you have. If you don’t get the prereqs right, it causes a mess of errors. It’s SUPER annoying.
Use the latest Unreal Engine Version 4.27.2.
It’s much more up to date and compatible with VR projects.
As of this writing, there are a LOT newer versions of Android Studio, OpenJDK, Build-Tools and SDKs, NDKs, but Unreal Engine 4.27.2 REQUIRE the outdated versions. This is also partly due to the outdated version of Gradle that the engine itself installs, which is 6.1.1 (not current version 7.3.3), and is installed automatically at compile/launch/package of project, and then tries to install even more outdated prereqs that just don’t work.
Unreal Engine 4.27.2 requires the following, which is NOT in the documentation, NOR is it on the Oculus/Meta Quest documentation. In order to launch VR projects on Quest 2, that works 100% for my setup, and it’s the ONLY thing that has worked for me, do this:
Obviously make sure you have Unreal Engine 4.27.2 installed.
REMOVE ALL VERSIONS OF JAVA’s JDK if present.
Make sure you ONLY use Android Studio 4.0, remove all other versions.
Android Studio 4.0 can be found here: https://developer.android.com/studio/archive
Accept the license agreement and find the version required.
Leave the installation paths for Android Studio AND the SDK as their defaults. ("C:Program FilesAndroidAndroid Studio" ; "C:Users[YOUR_NAME]AppDataLocalAndroidSdk"), where [YOUR_NAME] is replaced with your actual user name folder.
Set your environment variables. Both "User"(top window) and "System"(bottom window) for JAVA_HOME as "C:Program FilesAndroidAndroid Studiojre" without the quotes.
(This is also the path you will use in Unreal Engine for "JDK")
In Android Studio, SDK Manager, SDK Platforms tab, you MUST have "android-29" (Android 10 Q, API Level 29), but you can install as many SDK versions as you want for other Android devices. (Quest and Quest 2 use Android OS 10 Q.)
After that, click on the SDK Tools tab, and check the box for "Show Package Details".
You MUST have Android SDK build-tools version "29.0.3" AND NO OTHER VERSION!
(Though Gradle STILL might try to install build-tools 29.0.2 at launch, but at least it won’t affect the launch this time, which is the important thing.)
You MUST have NDK version "r21d", which is "21.4.7075529" in the list.
You need the "latest" Android SDK Command-Line Tools (version 5.0).
You MUST have CMake version "3.10.2.4988404".
You MUST have the Android SDK Platform-Tools.
Add the Android Emulator, and if you have an AMD processor, install the hypervisor driver for it. If you have an Intel processor, install the "Intel X86 Emulator Accelerator".
The "Google Play" stuff, you may or may not need if you are planning on making apps for other devices, but for the Quest/Quest2, it’s not required.
Click on Apply, let everything download and finish, then click finish/close.
REBOOT.
Go to the Unreal Editor’s install location. Under "UE_4.27 > Engine > Extras > Android", execute the SetupAndroid.bat file. It "should" complete successfully. When it does, press any key to close the window.
Open an existing Unreal project or start a new one. (For the sake of this answer, we’re gonna say start a new one using "Games > Virtual Reality", as this has most of the options we need out of the box. Refer to Oculus docs for more information on setting up a new blank project.
IMPORTANT – If you have an existing project:
BEFORE you open it, go into your project folder and DELETE the "Intermediate", "Saved" and "DerivedDataCache" folders.
THEN delete the ".gradle" folder from "C:Users[YOUR_NAME]", replacing [YOUR_NAME] with your actual user name folder.
Optionally, reboot, if you want to, but it’s not necessary.
Location of Android SDK: C:/Users/[YOUR_NAME]/AppData/Local/Android/Sdk
Location of Android NDK: C:/Users/[YOUR_NAME]/AppData/Local/Android/Sdk/ndk/21.4.7075529
Location of JAVA: C:/Program Files/Android/Android Studio/jre
Obviously change [YOUR_NAME] to your user name folder again, and BE MINDFUL of the slash direction, when pasting the paths into the fields: Use the forward slash " / ".
Under SDK API Level, use "android-29" without the quotes.
Under NDK API Level, use "latest" without the quotes.
Also make sure the "Target API" is set to 29.
Then scroll down to "Build" and make sure "Support arm64" is checked, as the Quest and Quest 2 are 64-bit!
Finally check "Support Vulkan", as Android Vulkan is fully supported and works great on the Q/Q2!
You should be able to follow the rest of the docs on the official pages from here without much issue.
In the view port, under "Settings > Preview Rendering Level", choose "Android Vulkan". This will let you see, more or less, what the game will look like on the Quest/Quest2, while you work on it in the viewport. Let all shaders compile.
Finally, make sure your Quest/Quest2 is set up to launch the game, and go ahead and select it and LAUNCH! It should launch/package successfully.
This has been a 2 day journey for me, and I have been through TONS of solutions that have not worked for me at all. Ultimately, I had to figure this out myself, and so this is my solution. I sincerely hope it helps somebody. It works for me, so I am off to the races with my VR projects!
Epic needs to pick better back ends to use to compile Android apps. Gradle is the number 1 issue preventing MANY people from compiling their apps. My solution plays nice with Gradle, and the Unreal Engine, and OLD STANDALONE JAVA VERSIONS BEGONE!
Finally as a bonus, if you use Godot, you’ll also have no issues as well. Just use the same Android SDK folder path (UNHIDE the "AppData" Folder) for that and you’re all set.
Thank you,
X
If all that fails, make sure "INCLUDE DEBUG FILES" is enabled under packaging. Sometimes it’s the simplest things. Everything else is right. With that disabled you will get the same error.