简体   繁体   English

构建消息错误时的 ARC 弱引用

[英]ARC Weak References when building message error

When i build my Ionic App with Capacitor in iOS, i get this error :当我在 iOS 中使用 Capacitor 构建我的 Ionic 应用程序时,出现此错误:

ARC Weak References - Cannot create weak reference in file using manual reference counting ARC 弱引用 - 无法使用手动引用计数在文件中创建弱引用

Xcode message erro ARC Weak References Xcode 消息错误 ARC 弱引用

The error seems to be from Cordova Plugins but i use Capacitor.该错误似乎来自 Cordova 插件,但我使用了电容器。 I try to reinstall the environnement and project several times, but still blocked since one week.我多次尝试重新安装环境和项目,但自一周以来仍然被阻止。 Thank you very much非常感谢

I had exactly the same error and I fixed it like this :我有完全相同的错误,我是这样修复的:

  1. In your Project Navigator (Xcode), one click on Pods在您的项目导航器 (Xcode) 中,单击 Pods
  2. In the second tab, one click on Targets -> CordovaPlugins在第二个选项卡中,单击 Targets -> CordovaPlugins
  3. Do the same thing that you did for your main project (App), change "Weak Reference in Manual Retain Release" to Yes.对主项目(应用程序)执行相同的操作,将“手动保留发布中的弱引用”更改为是。
  4. Build建造

It depends on your build results but after that, I had to replace in a CordavaPlugins file the type of a value.这取决于您的构建结果,但在那之后,我不得不在 CordavaPlugins 文件中替换值的类型。 It was "__weak ...." and I replace with "__strong ....".它是“__weak ....”,我替换为“__strong ....”。

The first time, I go with the way from here: https://stackoverflow.com/a/62679942/1979190第一次,我从这里走: https : //stackoverflow.com/a/62679942/1979190

But this way will lead to many issues as EXC_BAD_ACCESS because some Cordova Plugins do not support that way.但是这种方式会导致许多问题,如EXC_BAD_ACCESS因为某些 Cordova 插件不支持这种方式。

My teammate found a way to resolve this issue.我的队友找到了解决此问题的方法。 The root cause is from Capacitor, I don't know why they set Compiler flags to -fno-objc-arc for all files from CordovaPlugins .根本原因来自电容器,我不知道他们为什么将Compiler flags设置为-fno-objc-arc所有来自CordovaPlugins文件。

We just need to revert the Compiler flags to empty like this image below to avoid all error messages related to ARC Weak References .我们只需要像下图一样将Compiler flags恢复为empty ,以避免与ARC Weak References相关的所有错误消息。

在此处输入图片说明

But every time you run npx cap update or npx cap sync everything will be reset to -fno-objc-arc ^^.但是每次运行npx cap updatenpx cap sync所有内容都将重置为-fno-objc-arc ^^。

So we need to write a script to set Compiler flags to empty for all files from CordovaPlugins after we run these commands.因此,我们需要编写一个脚本,在运行这些命令后,将CordovaPlugins所有文件的Compiler flags设置为empty

We will add this script below Podfile ( ios/App/Podfile ) to do the job.我们将在 Podfile ( ios/App/Podfile ) 下面添加这个脚本来完成这项工作。

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if ['CordovaPlugins'].include? target.name
      target.build_phases.each do |build_phase|
        if (build_phase.display_name.eql? "Sources")
          build_phase.files.each do |file|
              if (file.settings)
                settings = file.settings
                settings["COMPILER_FLAGS"] = ""
                file.settings = settings
              end
          end
        end
      end
    end
  end
end

Hope it help!希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM