I’m trying to add a simple iOS plug in to my project. I’m having no luck so I’ve stripped it down to the basic and still nothing is working. I’ve tried a few things…
I’m using Unity Pro with the Pro iOS licence v3.5.5f2 (most recent).
So here’s my iOS script
TestPlugIn.m
int IntReturn()
{
return 4;
}
I’ve tried variations of this (.mm extension, adding extern “C” when changing it to a .cpp/.mm file, adding the inline keyword, splitting it into a .h/.cpp or .h/.mm file which generate the same results).
In my C# script I have the following
public class TestScript : MonoBehaviour
{
private void Start()
{
Debug.Log( IntReturn() );
}
[DllImport ("__Internal")]
private static extern int IntReturn();
}
Now I’ve tried adding this to the generated Xcode project in a number of ways.
- Adding to the Unity project under
‘Assets/Plugins/iOS’ (no sub folders). - Adding to the ‘Classes’ folder of a
pre-generated Xcode project.
In both cases I get the following linker errors when building the generated Xcode project (generated both through the Build Settings options and BuildPipeline.BuildPlayer) because the PlugIn source files have not beed added to, or built by, the Xcode project.
Undefined symbols for architecture armv6:
"_IntReturn", referenced from:
RegisterMonoModules() in RegisterMonoModules.o
ld: symbol(s) not found for architecture armv6
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(null): "_IntReturn", referenced from:
(null): RegisterMonoModules() in RegisterMonoModules.o
(null): Symbol(s) not found for architecture armv6
(null): Linker command failed with exit code 1 (use -v to see invocation)
Looking at the generated project there is no reference to the TestPlugIn.m file, the only reference to the IntReturn function is in the Register Modules file and the Unity generated dlls.
Now, if I manually copy the plug-in files to the classes folder, and manually add them to the project, they work fine. The project builds, copies over to the iPhone and runs quite happily.
But you can’t exactly have an automated build process when you have to manually add files to a project half way through.
So, what am I doing wrong because according to the iOS plug-in documents I’m doing everything I should. Any help is appreciated.
(I should also mention that the ‘Bonjour Browser Sample’ on the iOS Plug Ins documentation page generates the same issues too, even when I change the ‘Code’ folder to ‘Assets/Plugins/iOS’)
Thanks
Lee