Skip to content

Fixed – Unity build failure: Cannot access output property ‘soFolder’ of task ‘:unityLibrary:buildCMakeRelWithDebInfo[armeabi-v7a]’.

Error

Cannot access output property 'soFolder' of task ':unityLibrary:buildCMakeRelWithDebInfo[armeabi-v7a]'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by using Task.doNotTrackState(). For more information, please refer to https://docs.gradle.org/8.11/userguide/incremental_build.html#sec:disable-state-tracking in the Gradle documentation. See the Console for details.

You can fix this permanently by using Unity’s Custom Main Gradle Template. Here is how to set it up:

1. Enable the Custom Template

  1. In the Unity Editor, go to Edit > Project Settings.
  2. Select Player on the left menu, then click on the Android tab (the little Android icon).
  3. Expand the Publishing Settings section.
  4. Scroll down to the Build list and check the box for Custom Main Gradle Template.

(Note: When you check this box, Unity automatically generates a file named mainTemplate.gradle in your project’s Assets/Plugins/Android/ folder.)

2. Add the Fix to the Template

  1. Open your project folder in your computer’s file explorer.
  2. Navigate to Assets/Plugins/Android/ and open the mainTemplate.gradle file in a code or text editor (like VS Code or Notepad).
  3. Scroll to the very bottom of this file, paste the exact same snippet, and save the document:

Gradle

// Workaround for Gradle 8+ state tracking issues with Unity CMake tasks
tasks.configureEach { task ->
    if (task.name.startsWith("buildCMake")) {
        task.doNotTrackState("Fix for unreadable soFolder inputs in Unity CMake tasks")
    }
}

Now, whenever you build an APK, an AAB, or export the project, Unity will automatically inject this workaround into the generated unityLibrary/build.gradle file. This prevents Gradle 8.x from blocking your build without you having to patch it manually every time.

See also  How to create In-App Updates for Android in C# Unity

You should place the snippet at the absolute bottom of the file, i.e, on a new line after **EXTERNAL_SOURCES** (which is usually the last line in that file).

Those words surrounded by asterisks (like **IL_CPP_BUILD_SETUP**) are special variables. When you hit “Build,” Unity searches the file for those specific markers and replaces them with its own generated code.

If you put your custom Gradle snippet in the middle of those markers, it could accidentally break the code Unity is trying to inject. By placing your code at the very end of the file, after all the **MARKER** variables, you guarantee it runs safely after Unity has finished setting up the rest of the build script.

Here is what the very bottom of your mainTemplate.gradle file should look like:

Gradle

    **IL_CPP_BUILD_SETUP**
    **SOURCE_BUILD_SETUP**
    **EXTERNAL_SOURCES**

    // Workaround for Gradle 8+ state tracking issues with Unity CMake tasks
    tasks.configureEach { task ->
        if (task.name.startsWith("buildCMake")) {
            task.doNotTrackState("Fix for unreadable soFolder inputs in Unity CMake tasks")
        }
    }

Discover more from Knowledge sparks

Subscribe to get the latest posts sent to your email.

Leave a Reply

error: Content is protected !!