Unity batch mode process freezes for Android builds

We moved to 2020.3.2f1 and are trying to fix our Intel Mac mini build machine.

iOS builds and is playable; however, the android build just freezes ever since updating Unity.

I can open the project in the editor and build and run on the build machine.

Occasionally I connect to the build machine and see a system dialog ‘Unity Hub wants to make changes’. It’s not supposed to be showing dialogs in batchmode.

Here is the command line I am using to test:

/Applications/Unity/Hub/Editor/2020.3.2f1/Unity.app/Contents/MacOS/Unity -projectPath /Users/teamviewer/builds/AbxzEpLH/0/thisco/myprojectname -executeMethod BuildCommand.BuildAndroidDevelopmentRemote -buildTarget Android -batchmode

I can confirm that 2020.3.2f1 is the correct version of unity.

There is no error message.

Here is a tail of the log:

Unloading 2969 unused Assets to reduce memory usage. Loaded Objects now: 23260.
Total: 1760.862750 ms (FindLiveObjects: 6.199505 ms CreateObjectMapping: 5.160122 ms MarkObjects: 1737.530675 ms  DeleteObjects: 11.969555 ms)
Unloading 0 Unused Serialized files (Serialized files now loaded: 0)
Loaded scene 'Temp/__Backupscenes/0.backup'
    Deserialize:            3.134 ms
    Integration:            221.335 ms
    Integration of assets:  0.006 ms
    Thread Wait Time:       21.093 ms
    Total Operation Time:   245.568 ms
System memory in use before: 0.94 GB.
System memory in use after: 0.94 GB.
Unloading 0 unused Assets to reduce memory usage. Loaded Objects now: 23252.
Total: 1443.301999 ms (FindLiveObjects: 5.859550 ms CreateObjectMapping: 3.460020 ms MarkObjects: 1433.910639 ms  DeleteObjects: 0.068975 ms)
[Project] Loading completed in 713.512 seconds
    Project init time:                 0.000 seconds
        Template init time:         0.000 seconds
        Package Manager init time:         0.000 seconds
        Asset Database init time:         0.000 seconds
        Global illumination init time:     0.000 seconds
        Assemblies load time:             0.000 seconds
        Unity extensions init time:     0.000 seconds
        Asset Database refresh time:     0.000 seconds
    Scene opening time:             589.731 seconds
Subscribe to USB device events
[00:00:01] Enlighten: Builtin Sky manager started.
[MODES] ModeService[none].Initialize
[MODES] ModeService[none].LoadModes
[MODES] Loading mode Default (0) for mode-current-id-BadEnergyKids
[00:00:02] Enlighten: Finished 1 Bake Ambient Probe job (0.01s execute, 0.00s integrate, 0.44s wallclock)

Here is our build command

    private static void BuildAndroid(bool development, bool localBuild,
        BuildOptions options = BuildOptions.None, AndroidArchitecture deviceTarget = AndroidArchitecture.All, bool isaab = false) {
        string[] scenes = GetBuildScenes();

        string path = GetBuildPath("android");

        if (scenes == null || scenes.Length == 0 || path == null) {
            return;
        }

        ApplyAndroidBuildSettings(development, localBuild, deviceTarget,isaab);

        BuildPipeline.BuildPlayer(scenes, path, BuildTarget.Android, options);
    }
   
    public static void BuildAndroidDevelopmentRemote() {
        EditorUserBuildSettings.buildAppBundle = false;
        BuildAndroid(true, false, BuildOptions.None, AndroidArchitecture.ARMv7 | AndroidArchitecture.ARM64);
    }

Same issue here on Mac, any solution?

Baking can take a spectacularly long amount of time, hours and hours even. Since the last entry is enlighten, that would be my first investigation. Bake all your lights or simply disable all baked lighting, try to build.

OTHERWISE…

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: