Unity IL2CPP使用Newtonsoft.Json问题

发布于 约 1 分钟

git np

工作时使用IL2CPP打包PC,发现打包失败。 alt text


解决方法:

1.找到你的项目文件夹/Packages/manifest.json文件,打开并添加以下内容

{
 "scopedRegistries": [
    {
      "name": "Packages from jillejr",
      "url": "https://npm.cloudsmith.io/jillejr/newtonsoft-json-for-unity/",
      "scopes": ["jillejr"]
    }
  ],
  "dependencies": {
    "jillejr.newtonsoft.json-for-unity": "12.0.201",
   ...
  }
}

2.在Assets文件夹下新建一个link.xml文件,写入以下内容,防止裁剪

<linker>
      <assembly fullname="Newtonsoft.Json" preserve="all" />
  <assembly fullname="System.Core">
    <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
  </assembly>
</linker>

3.最后记得代码的using更改

using Unity.Plastic.Newtonsoft.Json;
using Unity.Plastic.Newtonsoft.Json.Linq;
 
//改为下面这段
 
 
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;