Flutter:添加共享扩展

标签 flutter cocoapods bitcode share-extension

问题

我已将 iOS Share Extension 添加到一个非常简单的 Flutter 项目中,

My codefeature branch 上设置设备,我也知道bitcode in flutter is not ready yet :

在设备上运行目标:共享扩展

ld: '[Project_Path]/ios/DerivedData/Products/Debug-iphoneos/FMDB/libFMDB.a(FMDatabase.o)' 
does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting 
ENABLE_BITCODE)

在设备上运行目标:容器应用

注意:此[CP] Embed Pods Framworks[ProjectCompare]相同。

* Run custom shell script '[CP] Embed Pods Framworks'....
* Validate [Project_Path]/ios/DerivedData/Products/Debug-iphonos/Runner.app/PlugIns/
  ShareExtension.appe(in target: Runner)
* cd [Project_Path]/ios
* builtin-embeddedBinaryValidationUtility [Project_Path]/ios/DerivedData/Products/
  Debug-iphonos/Runner.app/PlugIns/ShareExtension.appex 
    -siging-cert [someID] 
    -info-plist-path [Project_Path]/ios/DerivedData/Products/Debug-iphonos/Runner.app/Info.plist
* error: Embedded binary is not signed with the same certificate as the parent app. 
  Verify the embedded binary target's code sign settings match the parent app's.
    * Embedded Binary Signing Certificate:    Not Code Signed
    * Parent App Signing Certificate:  iPhone Developer: MyName (XXXXX)

比较

我还创建了一个纯iOS项目ProjectCompare也一样,并在更改后将 Pod 添加到其中。我使用 workspace 打开项目并添加 Share Extension,它在设备上运行良好。

问题

所以我认为可能是一些与 Flutter 设置相关的脚本导致了这个错误?或者 Podfile 中的脚本?

知道该怎么做吗?

更新

覆盖目标:共享扩展中的设置后:

  • LIBRARY_SEARCH_PATHS = "";
  • OTHER_LDFLAGS = ""; or OTHER_LDFLAGS = "-ObjC";

在设备上运行目标:ShareExtension目标:容器应用程序都可以工作。

最佳答案

所以@pulyaevskiy的帮助。我找到了修复方法:

简短:

overwrite设置在Target: Share Extension :(git diff sample)

LIBRARY_SEARCH_PATHS = "";

OTHER_LDFLAGS = ""; or OTHER_LDFLAGS = "-ObjC";

详细信息:

  1. 位置:运行时Target: ShareExtension & Target: Container App 两者都会出错,只是因为添加 Target: Share Extension 。 这意味着错误主要来自Target: ShareExtension .

  2. 列出命令详细信息:

[Clang Path]/clang -arch arm64 -isysroot 
[iOS SDK Path]/iPhoneOS12.4.sdk 
-L[Project Path]/ios/DerivedData/Products/Debug-iphoneos 
-L[Project Path]/ios/DerivedData/Products/Debug-iphoneos/FMDB      <-- this 
-L[Project Path]/ios/DerivedData/Products/Debug-iphoneos/sqflite   <-- this 
-F[Project Path]/ios/DerivedData/Products/Debug-iphoneos 
-F[Project Path]/ios/Pods/../.symlinks/flutter/ios 
-filelist [Project Path]/ios/DerivedData/Build/Intermediates/Runner.build/Debug-iphoneos/ShareExtension.build/Objects-normal/arm64/ShareExtension.LinkFileList 
-Xlinker 
-rpath 
-Xlinker @executable_path/Frameworks 
-Xlinker 
-rpath 
-Xlinker @loader_path/Frameworks 
-Xlinker 
-rpath 
-Xlinker @executable_path/Frameworks 
-Xlinker 
-rpath 
-Xlinker 
@executable_path/../../Frameworks 
-miphoneos-version-min=12.4 
-dead_strip 
-Xlinker 
-object_path_lto 
-Xlinker [Project Path]/ios/DerivedData/Build/Intermediates/Runner.build/Debug-iphoneos/ShareExtension.build/Objects-normal/arm64/ShareExtension_lto.o 
-Xlinker 
-export_dynamic 
-Xlinker 
-no_deduplicate 
-fembed-bitcode-marker 
-fobjc-arc 
-fobjc-link-runtime 
-fapplication-extension 
-ObjC 
-lFMDB              <-- this 
-lsqflite           <-- this 
-lsqlite3           <-- this 
-framework Flutter  <-- this 
-e _NSExtensionMain 
-Xlinker 
-dependency_info 
-Xlinker [Project Path]/ios/DerivedData/Build/Intermediates/Runner.build/Debug-iphoneos/ShareExtension.build/Objects-normal/arm64/ShareExtension_dependency_info.dat 
-o [Project Path]/ios/DerivedData/Products/Debug-iphoneos/ShareExtension.appex/ShareExtension

错误详细信息:

ld: '[Project_Path]/ios/DerivedData/Products/Debug-iphoneos/FMDB/libFMDB.a(FMDatabase.o)' 
does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting 
ENABLE_BITCODE)
  • 所以搜索Target: ShareExtension的设置为 FMDB ,有 3 个结果:

    1. Other Linker Flags:-l"FMDB"
    2. Header Search Flags:"${PODS_ROOT}/Headers/Public/FMDB"
    3. Library Search Flags:"${PODS_CONFIGURATION_BUILD_DIR}/FMDB"
  • Library Search Flags是像DerivedData/Products/Debug-iphoneos/FMDB/libFMDB.a这样的路径吗? ,所以我overwrite它与 "" , git diff 的结果是添加新行: LIBRARY_SEARCH_PATHS = "";

  • 运行Target: ShareExtension检查结果: 这两行命令详细信息不见了

  • -L[Project Path]/ios/DerivedData/Products/Debug-iphoneos/FMDB
    -L[Project Path]/ios/DerivedData/Products/Debug-iphoneos/sqflite 
    
    

    错误变为(这也意味着上述更改有效):

    ld: library not found for -lFMDB
    
  • 搜索 FMDB再次,我猜是Other Linker Flags :-l"FMDB"就像 -lFMDB 的错误,所以我overwrite它与 "" (或左 "-ObjC" ),git diff 的结果是 添加新行: OTHER_LDFLAGS = "";OTHER_LDFLAGS = "-ObjC"; .

  • 运行Target: ShareExtension & Target: Container App现在两者都有效。

  • 检查change in git differ

    enter image description here enter image description here enter image description here

    关于Flutter:添加共享扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57442240/

    相关文章:

    ios - 无法重新解析位码包 : 'Invalid bitcode version 中的目标文件

    firebase - 获取 "CocoaPods could not find compatible versions for pod "Firebase/数据库“” flutter 错误

    dart - 如何在 Dart 中初始化 mixin 的不可变数据?

    async-await - 在 Flutter 中使用 Future 在异步任务中使用进度条对话框

    android - flutter中facebook应用程序的包名称和类名称

    ios - 在我的项目中安装 LayerKit 时出现问题

    ios - 如何在不安装cocoapods的情况下运行从github下载的xcode项目?

    ios - 应用程序扩展是在没有位码的情况下构建的 - 仅在 M1 mac 上

    ios - 使用 Cocoa Touch 框架构建

    dart - 使用 Flutter Slider 未正确触发 onChangeEnd