Unity iOS - 无法从 .Bundle 导入函数
Unity iOS - Cannot import functions from .Bundle
目前正在尝试为 Unity 上的 iOS 框架创建包装器。
我制作了一个 .bundle,包含基本 objective-c 代码:
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
}
SDK 作为 .framework 包含在包中("Linked Frameworks and libraries" 中的引用)。捆绑包目标是 iOS.
包构建成功。
捆绑包放在 Unity 中 "Assets/Plugins/iOS" 下,标记为 "iOS" 和 "Add to Embedded Binaries"
然后,在Unity中,有一个简单的C#脚本调用SDK函数:
sample.cs
public class BundleImportSample : MonoBehaviour {
#if UNITY_IOS
[DllImport("__Internal")]
private static extern void SampleFunction();
#endif
void Start()
{
#if UNITY_IOS
SampleFunction();
#endif
}
}
当我在编辑器中测试此代码时,出现以下错误:
EntryPointNotFoundException: SampleFunction
如果我在 iOS 上构建生成的项目,我会遇到类似的问题:
ld: symbol(s) not found for architecture arm64
注意:我使用以下教程作为指导:http://blog.mousta.ch/post/140780061168
为什么在 __Internal 中找不到 SampleFunction()?
代码很好。
问题与 .bundle 中的切片有关。它是为 i386 / x86_64 而不是 arm64 / armv7 /armv7s 构建的。
要避免此问题,请检查目标上的以下选项:
- 基于"Generic iOS device"
- 构建设置:"Build Active Architecture Only : NO"
- 构建设置:"Architecture : Standard architecture"
目前正在尝试为 Unity 上的 iOS 框架创建包装器。
我制作了一个 .bundle,包含基本 objective-c 代码:
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
}
SDK 作为 .framework 包含在包中("Linked Frameworks and libraries" 中的引用)。捆绑包目标是 iOS.
包构建成功。
捆绑包放在 Unity 中 "Assets/Plugins/iOS" 下,标记为 "iOS" 和 "Add to Embedded Binaries"
然后,在Unity中,有一个简单的C#脚本调用SDK函数:
sample.cs
public class BundleImportSample : MonoBehaviour {
#if UNITY_IOS
[DllImport("__Internal")]
private static extern void SampleFunction();
#endif
void Start()
{
#if UNITY_IOS
SampleFunction();
#endif
}
}
当我在编辑器中测试此代码时,出现以下错误:
EntryPointNotFoundException: SampleFunction
如果我在 iOS 上构建生成的项目,我会遇到类似的问题:
ld: symbol(s) not found for architecture arm64
注意:我使用以下教程作为指导:http://blog.mousta.ch/post/140780061168
为什么在 __Internal 中找不到 SampleFunction()?
代码很好。
问题与 .bundle 中的切片有关。它是为 i386 / x86_64 而不是 arm64 / armv7 /armv7s 构建的。
要避免此问题,请检查目标上的以下选项:
- 基于"Generic iOS device"
- 构建设置:"Build Active Architecture Only : NO"
- 构建设置:"Architecture : Standard architecture"