Click here to Skip to main content
11,797,355 members (70,893 online)
Click here to Skip to main content

Native libraries in MonoDroid library projects

, 13 Jul 2012 CPOL 8.3K 5
Rate this:
Please Sign up or sign in to vote.
Support for native libraries in MonoDroid.

Currently, MonoDroid (Mono for Android) doesn’t support native libraries (or any other Android resource type) in library projects (bug report). Fortunately, they support normal .NET assembly resources. This led me to write a workaround for this missing feature.

The Class

Here’s the class that implements the loader.

// Copyright 2012 Sebastian Krysmanski
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.IO;
using System.Reflection;
using Android.App;
using Android.Content;
using Android.OS;

namespace Android.Util {
  /// <summary>
  /// Dynamically loads a native library from the resources of an assembly.
  /// <para>Important:
  /// <list type="bullet">
  /// <item><description>
  ///   The native library must be marked with "Embedded Resource" (not "AndroidNativeLibrary")
  /// </description>

How to use

To use this class, you first need to create a directory structure for the native libraries, like this:

+- NativeLibs
   +- armeabi-v7a
   +- armeabi
   +- other ABIs you want to support

Now place the native libraries in the apropriate directories, for example:

+- NativeLibs
   +- armeabi-v7a
   |  +-
   +- armeabi

Then select “Embedded Resource” as Build Action in the file’s properties (Hotkey: F4).

Selecting "Embedded Resource" as "Build Action"

Now use one of the Load() methods to load the library. For example, if you have a type called MyType in the project’s default namespace (specified in the project settings), you can use this call to load a library called

MonoDroidLibraryLoader.Load("sqlite", typeof(MyType));

Note: If you renamed the directory “NativeLibs” from above, you can specify it as third parameter for Load().


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Sebastian Krysmanski
Software Developer University of Stuttgart
Germany Germany
I have studied Software Engineering and am currently working at the University of Stuttgart, Germany.

I have been programming for many years and have a background in C++, C#, Java, Python and web languages (HTML, CSS, JavaScript).

You may also be interested in...

Comments and Discussions

QuestionQuestion Pin
saeidfarahi8-Aug-14 16:45
membersaeidfarahi8-Aug-14 16:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 13 Jul 2012
Article Copyright 2012 by Sebastian Krysmanski
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid