简体   繁体   English

Unity System 和 Newtonsoft 库在为 android 构建时不起作用

[英]Unity System and Newtonsoft libraries does not work when built for android

I am new at Unity but I have some experience at Asp.Net programming.我是 Unity 的新手,但我在 Asp.Net 编程方面有一些经验。 I need to develop a application which need to connect an API and get,post,delete some datas from that API.我需要开发一个需要连接 API 并从该 API 获取、发布、删除一些数据的应用程序。 In order to achieve that, I am using these libraries below:为了实现这一点,我在下面使用这些库:

using System.Net.Http;
using System;
using Newtonsoft.Json;

When I run the application, there is no any error, warning etc. on my computer (I am using Unity 2020.3.24f1).当我运行应用程序时,我的计算机上没有任何错误、警告等(我使用的是 Unity 2020.3.24f1)。 It works exactly how I want.它完全按照我的意愿工作。 But when I build it for android platform (apk) and install it to my android phone, my codes which use these libraries does not work on the phone.但是当我为 android 平台(apk)构建它并将其安装到我的 android 手机时,我使用这些库的代码在手机上不起作用。 I can not see any error on the phone screen just does not work.我在手机屏幕上看不到任何错误,只是不起作用。 I hope I could explain.我希望我能解释一下。

There is no "Unity System".. you are using the general c# System and System.Net.Http namespaces!没有“统一系统”..您使用的是通用c# SystemSystem.Net.Http命名空间! And in general from System.Net通常来自System.Net

Classes in the System.Net namespace can be used to develop Windows Store apps or desktop apps. System.Net 命名空间中的类可用于开发 Windows Store 应用程序或桌面应用程序。

so this doesn't exist on Android .所以这在Android上不存在。


You should rather use Unity's UnityWebRequest.Get , UnityWebRequest.Post and UnityWebRequest.Delete accordingly.您应该相应地使用 Unity 的UnityWebRequest.GetUnityWebRequest.PostUnityWebRequest.Delete


For JSON either stick to the built-inJsonUtility if possible or make sure to use the "semi-built-in" package Newtonsoft JSON you can install via the Package Manager (if it is not the case anyway for newer versions by default). For JSON either stick to the built-inJsonUtility if possible or make sure to use the "semi-built-in" package Newtonsoft JSON you can install via the Package Manager (if it is not the case anyway for newer versions by default).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构建我的统一项目时,此代码不起作用 - This code does't work when my unity project is built 当统一构建 android 项目时,Refit 6 不起作用 - Refit 6 not working when android project built with unity Unity Newtonsoft JSON Android Build MissingMethodException: 未找到“System.ComponentModel.ReferenceConverter”类型的构造函数 - Unity Newtonsoft JSON Android Build MissingMethodException: Constructor on type 'System.ComponentModel.ReferenceConverter' not found HyperDescriptor在.NET 4中构建时是否有效? - Does HyperDescriptor work when built in .NET 4? 为什么 Newtonsoft.Json 在示例中起作用而 System.Text.Json 不起作用 - Why does Newtonsoft.Json work in example and System.Text.Json doesn't C# System.IO.File.Exists 在 Unity 中不起作用 - C# System.IO.File.Exists does not work in Unity 我的团结计划的高分系统不起作用 - The high score system for my unity program does not work 使用对象的网格物体作为粒子系统的发射器时,内置的Unity游戏崩溃 - Built Unity game crashes when using object's mesh as emitter for particle system StartCoroutine(带有WWW)在Android上不起作用,但在编辑器上起作用-Unity - StartCoroutine (with WWW) does not work on Android but it does on the editor - Unity Unity InjectionProperty 不起作用 - Unity InjectionProperty does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM