onevcat/Kingfisher

Kingfisher stops the app from archiving on Xcode 13 RC

TizianoCoroneo opened this issue · 15 comments

Issue Description

Kingfisher produces a large number of build errors when building for "Any iOS device (arm64)" with Xcode 13 RC.

What

It seems that it cannot find references to SwiftUI data types, even the import SwiftUI statement is present.

There is a workaround, but it's not nice: we forked and bumped the minimum version for iOS in KF's Package.swift to iOS 13, and the issue disappeared.

Screen Shot 2021-09-15 at 09 59 26

Screen Shot 2021-09-15 at 10 00 42

Reproduce

I made a sample project that reproduces the issue:
KingfisherArchiveIssue.zip

Select "Any iOS Device (arm64)" and try to build (or archive).

Duplicated with #1725

As indicated in the Xcode 13 Release Notes:

Known Issues

Swift libraries may fail to build for iOS targets that use armv7. (74120874)
Workaround: Increase the platform dependency of the package to v12 or later.

Swift libraries depending on Combine may fail to build for targets including armv7 and i386 architectures. (82183186, 82189214)
Workaround: Use an updated version of the library that isn’t impacted (if available) or remove armv7 and i386 support (for
example, increase the deployment target of the library to iOS 11 or higher).

Unfortunately Kingfisher falls into this (since it is supporting SwiftUI, which in turn using Combine to manage states).

This is not a thing can be fixed easily in a library like Kingfisher. So please try to upgrade to Kingfisher v7 (and consider to drop support under iOS 12. Here is the migration guide).

Here is an image (from Aug, 2021) that you can use to persuade your boss to drop those old ones:

I am not sure if this "Known Issues" can be fixed by Apple in near future. With the fact that the problem started to be there from Xcode 13 beta 2 to the final release, I doubt whether Apple has any motivation to fix it or mark it as urgent.

If you still need to support older systems (such as iOS 10 or 11), maybe it is a good idea to keep using Xcode 12 for a longer while before Apple fixes it.

For now, using SPM requires a target version in Kingfisher's Package.swift to iOS .v12 and it was released as a part of Kingfisher v7 (currently in beta, but should be quite stable) and here is the migration guide.

If you still need to use Kingfisher v6 with Xcode 13 (say, you still need to support iOS 10 and 11), choose another integrating way (CocoaPods, Carthage or so).

We have a minimum deployment target of iOS 13.2 and we still have this issue. Since we need the SwiftUI components, for us there is no migration path possible without dropping iOS 13, and moving to KF v7, unless we make our own fork and bump KF's target version.

@TizianoCoroneo

That is also a reasonable workaround for now to fork from v6 and only update the deployment target version without any changes of other part, until you are prepared to migrate to the new Kingfisher version 7.

Duplicated with #1725

As indicated in the Xcode 13 release note:

Swift libraries may fail to build for iOS targets that use armv7. (74120874)
Workaround: Increase the platform dependency of the package to v12 or later.

For now, using SPM requires a target version in Kingfisher's Package.swift to iOS .v12 and it was released as a part of Kingfisher v7 (currently in beta, but should be quite stable) and here is the migration guide.

If you still need to use Kingfisher v6 with Xcode 13 (say, you still need to support iOS 10 and 11), choose another integrating way (CocoaPods, Carthage or so).

What does one have to do in order to get this working with cocoapods?

EDIT: You have to go to your pods target settings and change the deployment number.

Hi, you can use Xcode 13+ and Kingfisher and iOS 11 (tested) if you will remove pods and install Kingfisher from SPM

Archiving work fine

Use Xcode 13 Release and drop support under iOS 11 will fix for me.
emmmm.... Maybe Apple Document made a mistake!

Since my min supported iOS version is 13.0.
This did the trick for me to fix cocoapods integration:

post_install do |pi|
    pi.pods_project.targets.each do |t|
        t.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
        end
    end
end

Use Xcode 13 Release and drop support under iOS 11 will fix for me.
emmmm.... Maybe Apple Document made a mistake!

Some project need to modify configuration as follows:

post_install do |pi|
    pi.pods_project.targets.each do |t|
        t.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
        end
    end
end

Confused behaviour! 😂

Use Xcode 13 Release and drop support under iOS 11 will fix for me.
emmmm.... Maybe Apple Document made a mistake!

Some project need to modify configuration as follows:

post_install do |pi|
    pi.pods_project.targets.each do |t|
        t.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
        end
    end
end

Confused behaviour! 😂

We noticed this issue can be fixed by changing Project Format to Xcode 8.0-compatible within iOS 11. And then Architectures became ARCHS_STANDARD_64_BIT, Archiving will not include armv7. But We recommend to set Xcode 12.0-compatible and modify pod target config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET' to inherit project.

TLDR

Determine the latest version you can use by:

UIKit SwiftUI Xcode Kingfisher
iOS 10+ iOS 13+ 12 ~> 6.3.1
iOS 11+ iOS 13+ 13 version6-xcode13
iOS 12+ iOS 14+ 13 ~> 7.0

If you really have to support from iOS 10 in Xcode 13, and you are not using SwiftUI. Check the workaround here.

Detail for current workaround

For anyone who still needs to use Kingfisher v6 (for supporting iOS 11 UIKit or iOS 13 SwiftUI), but wants to use it in Xcode 13, now there is a compatible branch version6-xcode13. Pointing your dependency of Kingfisher to that branch would help you to avoid this issue.

The only change in that branch, compared to the released 6.3.1, is dropping of iOS 10 for UIKit support. That allows Xcode 13 skip the ARMv7 compilation so it won't trigger this issue anymore. That branch would exist for at least one year so you can migrate to version 7 eventually.

Again, the deployment increment in Kingfisher v7 (iOS 12 for UIKit, iOS 14 for SwiftUI) is intended and important to provide a correct data model. If you do not need to support older system anymore, it is encouraged to upgrade to the latest version.

We use 6.3.0, have iOS 11 support and build/archive with Xcode13 with no problem - however - we already had in our podfile what @ZeroOnet recommends here. That is the alternative solution for those who do not want to switch to version6-xcode13 branch

因为项目需要适配iOS10,并且项目没有使用到swiftui,所以就使用ruby脚本将报错相关代码移除掉
在Podfile文件中添加以下钩子函数,然后运行pod install

pre_install do |installer|
remove_swiftui()
end

def remove_swiftui
system("rm -rf ./Pods/Kingfisher/Sources/SwiftUI")
code_file = "./Pods/Kingfisher/Sources/General/KFOptionsSetter.swift"
code_text = File.read(code_file)
code_text.gsub!(/#if canImport(SwiftUI) && canImport(Combine)(.|\n)+#endif/,'')
system("rm -rf " + code_file)
aFile = File.new(code_file, 'w+')
aFile.syswrite(code_text)
aFile.close()
end

Apple fixed this in Xcode 13.2 (still in beta though), so if you still need Kingfisher v6 (supporting from iOS 10) in Xcode 13, you can wait for the final release of Xcode 13.2. Otherwise, if you only need to support from iOS 12 or later, upgrade to the latest Kingfisher v7 would be a better choice.

Xcode 13.2 was released (as RC although) in which a fix for this is contained. Now even Kingfisher v6 could be used in Xcode 13.2.