iOS Plugin Files Not Being Added To Project

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

Ok, to answer my own question and in case anyone else has the same issue.

I took the Unity docs at face value

All files with extensions .a,.m,.mm,.c,.cpp located in the Assets/Plugins/iOS folder will be
merged into the generated Xcode project automatically

What I took this to mean was in the project view in Unity you needed the following hierarchy (since the majority of the work is done inside Unity itself, I didn’t think at this point they were referencing folder structures on disk)

[2712-wrong+path.png|2712]

What it really means is to have the ‘Assets/Plugins/iOS’ folder structure on disk, so removing the additional Assets folder, and having only Plugins/iOS in the Project view caused the plug-ins to be added as they should.

[2713-right+path.png|2713]

One of those things that is obvious now but when reading the documentation it isn’t. The documentation could do with a lot more images to make things like this clearer!