[英]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#
System
和System.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.Get
、 UnityWebRequest.Post
和UnityWebRequest.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-in
JsonUtility
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.