returns Xcode 10.3 中的资产目录 returns 无图像,在 10.1 中工作正常

Asset catalog returns nil image in Xcode 10.3, works fine in 10.1

使用两个不同 Xcode 版本构建的应用程序表现不同。当使用 Xcode 10.1 构建时,所有图像都按预期通过 UIImage(named:in:compatibleWith:) 方法加载。但是一旦我使用 Xcode 10.3 构建应用程序,此方法 returns nil 用于所有 unsliced 图像。奇怪的是,它 returns 非 nil 用于切片图像。

同样值得注意的是,当我 运行 来自 Xcode (10.1/10.2.1/10.3) 的应用程序时图像正常工作,但当 tested 从命令行使用 xcodebuild test-without-building.

问题出在 xcodebuild -destination 标记内容中。由于这是在 CI 上发生的,因此为两个单独的构建(Xcode 10.1 和 10.2.1)传递不同的值并不明显。

使用 Xcode 10.1 构建时,使用了 iOS Simulator 10.3.1。因此,actool --filter-for-os-device-version 10.3.1 参数是由 xcode 构建系统推断出来的。生成的汽车文件与 iOS 10+ 运行时兼容。

使用 Xcode 10.2.1 构建时,使用了 iOS Simulator 12.2。在这种情况下,构建系统推断出 actool --filter-for-os-device-version 12.2 参数。生成的汽车文件与 iOS 12+ 运行时兼容。

在这两种情况下,xcodebuild test-without-building 都与 iOS Simulator 11.3 环境一起使用。因此,使用 Xcode 10.2.1 构建的应用程序仅适用于 iOS 12.2 环境,使所有图像在 iOS 11.3 环境中消失。

解决方法是在命令调用中同步 build-for-testingtest-without-buildingxcodebuild -destination 标志的值。

另一个有用的建议是将 ENABLE_ONLY_ACTIVE_RESOURCES 构建设置切换为 NO