I'm having trouble getting my shared project to work with my UWP application. The shared project uses Mono.Data.Sqlite for the database connection and it works on Android and iOS, but I don't know what reference I'm missing since it doesn't recognize the library on UWP. Anyone tried this before?
On Windows Phone the SQLite engine does not come by default so you need to add support for it. This is an easy step. Just add the precompiled binaries. A way how you can do this can be read here.
This is why the Mono.Data.Sqlite namespace will not work on UWP applications. To work around this issue you have to use compiler switches. For example:
#if !WINDOWS_PHONE
using Mono.Data.Sqlite;
#endif
#if WINDOWS_PHONE
using Whatever namespace it is.
#endif
This will work with SharedProjects. An other option would be a PCL (Portable Class Library) that contains your shared code. With this you can use the SQLite-NET – Cross-Platform ORM.
Related
We are getting following exception when we try to call storagefolder.getfilesasync() method in Xamarin Forms UWP enviornment.
is ther any alternative to that?
I suspect the reason is that you are trying to use files inside the shared Portable Class Library. Because this library is shared across UWP, Android and iOS, you can't use Windows specific StorageFile there.
To work around this, you will need to create an interface for file access and implement it for each operating system separately. Working with files is very well described in Xamarin Documentation.
I have a dot net dll which uses System.Drawing.dll for using classes like Bitmap, Rectangle,Size etc.. But my dll cannot be used on xamarin... Plz suggest me what else should I use in my dot net dll for using Bitmap etc.so that it can run on xamarin.
Your dot net dll is complied for specified platform, such as Windows. so you cannot use it in other phone OS. It is no way for you to directly use dll in Xamarin unless you build it for portable class. But portable class is a generic class base, it lack of lots of classes. Such as Bitmap, it is different in different OS like Nick Turner said, so you will failed to build your source file.
The best way, you can reuse some none-platform dependent code in you dll, but for others, you need to write new code in each Android, ios, winphone project. So the Xamarin is not so wonderful for writing once, using every where. There is still lots of work in Xamarin, especially for platform specific code.
I want to use a C++ library (static/dynamic) on my Xamarin.Android and Xamarin.iOS project.
Should the C++ library be static or dynamic in order to be used on both Xamarin.Android and Xamarin.iOS projects, as i'm thinking of using C# DLLimport/SWIG tool to use the C++ library as C#.
(I heard that iOS forbids the usage of dynamic libraries in the apps.) What can be the best approach for me?
Thanks!
You are correct, iOS does not allow you to use dynamic libraries, so at least for iOS you must build the C++ library as a static library.
I believe both a static and a dynamic library work fine on Android, so there it doesn't matter which you choose.
As soon as iOS8 has been released in September, you will be able to add support for iOS Embedded frameworks to all devices with a minimum deployment target of iOS8. In fact you can now add dynamic libraries when you target is not less than iOS8.
Anyways there are some pitfalls, depicted here.
I've currently built a service layer and API which I'm consuming from an ASP.NET website, Windows Phone app, and a Windows 8 metro app - the key to all of them being a project containing model classes which is a portable class library project, and is shared as a reference between all of them. This architecture works fine and without any issues.
However, I've recently started experimenting with Xamarin - specifically the iOS functionality (with a view to moving onto Android later). My initial assumption was that I would be able to utilise this model library as I do with the other projects - however, I've since realised this this isn't the case.
When I first added a reference to my model class library to my Xamarin.iOS project (in Visual Studio), I was greeted by the error:
'The current project does not support references to Portable Library projects'.
Strange - as I thought this would be a scenario that would be supported. I found a post here which suggested a fix that forced Visual Studio to detec the Monotouch (Xamarin) framework as supporting Portable Library Projects. Seemed to be exactly what I needed - but no. When I added the reference again, I was greeted by a different error:
'The current project's target framework is not compatible with that of the Portable Library project'.
And it suggests I change the target framework in the project properties. Except I can't, as the Xamarin iOS project needs to support Monotouch (and I can't change it to anything else from the GUI anyway). So I tried to change the model library's properties instead - maybe I can do something there. And it looked like I could. I can check Monotouch (Xamarin) as a supported platform here (where Windows phone, Windows store, etc are already checked), but it won't let me save. It just shows the message:
'There is no additional functionality that is supported by the target frameworks you have selected'
After some research, I discovered that the only way Xamarin suggest to share code is to use separate projects with linked code files (so in effect, a pseudo-single code base. Which I have tried and works - but it seems a hack. See here:
http://docs.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options
So is this the only option? Or is there any way to have a true single class (model) library across all platforms, including Microsoft and Xamarin?
It is currently possible to use Portable Library Projects - e.g. profile 104 - across all of .Net4.5, WP, WinRT, Xamarin.Android and Xamarin.iOS
It is also currently possible to use the output binary assemblies across .Net4.5, WP, WinRT and Xamarin.Android - but not current against Xamarin.iOS.
This situation is changing 'very soon' now with Xamarin adopting full PCL support - see http://slodge.blogspot.co.uk/2013/02/the-future-is-portable.html and listen to http://hanselminutes.com/362/ios-and-android-apps-with-xamarin-studio-20-and-miguel-de-icaza
I personally deliver MvvmCross (and a lot of apps that use MvvmCross) using PCLs - and have done for the last 6 months - but there is some setup pain involved in this currently. For some info see my blog:
http://slodge.blogspot.co.uk/2012/12/cross-platform-winrt-monodroid.html
http://slodge.blogspot.co.uk/2013/03/xamarinios-with-mvvmcross-in-vs2012.html
I do hope to provide an update on this in the very near future - it should work 'out of the box' soon.
The future is bright on Xamarin side, as it is going to support .NET 4.5 profile on all its platforms,
http://blog.xamarin.com/brave-new-async-mobile-world/
The only problem as far as I can see comes from Microsoft side, who refuses to unify its own platforms to a common profile (Windows 8 and Windows Phone 8 are still messy tailored versions no better than CF or Silverlight in my own situation).
Portable class libraries are out there, but as a library author (#SNMP) I rather build separate project files for my own projects as Xamarin suggests.
How to cope with the Microsoft Phone specific assemblies when loading the classes inside a MonoGame For Android project (MonoGame FrameWork)? As e.g:
using Microsoft.Phone.BackgroundAudio;
using Microsoft.Phone.Marketplace;
using Microsoft.Phone.Tasks;
using System.Device.Location;
These will have to #if defed out as they are not currently supported under MonoGame.
Background audio should be supported via the Song and Sound classes though.
I think the MarketPlace namespace is an interesting one, and is one that should not be phone specific, as MacOS also has an App Store.
I hope this helps.