筆者Unity版本2021.3.8f1
1,確保安裝了對應(yīng)版本的擴展包:UnitySetup-Windows-IL2CPP-Support-for-Editor
2,打包報錯:
error: Could not set up a toolchain for Architecture x64. Make sure you have the right build tools installed for il2cpp builds. Details:
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
和
Internal build system error. BuildProgram exited with code -2146233088.
error: Could not set up a toolchain for Architecture x64. Make sure you have the right build tools installed for il2cpp builds. Details:
IL2CPP C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
* Visual Studio 2022 or newer with C++ compilers and Windows 10 SDK (recommended)
* Visual Studio 2019 with C++ compilers and Windows 10 SDK
* Visual Studio 2017 with C++ compilers and Windows 10 SDK
* Visual Studio 2015 with C++ compilers and Windows 10 SDK
Visual Studio 2017 (or newer) is detected using `vswhere.exe` as well as VSCOMNTOOLS environment variables.
Visual Studio 2015 is detected by looking at "SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir" in the registry as well as VSCOMNTOOLS environment variables.
Windows 10 SDK is detected by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry.
Unable to detect any compatible Visual Studio installation!
* Found Visual Studio 2022 installation without C++ tool components
Windows 10 SDK is not installed. You can install from here: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk/
Unity.IL2CPP.Bee.BuildLogic.ToolchainNotFoundException: IL2CPP C++ code builder is unable to build C++ code. In order to build C++ code for Windows Desktop, you must have one of these installed:
* Visual Studio 2022 or newer with C++ compilers and Windows 10 SDK (recommended)
* Visual Studio 2019 with C++ compilers and Windows 10 SDK
* Visual Studio 2017 with C++ compilers and Windows 10 SDK
* Visual Studio 2015 with C++ compilers and Windows 10 SDK
Visual Studio 2017 (or newer) is detected using `vswhere.exe` as well as VSCOMNTOOLS environment variables.
Visual Studio 2015 is detected by looking at "SOFTWARE\Microsoft\VisualStudio\14.0_Config\InstallDir" in the registry as well as VSCOMNTOOLS environment variables.
Windows 10 SDK is detected by looking at "SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0\InstallationFolder" in the registry.
這里:unable-to-build-il2cpp 建議使用Visual Studio Installer補充安裝一些C++相關(guān)的工具包。文章來源:http://www.zghlxwxcb.cn/news/detail-507725.html
3,若依舊報錯類似Building Library\Bee\artifacts\WinPlayerBuildProgram\ei6vj\ejx6_b_vm6.lump.obj failed with output: i3ib_vm6.lump.cpp
可以考慮把如下腳本放到Assets目錄下(來自這里)文章來源地址http://www.zghlxwxcb.cn/news/detail-507725.html
#if UNITY_EDITOR
using System;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
public class MsvcStdextWorkaround : IPreprocessBuildWithReport
{
const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS";
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var clEnv = Environment.GetEnvironmentVariable("_CL_");
if (string.IsNullOrEmpty(clEnv))
{
Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag);
}
else if (!clEnv.Contains(kWorkaroundFlag))
{
clEnv += " " + kWorkaroundFlag;
Environment.SetEnvironmentVariable("_CL_", clEnv);
}
}
}
#endif // UNITY_EDITOR
到了這里,關(guān)于Unity使用IL2CPP方式打Windows包的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!