microsoft / FluentDarkModeKit

A library for backporting Dark Mode in iOS
MIT License
1.63k stars 125 forks source link

WidgetExtension #error unsupported Swift architecture #111

Closed RisingSSR closed 1 year ago

RisingSSR commented 1 year ago

I have a widget extension. And my podfile like this:

platform :ios,'11.0'

use_frameworks!

target 'A' do

    pod 'FluentDarkModeKit'

end

target 'AWidgetExtension' do

end

When I use my Canvas for my widget, there is such a mistake.

FluentDarkModeKit.framework/Headers/FluentDarkModeKit-Swift.h:351:2: error: unsupported Swift architecture
#error unsupported Swift architecture

Does anyone have any idea?

levinli303 commented 1 year ago

can you please provide a sample project here? that would help us reproduce this issue. thanks

RisingSSR commented 1 year ago

Emmm, I think this is my problem. I have encapsulated a simpler usage based on your API, but the problem is here. It seems that I cannot reproduce this bug.

unsupported Swift architecture

----------------------------------------

SchemeBuildError: Failed to build the scheme "AWidgetExtension"

unsupported Swift architecture

Build target A:
warning: Run script build phase '[CP] Embed Pods Frameworks' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'A' from project 'A')
warning: Run script build phase 'Run Script' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'A' from project 'A')

Compile UIColor+Rising.m (arm64):
While building module 'FluentDarkModeKit' imported from /Users/ssr/Documents/SSR Program/A/A/Pod/Rising Extension/UIKit Extension/UIColor+Rising.m:10:
In file included from <module-includes>:2:
/Users/ssr/Library/Developer/Xcode/DerivedData/A-djijmevprrjlzdbajspncoilhydx/Build/Intermediates.noindex/Previews/AWidgetExtension/Products/Debug-iphonesimulator/FluentDarkModeKit/FluentDarkModeKit.framework/Headers/FluentDarkModeKit-Swift.h:351:2: error: unsupported Swift architecture
#error unsupported Swift architecture
 ^
1 error generated.
/Users/ssr/Documents/SSR Program/A/A/Pod/Rising Extension/UIKit Extension/UIColor+Rising.m:10:9: fatal error: could not build module 'FluentDarkModeKit'
#import <FluentDarkModeKit/FluentDarkModeKit.h>
 ~~~~~~~^
2 errors generated.

UIColor+Rising is a faster way to use your API and is integrated into the PCH file.

RisingSSR commented 1 year ago

Yep, Now I have reproduced this bug. It seems that it is caused by the podfile. Is there a better way to solve it? see: https://github.com/HONEY-SSR/FluentDarkTest please check out SwiftUIView.swift, Canvas cannot use.

levinli303 commented 1 year ago

it might be the post hook in the Podfile that is to blame. Are you building for simulator on apple silicon?

post_install do |installer|
    installer.pods_project.build_configurations.each do |config|
        config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
        config.build_settings['VALID_ARCHS'] = 'arm64 arm64e armv7 armv7s x86_64 i386'
        config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
        config.build_settings['HEADER_SEARCH_PATHS'] = '$(PROJECT_DIR)/**'
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
        config.build_settings['EXPANDED_CODE_SIGN_IDENTITY'] = ""
        config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
        config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
    end
end
RisingSSR commented 1 year ago

Yep. Now I know what the problem is. First, I need YYKit, but it needs architecture arm64 so that there is config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'. but the FluentDarkModeKit unsupported architecture arm64 but I seem to have no idea how to use these two pods at the same time.

levinli303 commented 1 year ago

setting `config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' means that it does not support arm64 simulator. Since it is set by YYKit, it means YYKit doesn't support arm64 simulator. FluentDarkModeKit supports any architecture you are building against.

Xcode will only build simulator app in x86_64 (running in Rosetta mode) when all the targets in the project excludes arm64 in the target settings (this include both your main project and the Pods project).

To get your project to build, you have to change the project setting (not the Pods project) setting `config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' in every target so that Xcode will build x86_64 version of everything and runs the app in Rosetta mode.

RisingSSR commented 1 year ago

Thank you for your suggestions. I will try my best to try every possible way again. If I make progress, I will continue to write under this issue.

levinli303 commented 1 year ago

closing since it is unrelated to the project.