Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug Unity Build fails for no reason

Discussion in 'Editor & General Support' started by kasym_, Sep 11, 2023.

  1. kasym_

    kasym_

    Joined:
    Oct 18, 2022
    Posts:
    11
    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?

    upload_2023-9-11_17-17-9.png
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,535
    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.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,067
    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.

    https://forum.unity.com/threads/cant-build-for-android.1306098/

    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...):

    https://forum.unity.com/threads/aab...y-2021-3-8-with-jdk-1-8.1322211/#post-8551193

    Android Gradle errors and other related stuff:

    https://forum.unity.com/threads/unity-gradle-bug-please-help.1368018/#post-8625789
     
  4. kasym_

    kasym_

    Joined:
    Oct 18, 2022
    Posts:
    11
    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
     
    Last edited: Sep 12, 2023
  5. kasym_

    kasym_

    Joined:
    Oct 18, 2022
    Posts:
    11
    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
     
  6. kasym_

    kasym_

    Joined:
    Oct 18, 2022
    Posts:
    11
    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
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,067
    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... :/
     
  8. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    8,218
    Editor versions are all installed separately. Then, you update a project by changing it's version in the Unity Hub and then opening it.
     
  9. kasym_

    kasym_

    Joined:
    Oct 18, 2022
    Posts:
    11
    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/`
     
  10. mahito2932

    mahito2932

    Joined:
    Nov 15, 2020
    Posts:
    117
    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.
     
  11. kasym_

    kasym_

    Joined:
    Oct 18, 2022
    Posts:
    11
    You can also use clean build, this way it doesn't fail
     
  12. mahito2932

    mahito2932

    Joined:
    Nov 15, 2020
    Posts:
    117
    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