Can't load wikitude monotouch binding - ios

The monotouch binding that I created for the Wikitude SDK framework does not work at run time. I created my binding by following these instructions: https://stackoverflow.com/a/13070064/42826.
When I try to instantiate my wrapper class at run-time, I get the following exception:
Wrapper type 'Wikitude.WTArchitectView' is missing its native
ObjectiveC class 'WTArchitectView'.
It looks like the native class WTArchitectView goes not get loaded by the binding assembly at run-time. The native library WikitudeSDK.a is indeed located in the binding assembly with the ObjcBindingNativeLibrary build action.
Here is my LinkWith declaration (notice the -ObjC that is required by the Wikitude native library):
[assembly: LinkWith ("WikitudeSDK.a", LinkTarget.ArmV7 | LinkTarget.Simulator, Frameworks = "CoreVideo Security SystemConfiguration CoreMedia AVFoundation CFNetwork CoreLocation CoreMotion MediaPlayer OpenGLES QuartzCore CoreGraphics", ForceLoad = true, LinkerFlags = "-ObjC", IsCxx = true)]
Most of my ApiDefinition.cs was created using Objective Sharpie.
Note: I only left a single function for testing purposes.
namespace Wikitude
{
[BaseType (typeof (UIView))]
interface WTArchitectView {
[Export ("initializeWithKey:motionManager:")]
void InitializeWithKey (string key, NSObject motionManager);
}
}
Here is the Wikitude SDK header file: http://pastebin.com/HKBED11u
My project has the ARMv7 + ARMv7s supported architectures.
Do I have to force loading the native library somehow or did I simply miss something obvious to get the wrapper to work?

The LinkWith attribute only mention ArmV7 and Simulator as LinkTargets. If your device is Armv7s, this could explain why it doesn't work.

Related

Xamarin iOS Swift library .a error on Visual studio mac

I have found some issue while run a iOS App on Xamarin iOS. Kindly help me to succeed.
I have tried to create a Xamarin iOS App. I have .a library. It contains NSObject class and single function.
import Foundation
#objc(CustomSwift)
class CustomSwift: NSObject {
func getValue() -> String {
return "Hi, This is a Custom swift.a"
}
}
And I created a fat library by using
lipo -create -output
I have imported .a library on Xamarin iOS Binding library project.
ApiDefinition.cs
using System;
using ObjCRuntime;
using Foundation;
using UIKit;
namespace CustomSwiftLibrary
{
[BaseType(typeof(NSObject))]
interface CustomSwift
{
[Export ("getValue")]
string Value { get; }
}
}
And I call my .a library class on ViewController.cs
CustomSwift customObject = new CustomSwift();
System.Diagnostics.Debug.Print(customObject.Value);

Swift: import framework but can't find class in it

I import a swift framework to a swift project, but when I call the class in this framework, Xcode throw a compile error "Use of undeclared type 'xxxx(class name)' ".
I feel Xcode have found the framework, otherwise it will complaint "can't find xxx(framework name)".
But why Xcode can't find the class of this framework.
I have tried remove and re-add framework, and delete DeivedData files, but all of them not work. I haven't use CocoaPods to import framework.
Any idea?
In a Framework that was built for Release (and not Debug), the class symbols need to be accessible.
Make sure you are you trying to access Public or Open classes from your Swift framework.
// set the Framework class to Public
public class rnHello{
// set the initializer to public, otherwise you cannot invoke class
public init() {
}
// set the function to public, as it defaults to internal
public static func world() {
print("hello from a static method")
}
}
Now you can access this via your Swift code or if you attach lldb using:
lldb) po rnHello.world()
Make sure that the FrameWorkSearch path in the BuildSettings of the project is reflecting the correct path to your framework.

Swift compiler: Printing the AST of a Swift file with 3rd party imports

I'm trying to print the Abstract Syntax Tree (AST) from a Swift file using the Swift compiler with the -print-ast flag. This is without Xcode & xcodebuild.
I'm stuck handling imports of 3rd party frameworks, built via Carthage. Given a source file with the following code:
Source
import Foundation
import BrightFutures // 3rd party framework
class MyAsyncService {
func asyncFunc() -> Future<String, NSError> {
return Promise<String, NSError>().future
}
}
Compiling for MacOS works
By specifying the framework search path (-F) the following command:
swiftc -print-ast Source.swift -F Carthage/Build/Mac
Produces the expected output:
import Foundation
import BrightFutures
internal class MyAsyncService {
internal func asyncFunc() -> Future<String, NSError>
#objc deinit
internal init()
}
Compiling for iOS?
I need to print the AST for a project only targeting iOS, with dependencies built for iOS.
When I try pointing to the frameworks built for iOS:
swiftc -print-ast Source.swift -F Carthage/Build/iOS
The command fails:
Source.swift:2:12: error: module file was created for incompatible target x86_64-apple-ios8.0: [...]/Carthage/Build/iOS/BrightFutures.framework/Modules/BrightFutures.swiftmodule/x86_64.swiftmodule
import BrightFutures // 3rd party framework
^
import Foundation
import BrightFutures
internal class MyAsyncService {
internal func asyncFunc() -> <<error type>>
#objc deinit
internal init()
}
I've tried also tried adding the -sdk flag:
-sdk $(xcrun --sdk iphoneos --show-sdk-path) to specify the iphoneos SDK, but this spits out an error about unsupported architectures.
How can I get this to build?
Looks like an alternative to printing the AST with the Swift compiler is to use SourceKit.
There's a CLI tool called SourceKitten which allows you to parse the structure of a Swift source file into JSON format, without needing to handle imports of 3rd party frameworks and other source files.

Linking failure with a MonoTouch native library binding

I am creating native library binding for the Wikitude SDK.
The MonoTouch app fails linking:
Undefined symbols for architecture armv7:
"std::__1::basic_string, std::__1::allocator >::find_last_of(char const*, unsigned long, unsigned long) const", referenced from:
WtUnzip::unzipFileTo(char const*, bool)in WikitudeSDK.a(wtunzip.o)
...
My LinkWith:
[assembly: LinkWith ("WikitudeSDK.a", LinkTarget.ArmV7, Frameworks = "CoreVideo Security SystemConfiguration CoreMedia AVFoundation CFNetwork CoreLocation CoreMotion MediaPlayer OpenGLES QuartzCore CoreGraphics", ForceLoad = true, LinkerFlags = "-lsqlite3.0 -ObjC", IsCxx = true)]
I have to admit that I am new to this MonoTouch/IOS world, by I am trying to get my head out of the water.
What should I do to get my app to link?
I just figured that I needed to add libc++ in my LinkWith. My new LinkWith looks like this:
[assembly: LinkWith ("WikitudeSDK.a", LinkTarget.ArmV7, Frameworks = "CoreVideo Security SystemConfiguration CoreMedia AVFoundation CFNetwork CoreLocation CoreMotion MediaPlayer OpenGLES QuartzCore CoreGraphics", ForceLoad = true, LinkerFlags = "-lsqlite3.0 -ObjC -lc++", IsCxx = true)]
Hopefully that can eventually help others.
I was dealing with an issue where the linking step was failing with "Native linking failed, undefined symbol: std::string::find_last_of(char const*, unsigned long, unsigned long)..."
It turned out the iOS Deployment Target for the app was apparently not matched with the original native library. By matching those up (by comparing against a working "consumer" of the same binding library) I was able to get past the errors.

How to use iOS framework with Unity?

I'm trying to use an iOS native framework inside Unity, but I don't know how.
Inside my C# script, I call a native function like this :
[DllImport ("__Internal")]
private static extern void writeHello();
void Start () {
writeHello();
}
I have drag the iOS framework inside my project like this :
Link to my image
But when I deploy my app on iPad, xCode showing this error :
Undefined symbols for architecture armv7: "_writeHello", referenced
from:
RegisterMonoModules() in RegisterMonoModules.o ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with
exit code 1 (use -v to see invocation)
I don't understand why, and I don't know if what I'm trying to do is possible.
Help! :)
Thanks,
Sennin
The iOS framework must be put in the xCode generated project, not in unity.
And the framework's functions must be wrapped in an extern "C" block (as shown here).
Then you will be able to use it in C# with dllimport.
The doc says that 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. The docs also says that subfolders are currently not supported, so, in your example, the "framework-helloUnity.framework" folder will be ignored.
It is important to note that .m files default to C-style bindings, while .mm files default to C++-style bindings. In other word, unless you use the extern "C" keyword, as Heilo suggested, your functions won't be found if you put them in .mm or .cpp files.
In other words, if you put the following:
void writeHello() {}
in a file named Assets/Plugins/iOS/myTestFile.m, your code should compile.
Found the solution thanks to this post : Calling Objective-C method from C++ method?
By doing like that :
void myWriteHello( void *test) {
[(id)test writeHello];
}
- (void) writeHello
{
NSLog(#"Hello World!");
}
and calling my C function from Unity
You have write the following function in your Xcode project any class
extern "C"
{
-(void) writeHello
{
}
}

Resources