Reference something from a shared project

494 views Asked by At

So I am using Xamarin to create an Android App. All the android "stuff" will be in the Android project and I have created a Shared Project to house the business logic, so that I will be able to use it should I have to create an IOS app.

I have successfully referenced the Shared Project from the Android project - so far so good. So my Database code is in the shared project ready for any platform to use.

My app needs to connect to a webservice, so I wanted to house all that in the Shared Project but there seems to be no way to add references (web or otherwise) to a shared project - is this correct? surely it can't be or I wouldn't be able to use JSON.net in the Shared project or anything else that requires a reference to an external DLL...? Which would result in me duplicating any code like this multiple times, once in each platform.

Surely I am missing something here - any Google search returns how to reference a shared project from another project...Not what I need.

So the question is, can I add references in a Shared Project to a web service/3rd party DLL, if so, how do I do it?

Thanks for any help.

2

There are 2 answers

2
Mike Crawford On

iOS Apps can't use shared libraries that you create yourself. The only ones you can use are those provided by Apple, in the System frameworks, that you'll find in the iOS SDK.

You can use static libraries. That might or might not solve your problem.

Possibly Xcode is enforcing this rule.

For a simple test, can you share a single source file, rather than a library?

Also they aren't called "DLLs" on iOS or Mac OS X, they're called "dylibs".

0
Khaled On

It's not possible to use reference directive in Shared project. You will have to instantiate the references on the platform specific project (Project.iOS) and pass it to the class in the shared project.

Use AppDelegate to define web Services references.