2
votes

When i build my Ionic App with Capacitor in iOS, i get this error :

ARC Weak References - Cannot create weak reference in file using manual reference counting

Xcode message erro ARC Weak References

The error seems to be from Cordova Plugins but i use Capacitor. I try to reinstall the environnement and project several times, but still blocked since one week. Thank you very much

2

2 Answers

4
votes

I had exactly the same error and I fixed it like this :

  1. In your Project Navigator (Xcode), one click on Pods
  2. In the second tab, one click on 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. It was "__weak ...." and I replace with "__strong ....".

0
votes

The first time, I go with the way from here: 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.

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.

We just need to revert the Compiler flags to empty like this image below to avoid all error messages related to ARC Weak References.

enter image description here

But every time you run npx cap update or npx cap sync everything will be reset to -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.

We will add this script below Podfile (ios/App/Podfile) to do the job.

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!