最終確認日

GodotでiOS用プラグインのgodot ios pluginsを使いたい

プラグイン

godot-sdk-integrations/godot-ios-plugin

  • 現在は2022年9月にリリースされた3.5が最新
  • 3.5 では Godot 4に対応されていない
  • Update for Godot 4 #47のイシューは立っている状態
  • master ブランチはGodot 4.4 に対応しているようなことが書かれている。

使ってみる

リリース3.5ではなく、master ブランチから利用してみる。

クローン

サブモジュールを含むために、--recursive フラグをつけてクローンしてみる。

git clone --recursive https://github.com/godotengine/godot-ios-plugins.git
cd godot-ios-plugins

中身はこれらが入っている。

.
├── bin
├── CHANGELOG.md
├── godot
├── LICENCE
├── plugins
├── README.md
├── SConstruct
└── scripts

この godot がサブモジュールになっている。 この中はアップデートされておらず、Godot 3.5が入っているようだ。 そしてこの godot フォルダに入っているのは Godot 本体だね。 でも、必要なのはあくまでヘッダーファイルらしい。

自分が使っているは 4.4.stable なので、それをとってくる。サブモジュールのアップデートはちょいだるなので、バラバラにクローンすることにする。

クローン(やりなおし)

サブモジュールを含まずにクローンする。

git clone https://github.com/godotengine/godot-ios-plugins.git

godot-ios-plugins に移動し、その中に godotengine/godot Release 4.4-stableをクローンする。

cd godot-ios-plugins 

git clone --branch 4.4-stable --depth 1 https://github.com/godotengine/godot.git

godot フォルダの中にクローンできればおk。

SConsを使えるようにする

次に godot の ``

cd godot

scons platform=ios target=debug

SCons を使う。

scons は初めてだったので pip でインストールしておく。

$ python3 --version
Python 3.9.6

$ pip3 install scons
$ scons -v
sconsがないよと言われる

パスが通ってなかったので通す。

vi ~/.zprofile

export PATH="$HOME/Library/Python/3.9/bin:$PATH"

source ~/.zprofile

改めて scons -v をする。

$ scons -v

SCons by Steven Knight et al.:

SCons: v4.9.1.39a12f34d532ab2493e78a7b73aeab2250852790, Thu, 27 Mar 2025 11:44:24 -0700, by bdbaddog on M1Dog2021

SCons path: ['/Users/ユーザ名/Library/Python/3.9/lib/python/site-packages/SCons']

Copyright (c) 2001 - 2025 The SCons Foundation

ドキュメント通りに次のコマンドを実行してみた。

$ cd ~/GodotPlugins/godot-ios-plugins/godot
# 実行
$ scons platform=ios target=debug                                         HEAD

scons: Reading SConscript files ...

  

scons: *** Invalid value for enum variable 'target': 'debug'. Valid values are: ('editor', 'template_release', 'template_debug')

File "/Users/uruly/GodotPlugins/godot-ios-plugins/godot/SConstruct", line 287, in <module>

エラー通りに修正してみた。

$ scons platform=ios target=template_debug

実行された。けどエラーが出ている。

エラーを解決する

sh: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++: No such file or directory

デフォルトで使っているのが Xcode16.2.app なのでないんです。ごめんご。

$ xcode-select -p
/Applications/Xcode16.2.app/Contents/Developer
$ xcrun --find clang++

/Applications/Xcode16.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++

設定されているのにうまく行っていないね。

これでやってみる。

CC="xcrun clang" CXX="xcrun clang++" scons platform=ios target=template_debug

だめ。

つぎはこれ

CXX=/Applications/Xcode16.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ \
CC=/Applications/Xcode16.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
scons platform=ios target=template_debug

だめ。

Xcode.app のエイリアスを貼っておく。(実際にはXcode16.2.appが使われる)

sudo ln -s /Applications/Xcode16.2.app /Applications/Xcode.app

これでいけた。実行中。嘘でしょっていうぐらいMacがうるさい。

You don't have to wait for full engine compilation, as header files are generated first. Once the actual compilation starts, you can stop this command by pressing Ctrl + C.

と書かれている。実際にはヘッダーファイルのみしか使わないので、.cpp らへんのコンパイルをやっている途中で、Ctrl + C で終了させた。

ビルド後は作成したエイリアスをお片付けしておくといいかもね。

sudo rm /Applications/Xcode.app

.a ライブラリをビルドする

Static Library をビルドする。次を実行する。

./scripts/generate_static_library.sh <plugin_name> <debug|release|release_debug> <godot_version>

このとき <plugin_name>godot-ios-plugins/plugins 内のフォルダ名を利用する。

# 移動
cd ~/GodotPlugins/godot-ios-plugins

# 実行
./scripts/generate_static_library.sh inappstore release_debug 4.0

しかし、generate_static_library.sh はすでになかった。

├── README.md
├── SConstruct
└── scripts
    ├── extract_headers.sh
    ├── generate_headers.sh
    ├── generate_xcframework.sh
    ├── release_xcframework.sh
    └── timeout

この手順はスキップして良さそう。あくまで xcframework をビルドするために必要っぽいので。

スキップでおkだった!

.xcframework をビルドする

次のコマンドを実行する。

./scripts/generate_xcframework.sh <plugin_name> <debug|release|release_debug> <godot_version>

4.4.stable の場合でも指定するのは4.0

# 移動
cd ~/GodotPlugins/godot-ios-plugins

# 実行
./scripts/generate_xcframework.sh inappstore release_debug 4.0


xcframework successfully written out to: /Users/uruly/GodotPlugins/godot-ios-plugins/bin/inappstore.release_debug.xcframework

できた。

GodotでiOS用プラグインのgodot-ios-pluginsを使いたい-1748250414819

Godotプロジェクトに追加する

必要なのは .xcframework.gdip ファイルっぽい。

cd ~/GodotPlugins/godot-ios-plugins/plugins/inappstore

~/GodotPlugins/godot-ios-plugins/plugins/inappstore の中身はこんな感じ

.
├── in_app_store_module.cpp
├── in_app_store_module.d
├── in_app_store_module.h
├── in_app_store_module.o
├── in_app_store.d
├── in_app_store.h
├── in_app_store.mm
├── in_app_store.o
├── inappstore.gdip
└── README.md

とりあえず inappstore フォルダをコピー。

~/GodotPlugins/godot-ios-plugins/bin ないに生成されている inappstore.release_debug.xcframework を配置する。

.
├── in_app_store_module.cpp
├── in_app_store_module.d
├── in_app_store_module.h
├── in_app_store_module.o
├── in_app_store.d
├── in_app_store.h
├── in_app_store.mm
├── in_app_store.o
├── inappstore.gdip
├── inappstore.release_debug.xcframework
│   ├── Info.plist
│   ├── ios-arm64
│   │   └── libinappstore.arm64-ios.release_debug.a
│   └── ios-arm64_x86_64-simulator
│       └── libinappstore-simulator.release_debug.a
└── README.md

この inappstoreGodotプロジェクトの res://ios/plugins/の中に配置する。

Godotで開いてみると次のようなエラーが出ている。

ERROR: Invalid plugin config file inappstore/inappstore.gdip

inappstore.gdip をみてみる。

[config]
name="InAppStore"
binary="inappstore.xcframework"

initialization="register_inappstore_types"
deinitialization="unregister_inappstore_types"

[dependencies]
linked=[]
embedded=[]
system=["StoreKit.framework"]

capabilities=[]

files=[]

[plist]

binary="inappstore.release_debug.xcframework" にしてみた。

エラーが消えた!!

Export してみる

Godotプロジェクト側から Export した。

エラーが出ない!!

Xcodeからもビルド成功!

func _ready() -> void:
    if Engine.has_singleton("InAppStore"):
        apple_payment = Engine.get_singleton("InAppStore")
        MyUtility.add_log_msg("iOS IAP support is available.")

    else:
        MyUtility.add_log_msg("iOS IAP support is not available.")

GodotでiOS用プラグインのgodot-ios-pluginsを使いたい-1748251351538

ちゃんとプラグインが有効化されている!!Cool!

要約

#ChatGPTより引用

Godot 4.4 で iOS 向け InAppStore プラグインを導入するため、以下の手順を実施した:

  • godot-ios-pluginsmaster ブランチをサブモジュールなしでクローンし、godot/ ディレクトリに Godot 本体(4.4-stable)を配置
  • scons をインストールし、ヘッダーファイルを生成するために platform=ios target=template_debug でビルドを開始(途中で Ctrl+C で中断)
  • 使用中の Xcode16.2.appXcode.app にエイリアスすることで、scons が期待するパスを解決し、コンパイラの問題を回避
  • プラグインの .a ライブラリとシミュレータ対応バイナリを含んだ .xcframeworkgenerate_xcframework.sh でビルド
  • 出力された inappstore.release_debug.xcframeworkinappstore.gdip を Godot プロジェクトの res://ios/plugins/inappstore に配置
  • .gdip ファイルの binary フィールドを .xcframework のファイル名に合わせて修正し、Godot 上のエラーを解消
  • 最後に Godot 側でエクスポートと Xcode ビルドを実行し、Engine.has_singleton("InAppStore") でのプラグイン認識を確認

この一連の手順により、Godot 4.4 で iOS アプリ内課金(IAP)を可能にする InAppStore プラグインの統合が成功した

サイトアイコン
公開日
更新日