1.导入最新的Aliyun.OSS.dll
2.将Unity-Player-Other Settings设置
Api Compatibillity Level* = .NET 4.X
编辑器下运行正常
3.导出android包以后,运行报错
2023-10-23 18:57:24.372 29533-29619/? D/xiaoyuan: getUpdateCycle start
2023-10-23 18:57:24.378 29426-29730/? I/Unity: -----------------下载文件出错:System.NullReferenceException: Object reference not set to an instance of an object.
at Aliyun.OSS.Common.Communication.HttpExtensions.AddInternal (System.Net.WebHeaderCollection headers, System.String key, System.String value) [0x00000] in <00000000000000000000000000000000>:0
at Aliyun.OSS.Common.Communication.HttpFactory.SetRequestHeaders (System.Net.HttpWebRequest webRequest, Aliyun.OSS.Common.Communication.ServiceRequest serviceRequest, Aliyun.OSS.Common.ClientConfiguration configuration) [0x00000] in <00000000000000000000000000000000>:0
at Aliyun.OSS.Common.Communication.HttpFactory.CreateWebRequest (Aliyun.OSS.Common.Communication.ServiceRequest serviceRequest, Aliyun.OSS.Common.ClientConfiguration configuration) [0x00000] in <00000000000000000000000000000000>:0
at Aliyun.OSS.Common.Communication.ServiceClientImpl.SendCore (Aliyun.OSS.Common.Communication.ServiceRequest serviceRequest, Aliyun.OSS.Common.Communication.ExecutionContext context) [0x00000] i
2023-10-23 18:57:24.392 1553-2442/? D/GameManagerService: respondWithJson. command: get_sysfs_data
原因:
1.通过查看源码增加打印测试得知,在android环境中,Environment.OSVersion.Platform识别成了
Environment.OSVersion.Platform=PlatformID.Unix;
最后导致
_isMonoPlatform = MonoPlatforms.Contains(Environment.OSVersion.Platform);
_isMonoPlatform = true;
后续的赋值导致_addInternalMethod = null;
解决方案:
1.注释HttpExtensions.MonoPlatforms变量中的PlatformID.Unix
2.选中 aliyun-oss-sdk项目重新生成dll
3.拷贝 D:\unityWork\aliyun-oss-csharp-sdk-2.13.0\sdk\bin\Debug\Aliyun.OSS.dll覆盖到项目中
4.出android包测试成功
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。