Flutter 集成到iOS及混合栈探索遇到的问题

环境:Flutter 1.9.1 fix6

1.The application’s Info.plist does not contain CFBundleVersion.

默认生成的Flutter module里面没有bundle version及 build号, 填写上即可.

2.为了方便大部分测试可能是在模拟器上进行的,这样首先避免了设备添加证书的限制。

直到发现了一个问题,这个问题只在模拟器上出现,真机上正常:切换engin 的viewcontroller

在iOS模拟器下,第二次使用engin 创建FlutterViewContainer时, initWithEngine: 会crash,报错如下

Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

这个错误是由于僵尸指针导致。打开Zombie 指针调试后 可以看到控制台打印如下错误

[FlutterView setAccessibilityElements:]: message sent to deallocated instance 0x7ff4b30a6dc0

使用Instruments Zombie 工具调试具体信息如下。

Flutter 集成到iOS及混合栈探索遇到的问题Flutter 集成到iOS及混合栈探索遇到的问题
zombie.png

最终定位到源码,是engin下的setViewController:方法导致

self.iosPlatformView->SetOwnerViewController(_viewController); 
"flutter::PlatformViewIOS::SetOwnerViewController(fml::WeakPtr<FlutterViewController>)+0x21"    

相关engin源码
https://github.com/flutter/engine/blob/master/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm

这个问题在真机上不会出现,具体原因未进行深入排查。如果不改源码自己维护engin的话,只能真机测试了。
之后改为了真机测试,也遇到了一些配置问题。

3.flutter module中如过不使用第三方plugin或者使用纯dart package可能不会出现异常,引用三方plugin时报如下错误
Could not find or use auto-linked framework 'Flutter'
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_FlutterError", referenced from:
      objc-class-ref in BatteryPlugin.o
  "_OBJC_CLASS_$_FlutterMethodChannel", referenced from:
      objc-class-ref in BatteryPlugin.o
  "_OBJC_CLASS_$_FlutterEventChannel", referenced from:
      objc-class-ref in BatteryPlugin.o
  "_FlutterMethodNotImplemented", referenced from:
      -[FLTBatteryPlugin handleMethodCall:result:] in BatteryPlugin.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方法:
https://github.com/flutter/flutter/issues/17749
you have to have to set ONLY_ACTIVE_ARCH = YES for debug builds. Write this to you podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '4.2'
      config.build_settings['SUPPORTED_PLATFORMS'] = 'iphoneos iphonesimulator'
      if config.name == "Debug" || config.name == "Debug-alpha" || config.name == "Debug-live" || 
config.name == "Debug-development"
        config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
      else
        config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
      end
    end
  end
end

将以上添加到podfile中。

4.Flutter.framework: Permission denied

Command PhaseScriptExecution failed with a nonzero exit code

Flutter 集成到iOS及混合栈探索遇到的问题Flutter 集成到iOS及混合栈探索遇到的问题
permission denied.png

解决:
https://github.com/flutter/flutter/issues/40146
packages/flutter_tools/bin/xcode_backend.sh 中 144行 将
RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -exec chmod a-w "{}" ;

替换为
RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -iname '.h' -exec chmod a-w "{}" ;

这个问题在1.9.1 fix6版本之前出现,升级到1.12版本已经修复这个问题

       

留言

本站文章如未特殊注明,均为原创,转载请注明出处: 未必平凡  本文链接地址: https://vv2014.com/1390.html