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.
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
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
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
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.
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.
Related errors
- CS0246: CS0246Why Unity reports CS0246, ranked by how often each cause occurs, including assembly definitions, Editor folders and knock-on errors from elsewhere.
- CS1061: CS1061Why Unity reports CS1061, from typos and wrong types to private members and renamed APIs, with the fix for each and how to read the message.
Related tools
Sources
- Unity Manual: Import and configure plug-ins
- Unity Manual: Newtonsoft Json package
- Unity Discussions: multiple precompiled assemblies, Newtonsoft conflict
- GitHub: Newtonsoft.Json.dll duplicate reported against flutter-unity-view-widget
- Unity Discussions: package conflict, multiple precompiled assemblies
- Unity Discussions: PrecompiledAssemblyException from a duplicated dll
- Unity Discussions: 2018.3 PrecompiledAssemblyException, Version Control package