Unity iOS/Android构建报错:System.TypeLoadException无法解析Google.EditorInitializer
Unity构建iOS/Android时出现Google.EditorInitializer类型加载异常
问题描述
开发跨iOS和Android的Unity项目,此前已成功上架iOS App Store,但部署Android时触发以下错误,且现在iOS构建也受影响。自上次成功构建后未修改任何代码,已尝试重装Unity、升降级版本、重新安装模块,均无法解决。
错误信息:
System.TypeLoadException: Could not resolve type with token 01000075 from typeref (expected class 'Google.EditorInitializer' in assembly 'Google.VersionHandlerImpl, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null') UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorAssemblies.cs:130) System.TypeLoadException: Could not resolve type with token 01000075 from typeref (expected class 'Google.EditorInitializer' in assembly 'Google.VersionHandlerImpl, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null') UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[]) (at /Users/bokken/build/output/unity/unity/Editor/Mono/EditorAssemblies.cs:130) TypeLoadException: Could not resolve type with token 01000075 from typeref (expected class 'Google.EditorInitializer' in assembly 'Google.VersionHandlerImpl, Version=1.2.0.0, Culture=neutral, PublicKeyToken=null') Rethrow as TypeInitializationException: The type initializer for 'Firebase.Editor.GenerateXmlFromGoogleServicesJson' threw an exception. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <b6c5d0f08ddf477186f780f49bb14dee>:0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <b6c5d0f08ddf477186f780f49bb14dee>:0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <b6c5d0f08ddf477186f780f49bb14dee>:0) UnityEditor.AssetPostprocessingInternal.InvokeMethod (System.Reflection.MethodInfo method, System.Object[] args) (at /Users/bokken/build/output/unity/unity/Editor/Mono/AssetPostprocessor.cs:1145) UnityEditor.AssetPostprocessingInternal.PostprocessAllAssets (System.String[] importedAssets, System.String[] addedAssets, System.String[] deletedAssets, System.String[] movedAssets, System.String[] movedFromPathAssets, System.Boolean didDomainReload) (at /Users/bokken/build/output/unity/unity/Editor/Mono/AssetPostprocessor.cs:385)
解决方案
1. 彻底清理Google/Firebase相关残留文件
- 关闭Unity编辑器,删除项目根目录下的
Library、Temp、Obj文件夹,这些缓存目录常引发程序集加载异常 - 删除
Assets/Plugins/Google和Assets/Firebase文件夹(若项目使用Firebase服务) - 打开
Packages/manifest.json移除所有Google、Firebase相关包引用;同时删除Packages/packages-lock.json中对应条目,避免残留版本锁定
2. 重新导入对应版本的Google/Firebase包
- 重启Unity,通过Package Manager重新添加与上次成功构建时版本完全一致的Google/Firebase相关包
- 若使用Firebase,建议直接从Firebase官网下载对应版本的Unity SDK压缩包手动导入,避免Package Manager自动拉取的版本出现兼容性问题
3. 清理编辑器程序集残留
- 删除
Assets/Editor目录下自动生成的Google相关文件(如GoogleVersionHandler.cs类文件) - 检查
Assembly-CSharp-Editor.csproj等编辑器程序集配置,确保无异常引用Google.VersionHandlerImpl
4. 验证Firebase配置文件
- 重新从Firebase控制台下载最新的
google-services.json(Android)和GoogleService-Info.plist(iOS),替换项目中旧文件 - 确认配置文件的包名/Bundle ID与项目Player Settings中的设置完全匹配
5. 检查Unity运行时与插件兼容性
- 打开Player Settings → Other Settings,确认
Scripting Runtime Version、Api Compatibility Level与上次成功构建时保持一致 - 排查项目中其他第三方插件(如广告、分析工具)是否与Google/Firebase包存在版本冲突,暂时禁用可疑插件后尝试构建
内容的提问来源于stack exchange,提问作者Dhwanit Zaveri
相关产品推荐
相关产品推荐

