How to fix ''Gradle Build Failed'' on Unity?
Asked Answered
L

13

8

I'm trying to build my android app for a while and can't seem to find any solution for this problem: Image

Unity Version: Unity 2020.3.21f1 (64-bit) JDK, SDK, NDK and Gradle used are Unity's recommended ones (already tried to use other ones).

The console details are here:

Configure project :launcher
WARNING: The option setting 'android.enableR8=false' is deprecated.
It will be removed in version 5.0 of the Android Gradle plugin.
You will no longer be able to disable R8

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)`

    FAILURE: Build failed with an exception.

    * What went wrong:
    com/sun/istack/FinalArrayList
    
    * Try:
    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.

    CommandInvokationFailure: Gradle build failed. 
    C:\Program Files\Unity\Hub\Editor\2020.3.21f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2020.3.21f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
    
    stderr[
    
    FAILURE: Build failed with an exception.

    Build completed with a result of 'Failed' in 60 seconds (59527 ms)
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

UnityEditor.BuildPlayerWindow+BuildMethodException: 4 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002ca] in <208f92fc783546f9abbe643bfc23920c>:0 
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <208f92fc783546f9abbe643bfc23920c>:0 
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

I already tried all tutorials on youtube and other forums, but every help is welcome, thanks!

Edit 1:

After trying Jaimin's solution this is happening now:

Assets/Plugins/Android\gradleTemplate.properties file is using a deprecated way of controlling which tool should be used to do the minification. To fix this, remove "useProguard" entries yourself. If not fixed, your build can fail.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)


 File C:\Users\Windows\.android\repositories.cfg could not be loaded.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

FAILURE: Build failed with an exception.

* What went wrong:
com/sun/istack/FinalArrayList
> com.sun.istack.FinalArrayList

* Try:
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.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

CommandInvokationFailure: Gradle build failed. 
C:\Program Files\Unity\Hub\Editor\2020.3.21f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2020.3.21f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[

FAILURE: Build failed with an exception.

* What went wrong:
com/sun/istack/FinalArrayList
> com.sun.istack.FinalArrayList

* Try:
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.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
]
stdout[
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.Command.Run (System.String command, System.String args, System.String workingdir, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1[T] progress, System.String error) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <f94168442e634613b6a5965ed17c38f4>:0)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1[T] progress) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <f94168442e634613b6a5965ed17c38f4>:0)
Rethrow as BuildFailedException: Exception of type 'UnityEditor.Build.BuildFailedException' was thrown.
UnityEditor.Android.PostProcessor.CancelPostProcess.AbortBuild (System.String title, System.String message, System.Exception ex) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <f94168442e634613b6a5965ed17c38f4>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <208f92fc783546f9abbe643bfc23920c>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Build completed with a result of 'Failed' in 127 seconds (127448 ms)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

UnityEditor.BuildPlayerWindow+BuildMethodException: 5 errors
  at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002ca] in <208f92fc783546f9abbe643bfc23920c>:0 
  at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <208f92fc783546f9abbe643bfc23920c>:0 
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

And here's how the Custom Gradle Properties Template file is coded:

org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
unityStreamingAssets=.unity3d**STREAMING_ASSETS**
**ADDITIONAL_PROPERTIES**
Landaulet answered 30/10, 2021 at 1:25 Comment(0)
R
11

This is because android.enableR8 is deprecated. To remove it from your gradle.properties file you have to go to Project Settings > Player > Android (Tab) > Publishing Settings > Custom Gradle Properties Template check this.

After that, a gradleTemplate.properties file is generated at:

Assets/Plugins/Android/gradleTemplate.properties

In this file, remove line android.enableR8, or comment it out, and now make new fresh build.

This trick should work.

Alternatively, export as an Android project and then change it in Android Studio. In Android Studio, you have more control on these things.

Ruthie answered 30/10, 2021 at 4:38 Comment(5)
Hello, thanks for the reply. I tried it and there are some new errors now, I added them to the question text above.Landaulet
try exporting android project and then edit it in android studioRuthie
thank you give me hint its not work for me but I deleted all files of \Assets\Plugins\Android folder even deleted all "gradleTemplate.properties" prefix files after that I copied files from the original or my old backup folder. Which works for me!Treasonous
This is now under Project Settings > Player > Android (Tab) > Publishing Settings > Custom Gradle Properties Template.Calf
Hi, i am doing what you said but it is automatically added to the file again after removing android.enableR8Nitrochloroform
K
1

I have seen in a lot of places and the issue is really painfull. In my case, my problem it was that there was an old CSharp interface of mine incorrect that wasn't in my csproj, so I couldn't see in my Visual Studio.

As Unity doesn't care about csproj, it uses it in compilation. I just noticed because of an inexistent java issue shown in Console window (because of Android, the CSharp was converted to Java and for this reason Graddle threw the issue).

Try to find in your CSharp program some class that doesn't appear in Solution Explorer in Visual Studio and remove or fix it.

Also, I followed the fix indicated above by Jaimin. It didn't work for me, but I left like that. It makes way more sense with it.

Kind answered 5/5, 2022 at 2:9 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewGlue
H
1

I solved this problem simply by migrating to Unity 2022.2

Hiatt answered 5/3, 2023 at 6:17 Comment(0)
G
1

I upgraded my target (Android) API level to 34 in the Player Settings -> Player -> Other settings. This installed a new version of Android SDK API and everything worked. The way I found this out was by just clicking every possible API version until one works.

Gaye answered 19/11, 2023 at 20:3 Comment(1)
This was the most helpful comment among all, everything works now, thank you!Wideopen
H
0

Install a new version of Unity, it will work

You can use the Unity 2020.3.33f1 version, that's the one I use, and it works fine.

Remember to set to Preferences: Unity default JDK, Gradle, NDK

Henriettehenriha answered 19/4, 2022 at 23:20 Comment(2)
Is there a specific, minimum version of Unity that they need to install? Without this, it doesn't seem like a very helpful answer. And especially when there's another answer that has been validated by the community that offers specific guidance.Corbitt
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Comprador
H
0

Try This For Windows go to the location

"C:\Program Files\Unity\Hub\Editor\2021.1.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\31.0.0"

find a file named d8.bat. This is a Windows batch file.

rename d8.bat to dx.bat.

in the folder lib ("C:\ProgramFiles\Unity\Hub\Editor\2021.1.24f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\31.0.0\lib")

rename d8.jar to dx.jar Remember AppData is a hidden folder. Turn on hidden items to see the AppData folder.

Now run your project...

From ELNexs https://forum.unity.com/threads/gradle-error-problem-with-gradle-build.538320/

Heliogabalus answered 18/2, 2023 at 20:16 Comment(0)
L
0

Try making it generate a new keystore.

  • Close Unity
  • Browse to C:\Users\Username\.android
  • Move or delete the debug.keystore/lock
  • Build should be successful
Lim answered 7/4, 2023 at 21:3 Comment(0)
H
0

I solved the same problem by checking the keystore's password in Publishing Settings under Player Settings.

Player Settings > Publishing Settings > Project Keystore/Key Password check

Hedvige answered 17/5, 2023 at 14:46 Comment(0)
L
0

After changing Minimum Api level 24 to 32....Now its Resolved....

File > Build Settings > Player settings > Player > other > Minimum API level 32

Labret answered 11/12, 2023 at 18:43 Comment(0)
B
0

I upgraded the product from unity 2020.3.9f1 to 2022.3.16f1, unchecked everything under the "build" like the custom main manifest. Re importer the admob plugin and resolved then i checked only the "custom main gradle template" and the "custom gradle properties template" resolved again and started the build.

The build was successful but the ads won't show.

Beesley answered 9/1 at 18:32 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Comprador
C
0

I swtich Minimum API Level to the Level 34, then upgrade Android SDK, then swtich back to Level 26, it works fine ~

File > Build Settings > Player settings > Player > other > Minimum API level 32

Carrizales answered 28/2 at 6:2 Comment(0)
B
0

API level to 34 in the Player Settings -> Player -> Other settings. This installed a new version of Android SDK API and everything worked this is best. when changed to alt level 34 and then click to build unity will give option to upgrade and click on upgrade and it will take some time but it works

Bushweller answered 19/3 at 4:47 Comment(0)
B
0

Try Changing the security of your user folder. YourDrive > Users > YourName. then right click > properties > security then check modify, that should work.

Bogard answered 26/3 at 16:21 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Comprador

© 2022 - 2024 — McMap. All rights reserved.