[英]Xamarin.iOS is not seeing reference to iOS binding library
I have created new Cocoa Touch Static Library in XCode.我在 XCode 中创建了新的 Cocoa Touch 静态库。 I have written code in: StaticLibrary.m:
我在:StaticLibrary.m 中编写了代码:
#import "StaticLibrary.h"
@implementation StaticLibrary
- (int)addX:(int)x toY:(int)y
{
int sum = x + y;
return sum;
}
@end
I have build project in Release-iphoneos and Release-iphonesimulator, then use terminal:我在 Release-iphoneos 和 Release-iphonesimulator 中构建了项目,然后使用终端:
lipo -create Release-iphoneos/StaticLibrary.a Release-iphonesimulator/StaticLibrary.a -output StaticLibraryFat.a
Now I have fat library "StaticLibraryFat.a".现在我有了胖库“StaticLibraryFat.a”。 Then I create new iOS Binding Library (Xamarin), click PPM -> Add Existing item -> StaticLibraryFat.a.
然后我创建新的 iOS 绑定库 (Xamarin),单击 PPM -> 添加现有项目 -> StaticLibraryFat.a。 So the file was added and the new libStaticLibraryFinal.linkwith.cs was created.
因此添加了该文件并创建了新的 libStaticLibraryFinal.linkwith.cs。 Code inside:
里面的代码:
using System;
using ObjCRuntime;
[assembly: LinkWith ("libStaticLibraryFinal.a", LinkTarget.Simulator, ForceLoad = true)]
I go to Mac, open terminal and use Objective Sharpie:我去 Mac,打开终端并使用 Objective Sharpie:
sharpie bind --output=StaticLibrary --namespace=StaticLibrary ~/Desktop/StaticLibrary/StaticLibrary/*.h --sdk=iphoneos12.1 -scope ~/Desktop/StaticLibrary
Now I copy content of ApiDefinitions.cs into iOS Binding Library (Xamarin) - to ApiDefinitions.cs in project.现在我将 ApiDefinitions.cs 的内容复制到 iOS 绑定库 (Xamarin) - 到项目中的 ApiDefinitions.cs。
ApiDefinition.cs ApiDefinition.cs
namespace NativeLibrary
{
[BaseType(typeof(NSObject))]
interface StaticLibrary
{
[Export("addX:toY:")]
int AddX(int x, int y);
}
}
I build iOS Binding Library (Xamarin).我构建了 iOS 绑定库 (Xamarin)。 In folder bin -> Debug there is NativeLibrary.dll.
在文件夹 bin -> Debug 中有 NativeLibrary.dll。
I create new iOS App (Xamarin).我创建了新的 iOS 应用程序 (Xamarin)。 PPM -> Add Reference -> Project -> Solution -> iOS Binding Library (Xamarin).
PPM -> 添加引用 -> 项目 -> 解决方案 -> iOS 绑定库 (Xamarin)。 In ViewController.cs I write:
在 ViewController.cs 我写:
using NativeLibrary
and和
NativeLibrary.AddX(1, 2);
but there is an error但有一个错误
"Using directive is unnecessary. The type or namespace name "Native Library" could not be found (are you missing a using directive or an assembly reference?)
“不需要使用指令。找不到类型或命名空间名称“本机库”(您是否缺少 using 指令或程序集引用?)
What am I doing wrong?我究竟做错了什么? When I add reference to iOS Class library then the reference is working perfectly.
当我添加对 iOS 类库的引用时,该引用工作正常。 Why reference to iOS Binding Library is not working?
为什么引用 iOS 绑定库不起作用?
Ok, I have solved it.好的,我已经解决了。 There was a problem with different namespaces, so Visual Studio can not connect everything.
不同的命名空间存在问题,因此 Visual Studio 无法连接所有内容。 Namespace at ApiDefinition.cs and Structs.cs must be the same as name of iOSBindingLibrary.
ApiDefinition.cs 和 Structs.cs 的命名空间必须与 iOSBindingLibrary 的名称相同。 The generated .dll file has name "NativeLibrary.dll" and I change it to namespace.dll, then at iOS application I add reference to this dll.
生成的 .dll 文件名为“NativeLibrary.dll”,我将其更改为 namespace.dll,然后在 iOS 应用程序中添加对此 dll 的引用。 then using directive (using "namespace").
然后使用指令(使用“命名空间”)。 In class I write name of XCode's library and create new object.
在课堂上,我写下 XCode 库的名称并创建新对象。 Everything is working perfectly.
一切正常。
This is Crazy, but in my case, just create the ios binding project in a different solution and add the binding project DLL directly in the ios project.这很疯狂,但在我的情况下,只需在不同的解决方案中创建 ios 绑定项目,并直接在 ios 项目中添加绑定项目 DLL。 it will work fine.
它会正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.