I am trying to learn how to create iOS plugin for Godot engine. I just created simple iOS plugin which stores some key value data in UserDefaults and retrieve it. This is just an example, i know we don’t have to create separate plugin for every platform and i can use Gdscript's api to store some key value data as well. My goal is to learn how to create iOS plugin from scratch. Here are the steps which i followed
Download Godot source code from master branch
brew install scons
cd to Godot source code directory in terminal and ran scons platform=ios target=template_release -j4
Open xcode and selected static library for iOS
Go to the downloaded godot-repo, navigate to platform / iOS folder and add this path to Build settings => Header Search Paths in Xcode
Add the required code to my objective-c file & selected my iOS simulator and ran Command + B for the library to be build which is successfull
Create my Godot poject in Godot editor and created a bin folder
Found the libmystatticlib.a from my iOS project and copy pasted it to the bin folder of my iOS project
Create a folder called iOS and inside that a plugins folder. In pulgins folder created .gdip file and copied the code from docs and refactored it according to my needs
In Godot, click project => Export => Add iOS => Click Fix Import Error => Added bundle identifier & App Store team id
Created a button in Godot tscn and added pressed listener to gdscript file
On button pressed code , added the followed code
var bridge = load("res://ios/plugins/MyStaticlib.gdip").new()
bridge._save_value("Hello", "keyhello")
When i try to export my godot project for iOS i keep getting error saying Invalid plugin config file MyStaticlib.gdip
Which step am i doing wrong. Please help
Here is the sample ios plugin repo Here is the sample godot project repo
While I may not be able to provide an answer for you yet, I am a couple steps away from you. I am also trying to get into the iOS plugin development. I had the same error with the photo_picker module under the godot-ios-plugins github repo. I had to rename the binary to the exact same name as the xcframework to remove my issue. I don’t think that is an issue with yours. But you can check out the rest of their gdip file and see if anything sticks out. Try maybe removing something one by one.
If you can share any sources that you are using to help you with your journey, it could help a lot.
@djolero Thanks for the reply. I think the biggest mistake which i made was to create my own static library without completely understand the whole process. I will also pick the photo-picker plugin and try to make it work during weekend. My static lib did not contain initialization and deinitialization code when i try looking at other ios plugin. Will get back to you soon
I got the photo picker code to compile into an xcframework and I added it to my Godot project. I was able to enable it in the export settings, make the ipa and test it on my iPad. I’m on Godot 4.2 and the newest xcode. I got it to request the permissions for the photo gallery and camera, and it allowed me to select a photo. I just had an error after selecting which i think is related with the Objective-C code.
Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)"
I looked online and it seems that this is a common error when fetching photos from iOS, but not a clear solution to it.
The good thing is that it does talk back to Godot partially so there is a lot of good stuff to pick. I’m working on it today, trying to get it to work for the newer iOS. If I can figure it out, I wanna start working on the other plugins too and start making tutorials for the iOS side.
Update: The image data is actually being sent to Godot. I see the image instance in Godot is not empty, and when checking the individual pixel color data, it seems to match the colors inside the image from the iPad. Originally I kept seeing it fill a grey color inside a TextureRect. But I quickly realized that the Godot side of the code needed a little bit of a tweak to work. So I am in fact getting an image.
I downloaded the whole godot ios plugins repo from here: https://github.com/godotengine/godot-ios-plugins
Then I just followed the instructions on that same README.md file.
The very last instruction tells you how to compile the xcframework.
First after downloading the repo, I rebuilt the godot inside of it to match my current version (4.2).
Then I ran the shell script to make the xcframework specifically for the photo_picker
cd godot
git fetch
git checkout origin/4.2
scons platform=ios target=template_debug
cd ..
./scripts/generate_xcframework.sh photo_picker release_debug 4.0
You might be able to change that last number to 4.2 and still have it work. It worked for me in Godot 4.2 the way I wrote it.
After it got generated, I copied the xcframework folder and the gdip file already included into my working Project folder under ios/plugins
@djolero I created my own static library using xcode. I added the required files from the ios photo_picker plugin. I downloaded the Gogodt source code, switched to 4.2 branch and ran the following commands as well
I am not sure which one of the above command is correct, so i tried all 5 of them
I am using an m1 Mac and i want to run it on an ios simulator as i don’t have a real ios device. I added the Header Search Path in Build Settings pointing to Godot Source code of platform => iOS
Now when i try to build my project in xcode i get below error
So I couldn’t get it to work on a simulator, said that I didn’t have a simulator that supports arm64, which is weird being on an M chip Mac. I’ll see if I can get it to work in a simulator. I’m still taking a look at your code, but initially what jumped out is that you had one header and one .m file, but the photo picker had 2 hearder files and used a .mm file.
@djolero Yup i made a mistake. Can you check if the photo picker plugin works on simulator. You can ignore my code as it has lot of issues and i was not following the right template. My goal is to get some plugin working on a simulator
Yeah because in their script file that’s what they listed as options. I initially also tried 4.2, then got that error. So I put in 4.0, and it worked fine still.
I think it’s because they haven’t really changed much between 4.0 and 4.2 as far as ios plugin integration goes since that’s not their priority.
Btw I sent you a direct message in Reddit earlier, if it makes it faster.