override
今天发包的时候又双叒叕发现一个很生僻的问题,我电脑上有三个Unity工程两个可以 build iOS成功,其中一个报以下错误,我的Unity版本是2017.4.37c1。
Failed running /Applications/Unity/Unity.app/Contents/il2cpp/build/UnityLinker.exe --api=NET_4_6 -out="/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed/tempStrip" -l=none -c=link --link-symbols -x="/Applications/Unity/PlaybackEngines/iOSSupport/Whitelists/Core.xml" -f="/Applications/Unity/Unity.app/Contents/il2cpp/LinkerDescriptors" -x "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed/../platform_native_link.xml" -x "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/methods_pointedto_by_uievents.xml" -x "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/UnityEngine.xml" -x "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/preserved_derived_types.xml" -x "/Applications/Unity/Unity.app/Contents/il2cpp/LinkerDescriptors/System45.xml" -x "/Applications/Unity/Unity.app/Contents/il2cpp/LinkerDescriptors/mscorlib45.xml" -x "/Users/userName/prjectFolder/prjectName/Assets/XLua/Gen/link.xml" -d "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed" -a "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed/Assembly-CSharp-firstpass.dll" -a "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll" -a "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll" -a "/Users/userName/prjectFolder/prjectName/Temp/StagingArea/Data/Managed/DOTween.dll"
stdout:
Fatal error in Unity CIL Linker
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at UnityLinker.LocalDirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00076] in <7e310065a32e44da8c2e124136a4edf5>:0
at UnityLinker.UnityAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x0001a] in <7e310065a32e44da8c2e124136a4edf5>:0
at UnityLinker.LocalDirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00015] in <7e310065a32e44da8c2e124136a4edf5>:0
at Unity.IL2CPP.Common.WindowsRuntimeAwareMetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00065] in <3a27e73940da4b5081b4a2c248385935>:0
at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <29def57cc34c477e8d7d610cf6b6865a>:0
at Mono.Cecil.TypeReference.Resolve () [0x00006] in <29def57cc34c477e8d7d610cf6b6865a>:0
at UnityLinker.ResolveFromMonoBehaviours.IsMonoBehaviourOrScriptableObject (Mono.Cecil.TypeDefinition type) [0x0005b] in <7e310065a32e44da8c2e124136a4edf5>:0
at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext () [0x00037] in <5011e9e733714d64938421b744a2aefd>:0
at UnityLinker.ResolveFromMonoBehaviours.Process (Mono.Linker.LinkContext context) [0x000e7] in <7e310065a32e44da8c2e124136a4edf5>:0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00020] in <8fda245854de4877b507cdc580e3a786>:0
at UnityLinker.UnityDriver.Run () [0x00086] in <7e310065a32e44da8c2e124136a4edf5>:0
at UnityLinker.UnityDriver.RunDriverWithoutErrorHandling () [0x00001] in <7e310065a32e44da8c2e124136a4edf5>:0
at UnityLinker.UnityDriver.RunDriver () [0x00002] in <7e310065a32e44da8c2e124136a4edf5>:0
stderr:
UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunProgram(Program, String, String, String, CompilerOutputParserBase) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:128)
UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase, Action`1) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:73)
UnityEditorInternal.AssemblyStripper:RunAssemblyLinker(IEnumerable`1, String&, String&, String, String) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:89)
UnityEditorInternal.AssemblyStripper:StripAssembliesTo(String[], String[], String, String, String&, String&, String, IIl2CppPlatformProvider, IEnumerable`1) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:82)
UnityEditorInternal.AssemblyStripper:RunAssemblyStripper(String, IEnumerable, String, String[], String[], String, IIl2CppPlatformProvider, RuntimeClassRegistry) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:204)
UnityEditorInternal.AssemblyStripper:StripAssemblies(String, IIl2CppPlatformProvider, RuntimeClassRegistry) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/AssemblyStripper.cs:114)
UnityEditorInternal.IL2CPPBuilder:Run() (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:152)
UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action`1, RuntimeClassRegistry, Boolean) (at /Users/unity/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:34)
UnityEditor.BuildPipeline:BuildPlayer(BuildPlayerOptions)
AutoBuidle:BuildForPlatform(BuildPlayerOptions, String) (at Assets/Basics/Editor/Plug_Buidle/AutoBuidle.cs:361)
AutoBuidle:BuidleByType(EnumBuidleType, BuildTarget, Boolean) (at Assets/Basics/Editor/Plug_Buidle/AutoBuidle.cs:329)
AutoBuidle:BuidleIOSByType(EnumBuidleType, Boolean) (at Assets/Basics/Editor/Plug_Buidle/AutoBuidle.cs:269)
AutoBuidle:BuildIOSDebug() (at Assets/Basics/Editor/Plug_Buidle/AutoBuidle.cs:130)
看到这个问题不要怕,我们来找找具体的问题所在。看了具体bug日志我们可以抓住以下关键信息
stdout:
Fatal error in Unity CIL Linker
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Drawing,
ok,那么我们就定位问题在System.Drawing上,应该是工程在打包的时候调用了这个库,但是系统显示没有集成这个库文件。System.Drawing,顾名思义,它是.Net 的一个图形绘制库。下面我们就来解决这个bug。
libgdiplus安装
System.Drawing是依赖于libgdiplus库的,那么我们在电脑上检测一下是否安装了这个库文件。我的电脑是Mac,所以我们查看一下安装路径
/Library/Frameworks/Mono.framework/Versions/xxx/lib/libgdiplus.dylib
如果不存在,则安装libgdiplus库
brew install mono-libgdiplus
检测Drawing.dll配置
首先我们在Unity工程中搜索 Drawing,看是否有Drawing.dll文件,如果存在,选中Drawing.dll,查看他的配置,勾选中Editor,apply一下,我到这就解决了问题。
配置Unity.app
如果还是build失败,那么问题在可能是Unity找不到我们安装的libgdiplus,我们来查看一下Unity的配置
/Applications/Unity/Unity.app/Contents/MonoBleedingEdge/etc/mono/config
打开这个文件搜索一下gdiplus,发现一下相关配置
<dllmap dll="gdiplus" target="/Users/builduser/builds/vm/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib" os="!windows"/>
<dllmap dll="gdiplus.dll" target="/Users/builduser/builds/vm/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib" os="!windows"/>
<dllmap dll="gdi32" target="/Users/builduser/builds/vm/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib" os="!windows"/>
<dllmap dll="gdi32.dll" target="/Users/builduser/builds/vm/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib" os="!windows"/>
我们发下Unity配置的路径和我们安装的路径对不上,修改一下路径。
将/Users/builduser/builds/vm/mono/external/buildscripts/add_to_build_results/monodistribution/lib/libgdiplus.dylib替换为/Library/Frameworks/Mono.framework/Versions/xxx/lib/libgdiplus.dylib,xxx为本地mono版本号。
修改Unity config配置文件的方式虽然试验成功了,但是总感觉不是很安全,不知道这样有没有隐患,有知道的朋友可以交流一下。