[Solved] UE4 Android Package Error: cmd.exe failed with args

Edition:

UE4.27.2, Android Studio 4.0, Window system

Error content:

ERROR: cmd. exe failed with args /…….

Execution failed for task ‘:app:compileDebugJavaWithJavac’

> Compilation failed; see the compiler error output for details.

Solution:

This type of error reporting is general, JAVA-related error reporting, the red letter will only give cmd.exe failed with args, only search the line of error is unable to find the problem.

Error log to turn up, find * What went wrong:, the next two lines of the line is the real content of the error report.

In my personal case, the specific error is

Execution failed for task ‘:app:compileDebugJavaWithJavac’.

> Compilation failed; see the compiler error output for details.

The problem is caused by the inconsistency between the JDK version selected by UE4 and the JDK version in the system environment variable, either modify the JDK version selected by UE4 or modify the system environment variable.

The former: Edit->Project Settings->Android SDK->Location of JAVA, select the same JDK directory as your environment variable, and go to Edit->Project Settings->Android, you need to click Configure Now again.

The latter: open the system environment variables, find JAVA_HOME in the system variables, edit and modify it to the JDK version selected by UE4; find Path, double click to open it, find C:\Program Files (x86)\Common Files\Oracle\Java\javapath this line, copy the address, open it in the folder and delete the 3 JAVA files in it. Finally, open CMD and type java -version to test if the replacement has been completed.

Read More: