applejag/Newtonsoft.Json-for-Unity

Bug: Git package doesn't include link.xml fixes

KGMaxey opened this issue ยท 5 comments

First off, fantastic work with this package! This has come in very handy and is very much appreciated! (see the incoming coffee donation ๐Ÿ˜)

Issue

I'm currently working on creating a Unity Package that uses this package. Due to the way our team works as well as how we pull in other packages, we use git URLs to pull down this package. I noticed however that using the latest tag doesn't seem to use the link.xml fixes that have been added recently (See this commit). This causes issues with using StringEnumConverter and other Newtonsoft converter attributes when building for iOS using IL2CPP. I've done a bit of research on this topic including forum hopping to wrap my brain around how this AOT stuff works. This includes some of your posts on this thread by the way so cheers for that! If I'm not mistaken I would expect the link.xml file included at the root of the package to look like this from your updates:

<linker>
	<assembly fullname="System">
		<!-- No issue on these, though they are quite commonly used. -->
		<type fullname="System.ComponentModel.*Converter" preserve="all"/>
	</assembly>
	<assembly fullname="Newtonsoft.Json">
		<!-- https://github.com/jilleJr/Newtonsoft.Json-for-Unity/issues/54 -->
		<type fullname="System.Runtime.CompilerServices.NullableAttribute"/>
		<type fullname="System.Runtime.CompilerServices.NullableContextAttribute"/>

		<!-- https://github.com/jilleJr/Newtonsoft.Json-for-Unity/issues/8 -->
		<!-- https://github.com/jilleJr/Newtonsoft.Json-for-Unity/issues/65 -->
		<type fullname="Newtonsoft.Json.Converters.*Converter" preserve="all" />

		<!-- No issue on these, though they are quite commonly used. -->
		<type fullname="Newtonsoft.Json.Serialization.*NamingStrategy" preserve="all" />
	</assembly>
</linker>

However it appears it is the older version here:

<linker>
	<assembly fullname="System">
		<type fullname="System.ComponentModel.ArrayConverter" preserve="all"/>
		<type fullname="System.ComponentModel.BaseNumberConverter" preserve="all"/>
		<type fullname="System.ComponentModel.BooleanConverter" preserve="all"/>
		<type fullname="System.ComponentModel.ByteConverter" preserve="all"/>
		<type fullname="System.ComponentModel.CharConverter" preserve="all"/>
		<type fullname="System.ComponentModel.CollectionConverter" preserve="all"/>
		<type fullname="System.ComponentModel.ComponentConverter" preserve="all"/>
		<type fullname="System.ComponentModel.CultureInfoConverter" preserve="all"/>
		<type fullname="System.ComponentModel.DateTimeConverter" preserve="all"/>
		<type fullname="System.ComponentModel.DecimalConverter" preserve="all"/>
		<type fullname="System.ComponentModel.DoubleConverter" preserve="all"/>
		<type fullname="System.ComponentModel.EnumConverter" preserve="all"/>
		<type fullname="System.ComponentModel.ExpandableObjectConverter" preserve="all"/>
		<type fullname="System.ComponentModel.Int16Converter" preserve="all"/>
		<type fullname="System.ComponentModel.Int32Converter" preserve="all"/>
		<type fullname="System.ComponentModel.Int64Converter" preserve="all"/>
		<type fullname="System.ComponentModel.NullableConverter" preserve="all"/>
		<type fullname="System.ComponentModel.SByteConverter" preserve="all"/>
		<type fullname="System.ComponentModel.SingleConverter" preserve="all"/>
		<type fullname="System.ComponentModel.StringConverter" preserve="all"/>
		<type fullname="System.ComponentModel.TimeSpanConverter" preserve="all"/>
		<type fullname="System.ComponentModel.TypeConverter" preserve="all"/>
		<type fullname="System.ComponentModel.UInt16Converter" preserve="all"/>
		<type fullname="System.ComponentModel.UInt32Converter" preserve="all"/>
		<type fullname="System.ComponentModel.UInt64Converter" preserve="all"/>
	</assembly>
</linker>

If there's something I'm misunderstanding about your link.xml implementation or a step I might have missed other than installing the package and build please let me know! I'm going to start digging in to see if I can figure out how this project is set up and attempt and pull request to fix but I figured I'd start with a ticket just in case you're faster.

Details

Host Machine: MacBook Pro (Big Sur)
Unity Version: 2019.4.14f1
Package Version: 12.0.301
Install Route: Git URL

Checklist

  • Shutdown Unity, deleted the /Library folder, opened project again in Unity, and problem still remains.
  • Checked to be using latest version of the package.

TLDR/ Workaround

For anyone having a similar issue:
Git URL for package doesn't seem to include link.xml fixes for iOS/ IL2CPP builds stripping Json Converter constructors. To work around this add this file (or it's contents to an existing link.xml) to your project. This has worked for me and shouldn't cause problems when this issue gets fixed since Unity should merge all the link.xml files and get rid of any duplications.

Thanks again for the work and for any help in advance!

P.S: Sorry for not 100% following the template, just felt more clear this way

Hi @KGMaxey ! Thanks so much for such a clear issue, and the donation as well! โค๏ธ

The reason it doesn't work, might make you and me facepalm a little: I've forgotten to deploy! ๐Ÿ˜…

I'll deploy later today if that's OK? I just woke up and don't want to rush a deploy early in the morning before work. When it comes to hobby projects, you can actually deploy on a Friday afternoon ;)

Haha perfect facepalm moment. Take your time with the deployment, like I said I've got a workaround that'll keep me going no problem. Thanks for the quick reply as well! You're just waking up and I'm on the other side of the world about to head to bed yet we still managed to link up!

Hehe that's it quite cool. So sometime around when you're munching breakfast tomorrow I will be releasing a new version.

Timezones are funny

Good morning in advance for you then!

v12.0.302 has now been published and is already available via Cloudsmith (https://cloudsmith.io/~jillejr/repos/newtonsoft-json-for-unity/packages/detail/npm/jillejr.newtonsoft.json-for-unity/12.0.302/) and the OpenUPM repo https://openupm.com/packages/jillejr.newtonsoft.json-for-unity/?subPage=readme

If you've installed Newtonsoft.Json-for-Unity via any of those two repos, then you should be able to update now.

If you've installed it via Git, you can find how to update here: https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Installation-via-Git-in-UPM#updating-the-package

Hope that resolves your issue!

Fantastic! Just pulled it down and it seems to work like a charm! Thank you very much!