LoginSignup
1
0

【iOS】Realmsをインストールする際に出会ったいくつかのエラーとその対処

Posted at

Cocoapodsを使ってRealmsをインストールする際にいくつかのエラーが出てしまって、すごい困ってました。
なんとなくエラーを解消することができましたので、その取り組みについてまとめてみました。

一応、ビルドファイルどPodfileを綺麗に!

下記の方法を適用する前に、XcodeのビルドファイルとPodfileを綺麗にすることをおすすめします。
具体的には、
・ビルドファイル→Cmd+Shift+Kのショートカットでクリアする。
・Podfile→ターミナルから「pod deintegrate」入力して、ProjectからCocoapodsを削除、ProjectフォルダからCocoapods関係のファイルを削除する(Podfile、Podfile.lock、.xcworkspace)

最新バージョンのRealmsがインストールできない

Realmsの最新バージョンは、現時点(2024年3月17日)で「10.48.1」ですが、何故かインストールすると、「10.39.1」バージョンがインストールされてしまいました。
ちなみにPodfileは下記の通りでした。

platform :ios, '12.0'

target 'MyProject' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyProject
  pod 'RealmSwift'

end

そこで、Podfileを削除して再インストールしてみたり、Projectを再ビルドしてみたりしてみましたが、事象は直らず、、、

しかし、解決は意外と簡単で、下記のようにPodfileに「'~>10'」をつけてバージョンを設定したら、最新バージョンのインストールが無事にできました。

platform :ios, '12.0'

target 'MyProject' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyProject
  pod 'RealmSwift', '~>10'

end

스크린샷 2024-03-16 18.29.55.png

バージョン設定オプションは、Cocoapodsのマニュアルによりますと以下のようです。

Besides no version, or a specific one, it is also possible to use logical operators:
'> 0.1' Any version higher than 0.1
'>= 0.1' Version 0.1 and any higher version
'< 0.1' Any version lower than 0.1
'<= 0.1' Version 0.1 and any lower version
In addition to the logic operators CocoaPods has an optimistic operator ~>:
'~> 0.1.2' Version 0.1.2 and the versions up to 0.2, not including 0.2 and higher
'~> 0.1' Version 0.1 and the versions up to 1.0, not including 1.0 and higher
'~> 0' Version 0 and the versions up to 1.0, not including 1.0 and higher

つまり、「~> 10」というのはバージョン10以内での最新バージョンを取得するってことです!

ビルドする際に「Sandbox: rsync.samba (13105) deny(1)....」的なエラーが出てくる

なんとかRealmsの最新バージョンのインストールができて、いよいよProjectをビルドしたところが、なんと、、、Sandbox:rsync.....みたいなエラーが出てしまい、ビルドに失敗してしまいました。

これについて調べたところ、Xcode > Project > MyProject > Build Settings > Build Optionsから「ENABLE_USER_SCRIPT_SANDBOXING」を「NO」と設定すれば、解決できるようです。

image.png

元々XCode14ではENABLE_USER_SCRIPT_SANDBOXINGのデフォルト値が「NO」になっていましたが、XCode15からはデフォルト値が「YES」に変更されたようです。

しかし、ENABLE_USER_SCRIPT_SANDBOXINGをNOに設定することによって、脆弱性が生まれる可能性があるようで、そこは注意が必要です。
でも、現時点でこのエラーを解決する確かな方法は、これしかいないようで、、、
しばらくはこの方法にしておきたいですね、、、

ENABLE_USER_SCRIPT_SANDBOXINGとは?
→Xcode14のリリースの際に追加された機能であり、公式ドキュメントやリリースノートには次のように書いていました。

If enabled, the build system will sandbox user scripts to disallow undeclared input/output dependencies.

You can now enable sandboxing for shell script build phases using the ENABLE_USER_SCRIPT_SANDBOXING build setting. Sandboxing blocks access to files inside the source root of the project as well as the Derived Data directory unless you list those files as inputs or outputs. When enabled, the build fails with a sandbox violation if a script phase attempts to read from or write to an undeclared dependency, preventing incorrect builds. (90506067)

ビルド時に「Double-quoted include in framework header」が出る

これもXcode > Project > MyProject > Build Settings > Build Optionsから「CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER」を「YES」→「NO」と指定したら解決できました。

image.png

ついにビルド成功!しかし謎のWarningが、、、

なんとかビルドする事までは成功してましたが、「Create Symlinks to Header Folders' warning」という謎のWarningが表示されていました。
調べたところ、Podsfileに下記のラインを追加すると解決できるらしいですが、ビルドには影響はなかったため、まだ検証はしてないです。

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'Realm'
      create_symlink_phase = target.shell_script_build_phases.find { |x| x.name == 'Create Symlinks to Header Folders' }
      create_symlink_phase.always_out_of_date = "1"
    end
  end
end

終わりに

以上が私が出会ったエラーでした。
まだ本格的にRealmsを使っていないのに、こんなにエラーが出るなんて、、、
なんだか疲れてしまいました(笑)
でも、Cocoapodsの設定や、Xcodeのビルドについて良い勉強になったと思いますので、
これからも頑張って勉強していきたいと思います!

参考文献

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0