美文网首页
'Flutter/Flutter.h' file not fou

'Flutter/Flutter.h' file not fou

作者: 東玖零 | 来源:发表于2021-06-11 20:43 被阅读0次

    已有项目集成flutter,集成方式是Option A - Embed with CocoaPods and the Flutter SDK

    按照官网的步骤到打开xcode编译却报错,'Flutter/Flutter.h' file not found!!!!!

    还有人说iOS工程命名不规范,我重新建工程结果还是 Flutter/Flutter.h' file not found!

    看完这个发现我没有官方说的这个错误,执行 flutter doctor,有一个告警,提示cocopod版本低于1.10.0,我的版本为1.8.4。

    [!] The version of CocoaPods used to generate the lockfile (1.10.1) is higher than the version of the current executable (1.8.4). Incompatibility issues may arise.
    

    只能升级cocopod,网上找到的升级命令如下:

    sudo gem install cocoapods

    我的ruby版本是2.6.0提示文件找不到,具体的错误如下。

    Password:
    Building native extensions. This could take a while...
    ERROR:  Error installing cocoapods:
        ERROR: Failed to build gem native extension.
    
        current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.1/ext/ffi_c
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20210612-9541-peq40b.rb extconf.rb
    checking for ffi.h... *** extconf.rb failed ***
    Could not create Makefile due to some reason, probably lack of necessary
    libraries and/or headers.  Check the mkmf.log file for more details.  You may
    need configuration options.
    
    Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
        --with-ffi_c-dir
        --without-ffi_c-dir
        --with-ffi_c-include
        --without-ffi_c-include=${ffi_c-dir}/include
        --with-ffi_c-lib
        --without-ffi_c-lib=${ffi_c-dir}/lib
        --enable-system-libffi
        --disable-system-libffi
        --with-libffi-config
        --without-libffi-config
        --with-pkg-config
        --without-pkg-config
    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
    You have to install development tools first.
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
        from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
        from extconf.rb:10:in `system_libffi_usable?'
        from extconf.rb:42:in `<main>'
    
    To see why this extension failed to compile, please check the mkmf.log which can be found here:
    
      /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.1/mkmf.log
    
    extconf failed, exit code 1
    
    Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.1 for inspection.
    Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.1/gem_make.out
    
    
    

    网络上解决办法就是升级ruby,由于我不想安装rvm,我就去官网下载了一个最新的稳定版本3.0.1,按照官网的步骤编译安装(噩梦的开始),也安装成功了,ruby -v 显示是3.0.1。

    于是我重复上面的步骤重新安装cocopod,又是遇到一个新错误:

    ERROR: While executing gem ... (Gem::Exception)
        OpenSSl is not available. Install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources
    

    于是我使用brew 更新openssl,发现brew又要更新,一顿操作把brew 安装的内容都更新了一遍,真是ma mai pi!!!!!

    按网上资料,设置openssl的路径重新编译ruby3.0.1,再次安装,结果还是失败的。

    然后又找如何删除ruby,找到源码文件夹执行 make uninstall 就可以了。

    没办法只能寻找另一个方法,使用rvm安装,rvm安装前又要生成GPG keys,官网:https://rvm.io/

    生成了KEY,下载RVM的时候提示被服务器拒绝访问。最后的解决办法是关闭WIFI。因为我的笔记本电脑连了有线(wifi经常掉线)。

    最后我还是安装了RVM,重新安装ruby2.7.2,再次安装cocopods。

    升级cocopods成功后,pod install完成,iOS和flutter混合工程总算是能编译成功了!

    吐槽:我也不知道我是经历了什么,升级了一堆的软件,忙了一下午,心好累啊!!

    千万记住不要轻易的去编译源码安装ruby!!!!!!

    最后补一张图,坚持总有收获,加油!

    Simulator Screen Shot - iPhone 8 - 2021-06-11 at 20.59.39.png

    相关文章

      网友评论

          本文标题:'Flutter/Flutter.h' file not fou

          本文链接:https://www.haomeiwen.com/subject/ctiveltx.html