Unity Build fails for no reason

I have this weird behavior in Unity 2022.3.4f1 My project does not have any compile error or so, and builds fine. However, after I build my app 2-3 times, it just says that my build is failed without giving me any clue as to what’s happening.
I found a workaround, right-click on the Assets folder in the Project window and Reimport All Assets.
Then it again builds okay for 2-3 times until it starts to fail again.

Anyone has an idea how to resolve this?

Check the editor.log for any clues after a failed build, or post it here.

Since reimport all fixes it, try deleting the Library folder (close the project before you do). This truly reimports everything from scratch.

You could also try the latest patch version, 2022.3.9 I think.

How to troubleshoot build failures:

First, make a blank project with a single blank scene and prove that it builds successfully.

If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

Until you can build a blank project to the target platform, don’t fiddle with anything else.

Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

Most often things that prevent building are third-party libraries such as Firebase.

Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

Android build not building:

Recently (circa July 2022) there have been reports of Unity’s installer failing to install the Android Tools.

Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022 (edited on August 23, 2023 to include Android SDK 33…):

Android Gradle errors and other related stuff:

Is there a way to update my editor version? Or do I have to download the latest version?
I looked in the editor, it seems like it is installing the new version instead of updating the present one

The thing is that the project builds fine for the first 2-3 times and then fails (even if I don’t change anything). It wasn’t like that before

How many times do I have to build a blank project to reproduce that behavior?.. I don’t think that it is a time efficient solution

Could you please tell me the location of the file? I checked the Logs folder but I didn’t see a file with the same name as you specified

Okay, that’s downright annoying. I’ve seen that a few times.

Here is a faster way to reimport all which might work for you when the build fails:

  • exit Unity
  • within your project delete Library/ScriptAssemblies/
  • reopen and observe it recompile

If that doesn’t do it, then try adding this step too:

  • within your project Library/ folder delete things like the ShaderCache and the IL2CPP Cache

That’s at least faster than reimport all… :confused:

Editor versions are all installed separately. Then, you update a project by changing it’s version in the Unity Hub and then opening it.

This build error happens only when I use IL2CPP, if I switch to Mono it is building fine.
I thought maybe indeed it has something to do with the IL2CPP Cache, but I couldn’t find the folder inside the Library/

Indeed it’s only happening with IL2CPP… Literally to make a second build i need to remove all IL2CPP and BEE folder from Library. It’s the same for me the first build is fine. Second always fail.

You can also use clean build, this way it doesn’t fail

I did clean build no effect at all until I don’t delete everything manually.
For example now i have building errors if i do clean build it will do nothing if i start delete everything manually it build successfully so i need to do this every time that i need a second build