Forum General

Best practice for including libraries?

KevinNewmanKevinNewman USMember ✭✭


I'm new to Xamarin and Android development, and to Xamarin Studio, and have never used Visual Studio (I used to edit C# with Dreamweaver back in the day - don't laugh too hard!!).

I'm curious what the best way to include a third party library project into my project and source control is. Specifically, I'm using this SVG sample project, to integrate an SVGView for Android:

It looks like there are two main methods to include this into my solution/project. One is to include the entire project (SvgAndroid) in my solution by copying it, then linking it into my project in the "Edit References" screen under the Projects tab. Or to compile the library (in release mode) and include it as a .NET Assembly. For the SvgAndroid library project a reference needs to be added for svg-android-1.1.jar as well.

I ended up going with option two, because it seems like less overhead in source control. I copied the compiled release SvgAndroid.dll into an Assemblies folder inside my project hierarchy (though I don't have it visible inside Xamarin's Solution panel). And also copied svg-android-1.1.jar into a Jars folder, and set that the appropriate build action for that (AndroidJavaLibrary).

All of that is working, but I'm not sure if that is the best practice, or if I'm missing some functionality by doing it this way. Is it better to include the project to get better debugging for example? It was hard to figure out that SVG files loaded by this library have to have width and height attributes, because it was just failing silently without them (Illustrator CC doesn't save SVG with width/height) - would using a project have helped with better error messages?


Kevin N.


  • AndyFlisherAndyFlisher GBBeta, University ✭✭✭✭

    If I've interpreted correctly, and it's. Single paltfork project, it doesn't really matter. If you include the project as a reference it will get built, if you pre build the project and use the resulting dll as a reference it's the same.

    Main occasion I've found using the project appropriate is when you have a cross platform class library, it will build the project reference as needed for the platform you're currently building, ie a way of having a single reference that build for ios and Android, and others

  • KevinNewmanKevinNewman USMember ✭✭

    That's pretty much what I was thinking. To include a library project if it's yours, or a fork (and goes with your solution) or just include .dll files if it's someone else's project.


  • KevinNewmanKevinNewman USMember ✭✭

    I wrote a blog post about what I was trying to do (use SVG instead of bitmaps for image assets) if anyone is interested: SVGView for Xamarin.Android

  • SKallSKall USMember ✭✭✭✭

    Kevin, it really depends on how mature the library is. Debugging and possibly fixing bugs on the fly is the big benefit of adding it as a project.

  • MartinBauligMartinBaulig DEXamarin Team Xamurai

    Well, these are not the only two alternatives that you have and both are actually suboptimal.

    The first question you should ask yourself is whether you want to use a source or binary distribution of the library. Using a source distribution has the advantage that you can easily debug and fix bugs on the fly. The downside is that it may make it more difficult to build your project, especially if the library is big.

    How you should include it in your source control also depends on a variety of factors such as who's making changes, do you want to track new upstream versions, submit patches to the upstream, etc.

    When using a third-party library from github, it's usually better to create a fork and then either include it as submodule or require people to check it out next to your module (and you could use some scripts to do that). That keeps the source control of your own project small and also makes it a lot more easier to pull new upstream versions and/or submit patches.

    If you want to use a binary distribution, then I would recommend to create a NuGet Package if possible. Many popular third party libraries already have NuGet Packages and it's also not too difficult to create your own.

    Using packages makes it a lot easier to get newer versions and you don't need to manually copy .dll files around, which can be a very annoying and tedious task especially if your library contains multiple .dll files.

  • KevinNewmanKevinNewman USMember ✭✭

    Thanks for the suggestions.

    As far as the git example, that's usually close to what I do (though what you say about forking makes sense, so I'll probably start doing that). The problem with this particular SVGAndroid example is it's buried in a huge repo dump (monodroid-samples). There is no single repo I could find which contains just the one project I'm using (

    As far as NuGet - can that be used with Xamarin Studio on a Mac? I was actually looking to get MVVMCross set up, but it looks like a bunch of work without NuGet.

  • MartinBauligMartinBaulig DEXamarin Team Xamurai

    Sure, there's an Add-In for Xamarin Studio:

Sign In or Register to comment.