Gradle build fails only when building many assets using 'BuildPipeline.BuildPlayer'

I have a Unity project I build via the command line using ‘BuildPipeline.BuildPlayer’, specifically as part of my CI solution, and I have run into a frustrating error when attempting to build the Android version of my project this way.

What makes this frustrating is that when I manually build the project from within the editor, it builds just fine. This is with Unity version 2021.1.5f1.

I have attached the 3 errors that I get when attempting to build via ‘BuildPipeline.BuildPlayer’.
The relevant errors as far as I can tell are as follows:

WARNING: The option 'android.enableR8' is deprecated and should not be used anymore.
It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8.
...
> Task :launcher:mergeDexRelease
> Task :launcher:packageRelease
> Task :launcher:packageRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':launcher:packageRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > value (4392877980) > 0x00000000ffffffffL
CommandInvokationFailure: Gradle build failed.
C:\Program Files\Unity\Hub\Editor\2021.1.5f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK\bin\java.exe -classpath "C:\Program Files\Unity\Hub\Editor\2021.1.5f1\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-5.6.4.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"

stderr[
Note: C:\Users\Administrator\Desktop\TestBuild\Temp\gradleOut\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:packageRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > value (4392877980) > 0x00000000ffffffffL

The project uses AddressableAssets and has many sprites. For this reason, I thought it may be this bug reported here. However, I do not see more than 680 assets in my StreamingAssets folder. Although AddressableAssets could be deleting them after it is finished. Unfortunately, the suggested workaround in the comments did not work.

I have tried building on a clean machine with a clean install and even tried moving the assets over to a new project. The code-only builds fine, but it breaks when I add all the assets. I have tried some suggested Gradle options for similar issues, but those didn’t seem to have any noticeable effect.

Any advice on if this is a known Unity bug or if there’s a workaround would be appreciated.

7099807–846151–GradleDaemonError.txt (3.38 KB)
7099807–846154–GradleException.txt (1.04 KB)
7099807–846157–GradleFailureSummary.txt (7.59 KB)

Has anyone experienced the same issue, or does anyone have an update on this?
It really breaks our CI pipeline.

Try exporting gradle project instead and inspect gradle.properties, see how many entries there are for unityStreamingAssets property

Thanks for the response.
I decided to wait until 2021.1.9f1 was released, as that bug report was supposed to be fixed in that version, but I am still running into the issue.

Do you have any other tips that I could use to help debug this issue?