Game Dev Cheat Sheet

Build errors

PrecompiledAssemblyException: Multiple precompiled assemblies with the same name 'X' included for the current platform.

The exact message

PrecompiledAssemblyException: Multiple precompiled assemblies with the same name 'X' included for the current platform.
Variants of this message
  • Multiple precompiled assemblies with the same name
  • Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included for the current platform. Only one assembly with the same name is allowed per platform.
  • Only one assembly with the same name is allowed per platform.
  • PrecompiledAssemblyException

What it means

Two or more .dll files with the same assembly name are enabled for the platform you are building, and Unity will not choose between them. The message names the assembly, which is almost always the fastest route to the answer, because it tells you exactly which file to go looking for. This is a project composition problem rather than a code problem: nothing you have written is wrong, you simply have the same library twice.

Causes and fixes

Ranked by how often they actually occur, most common first.

  1. A package includes a library Unity now ships itself

    Newtonsoft.Json is the overwhelmingly common case. Unity ships it as the com.unity.nuget.newtonsoft-json package and several other packages depend on it, so an asset that bundles its own copy of Newtonsoft.Json.dll collides with the one Unity already provides. The error typically appears immediately after importing an asset store package or adding a package that pulls the dependency in.

    The fix: Delete the bundled .dll from the asset that brought it in, and let the Package Manager version be the single copy. Deleting the package-managed one instead does not work, because the Package Manager restores it.

    Source: Unity Discussions: multiple precompiled assemblies, Newtonsoft conflict, GitHub: Newtonsoft.Json.dll duplicate reported against flutter-unity-view-widget

  2. Two asset packages each bundle the same library

    Two unrelated assets that both depend on the same third-party library each ship their own copy, often at different versions and in different folders. Neither is wrong on its own, and the conflict only appears once both are in the project. Analytics, JSON and networking libraries are the usual culprits because so many assets depend on them.

    The fix: Keep one copy and delete the other, preferring the newer version. Test both assets afterwards, because the one whose copy you deleted is now running against a version it was not shipped with, and an API difference will show up at runtime rather than at import.

    Source: Unity Discussions: package conflict, multiple precompiled assemblies

  3. A .dll was duplicated by a copy or a bad merge

    The same file present in two folders, or left behind as a copy such as Newtonsoft.Json 1.dll, counts as two assemblies because Unity reads the assembly name from inside the file rather than from the file name. Merges that add a library in a new location without removing the old one produce this, as does moving a plugins folder by copying rather than moving it.

    The fix: Search the project for the assembly named in the message and delete all but one copy. Searching the file system rather than the Project window is more reliable, because a .dll inside a folder Unity ignores can still be picked up.

    Find every copy of the named assembly before deleting anything.

    # Windows, from the project root
    dir /s /b Newtonsoft.Json.dll
    
    # macOS and Linux
    find . -name "Newtonsoft.Json.dll" -not -path "./Library/*"
    
    # Expect exactly one result outside Library/ and Packages/.
    # Anything under Assets/ that duplicates a Package Manager copy
    # is the one to remove.

    Source: Unity Discussions: PrecompiledAssemblyException from a duplicated dll

  4. Both copies are enabled for the same platform

    Two copies of a library can coexist legitimately when each is restricted to a different platform, which is how some assets ship separate builds for Editor and player, or for Android and iOS. The error appears when their platform settings overlap, so both are included for the target you are building.

    The fix: Select each .dll and check its import settings in the Inspector. Untick the platforms one of them should not apply to, so that exactly one copy is included per platform, rather than deleting a file another platform still needs.

    Source: Unity Manual: Import and configure plug-ins

  5. A version control package supplies a conflicting copy

    Unity's built-in Version Control and Collaborate packages have historically bundled their own copies of shared libraries, which collide with a project that also has one. Because these packages are enabled by default in some project templates, the duplicate can be present without anyone having deliberately added it.

    The fix: Remove the unused package from the Package Manager. If Version Control is not in use, uninstalling it is the cleanest resolution and removes the bundled copy with it.

    Source: Unity Discussions: 2018.3 PrecompiledAssemblyException, Version Control package

How to prevent it

Read the assembly name in the message first. It tells you exactly what to search for, and searching the file system for that name resolves most occurrences in under a minute.

Prefer the Package Manager version of any library Unity distributes. A package-managed copy is restored automatically and updated with the project, so a bundled duplicate under Assets is always the one to remove.

Review what an asset store package adds before importing it, and untick bundled third-party libraries you already have. Unity's import dialog lists every file, and unticking a duplicate at import is far easier than untangling it afterwards.

Do not delete a .dll a second asset still depends on without testing that asset. The conflict is resolved at compile time but the incompatibility, if there is one, appears at runtime.

Unity version differences

The PrecompiledAssemblyException was introduced in Unity 2018.3, which is when Unity began rejecting duplicate assemblies rather than picking one non-deterministically. The Newtonsoft.Json case became common from Unity 2020 onwards, as more built-in packages took a dependency on the Package Manager version.

Sources

Frequently asked questions

Which copy should I delete?
Keep the one supplied by the Package Manager and delete the copy under Assets. A package-managed library is restored automatically if removed, so deleting it does not stick, and it is the version Unity's own packages are built against. Where both copies are under Assets, keep the newer one and test whichever asset shipped the older one.
Why is it nearly always Newtonsoft.Json?
Because Unity distributes it as a package that several built-in packages depend on, while a great many asset store packages bundle their own copy. Any project with both ends up with two. Unity's copy is the one to keep.
Can I keep both copies if they are different versions?
Not for the same platform. Unity allows only one assembly with a given name per platform, and it will not pick between two versions. You can keep two copies only when their import settings restrict each to a platform the other does not target, which is how some assets ship separate Editor and player builds.
Does deleting the Library folder fix this?
No. The duplicate is in your project rather than in the import cache, so a reimport finds both files again and reports the same conflict. Deleting Library is worth trying only after you have removed the duplicate and the error persists, which is uncommon.
Why did this appear when I changed build platform?
Because the message is about assemblies included for the current platform. Two copies with different platform settings can coexist without conflict until you switch to a target where both are enabled. Check the import settings of each copy rather than assuming the platform switch itself caused it.

Last updated: