Unity iOS - Cannot import functions from .Bundle
Asked Answered
T

1

5

Currently trying to create a wrapper for an iOS framework on Unity.

I made a .bundle, containing basic objective-c code :

sample.h :

#import <Foundation/Foundation.h>

extern "C"
{
    void SampleFunction(); // this is going to call already bridged swift or objc code
}

sample.mm :

#import "Sample.h"
#import <SDK/SDKFunctions.h>

void SampleFunction()
{

    // my sweet functions calls

}

The SDK is included in the bundle as a .framework (references in "Linked Frameworks and libraries"). The bundle target is iOS.

The bundle builds successfully.

The bundle is placed in Unity under "Assets/Plugins/iOS", marked as "iOS" and "Add to Embedded Binaries"

Then, in Unity, there is a simple C# script calling SDK functions :

sample.cs

public class BundleImportSample : MonoBehaviour {


    #if UNITY_IOS
        [DllImport("__Internal")]
        private static extern void SampleFunction();
    #endif
        void Start()
        {
    #if UNITY_IOS
            SampleFunction();
    #endif
        }
    }

When I test this code in the editor I get the following error :

EntryPointNotFoundException: SampleFunction

If I build the generated project on iOS, I get a similar issue :

ld: symbol(s) not found for architecture arm64

Note : I used the following tutorial as guideline : http://blog.mousta.ch/post/140780061168

Why is SampleFunction() not found in __Internal ?

Tubule answered 22/6, 2018 at 13:5 Comment(2)
I don't have experience doing this, but looking at the tutorial; Why are you using "__Internal"? on the example they do: [DllImport ("SwiftBeep")] where "SwiftBeep" was the name of the project/class/etc...Discomposure
On iOS, the DLL are loaded in __internal. See Unity documentation : docs.unity3d.com/Manual/PluginsForIOS.htmlTubule
T
6

Code was fine.

The issue was about slices in the .bundle. It was built for i386 / x86_64 instead of arm64 / armv7 /armv7s.

To avoid this issue check the following options on your target :

  • Build on "Generic iOS device"
  • Build settings : "Build Active Architecture Only : NO"
  • Build settings : "Architecture : Standard architecture"
Tubule answered 27/6, 2018 at 8:23 Comment(3)
You save my day. Thanks :-)Phosgene
What are those build settings of? The bundle or the unity project? I'd like to create a bundle for iOS and one for macOS: where should i place them?Bacciferous
Those are the build settings of the bundle (a .framework), in XCode. I don't remember about bundle location good pratices; but Unity documentation was quite precise about this.Tubule

© 2022 - 2024 — McMap. All rights reserved.