Unity3D读取AssetBundle失败:The file can not be loaded

今天项目换了台新mini打iOS版本的ab包,真机上出现资源读取失败并有如下报错

The file can not be loaded because it was created for another build target that is not compatible with this platform. Please make sure to build AssetBundles using the build target platform that it is used by. File's Build target is: 13

查了下BuildTarget的枚举值,13的是Android,iOS的是9。

明明打的是iOS,怎么会是Android呢?

确认下BuildSetting里的Platform设置无误后,再重新打了一次,还是失败!!!

经查阅资料,发现Unity有时候会缓存上次打包时的平台设置(应该是引擎的Bug,我的是2017版本),本着试一试的心态,在打包代码前面添加如下代码:

Debug.Log("当前打包平台" + EditorUserBuildSettings.activeBuildTarget)
if(EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS)
{
    Debug.Error("打包平台设置错误");
    return;
}

这段代码主要在于调用一次EditorUserBuildSettings.activeBuildTarget,刷新当前的平台设置。

重新打包,搞定!!!

 

参考链接:

https://stackoverflow.com/questions/38437310/asset-bundle-is-not-loaded#

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值