Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

This package still won't work on unity (IL2CPP builds) #132

Open
lordaltair opened this issue Aug 13, 2021 · 9 comments
Open

This package still won't work on unity (IL2CPP builds) #132

lordaltair opened this issue Aug 13, 2021 · 9 comments

Comments

@lordaltair
Copy link

Hi, I'm trying to use this package on my unity project. As the description says, the purpose of the package is to get IL2CPP builds. It is working on Unity editor but it is not working on android.

I'm using Unity 2019.3.7.f1 and the Newtonsoft.Json-for-Unity package version is 13.0.102. I tried other versions, too like 12.0.302 or 10.0.302. My OS is windows 10 and unity android built target version is 26. Is there any specific settings that I have to use? I didn't say anything in the description.

Thanks for your help.

@lordaltair lordaltair changed the title Help: this package still won't work on unity. This package still won't work on unity (IL2CPP builds) Aug 13, 2021
@applejag
Copy link
Owner

Hi @lordaltair! Thanks for reporting this!

In what way does it not work on Android?

Are there errors during compilation/building or during runtime? And if so, could you post the errors you receive?

Kind regards

@lordaltair
Copy link
Author

Hi @lordaltair! Thanks for reporting this!

In what way does it not work on Android?

Are there errors during compilation/building or during runtime? And if so, could you post the errors you receive?

Kind regards

Hi, Thanks for helping. No, it is on runtime, I have an android build but nothing works. The game works but the newtonsoft JSON package won't work. It isn't serialize or deserialize JSON or ...

@applejag
Copy link
Owner

Hi, Thanks for helping. No, it is on runtime, I have an android build but nothing works. The game works but the newtonsoft JSON package won't work. It isn't serialize or deserialize JSON or ...

If it's during runtime then I suggest you look into potential AOT issues. I've written some guides in the wiki. Recommend starting with What even is AOT followed by Fix AOT compilation errors.

To see the errors that occurs, I would suggest something like making a development/debug build, potentially by attaching your local Unity Editor to your Android phone so errors are relayed to your Unity Editor

@lordaltair
Copy link
Author

Hi, Thanks for helping. No, it is on runtime, I have an android build but nothing works. The game works but the newtonsoft JSON package won't work. It isn't serialize or deserialize JSON or ...

If it's during runtime then I suggest you look into potential AOT issues. I've written some guides in the wiki. Recommend starting with What even is AOT followed by Fix AOT compilation errors.

To see the errors that occurs, I would suggest something like making a development/debug build, potentially by attaching your local Unity Editor to your Android phone so errors are relayed to your Unity Editor

Well. I got no error. I use my mobile and I saw the errors. there was no error in the project. It is like that the compiler does not compile codes in which I used the package. Thanks for the links but those weren't helpful

@applejag
Copy link
Owner

Could you screenshot the errors you saw on your phone and post them here?

@albermotion
Copy link

It happens to me too. Running Unity 2020.3.7f1 and Windows 10.
It works perfectly on the editor, it deserializes a JSON string as you would expect. But when I make a build for Android, it just doesn't deserialize, everything is created but with null values. No errors are shown.
I'm using a custom JsonConverter on some properties with the attribute [JsonConverter(typeof(JsonToRxConverter))], but I've tried without it, and seems to do the same.
The funny thing is that even if the values are null it creates the correct number of elements from the array

@albermotion
Copy link

albermotion commented Aug 17, 2021

After adding a custom TraceWriter to try to find any info in the logs, I was able to see this log on every property:

Unable to deserialize value to non-writable property

Even though all my properties are public properties with public get and set

@applejag
Copy link
Owner

After adding a custom TraceWriter to try to find any info in the logs, I was able to see this log on every property:

Unable to deserialize value to non-writable property

Even though all my properties are public properties with public get and set

As IL2CPP has a much stricter stripping algorithm, my guess is that your code never explicitly sets those values, but it does get them. A property setter is just a method, and if it's unused then IL2CPP will strip it out.

Suggest using link.xml or a [Preserve] attribute on the type so that the property setters are not stripped out.

@godboutj
Copy link

godboutj commented Aug 17, 2021

You should add the following to the link.xml:
<assembly fullname="Newtonsoft.Json" preserve="all"/>
That should solve your issue with IL2CPP

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants