Problem loading .SO library

arielexchilearielexchile Member
edited December 2018 in Xamarin.Android

Hi Guys,

I am having problems to use a JAVA .SO library with my APP.

This library is for manage a led light in a Tablet that is used for meeting room.

This is the file content that the seller sent me to use the library

package com.example.elcapi;

public class jnielc
{

    public final static native int open();
    public final static native int ledred(int fd);
    public final static native int ledblue(int fd);
    public final static native int ledgreen(int fd);
    public final static native int ledmix(int fd);
    public final static native int ledoff(int fd);
    public final static native int seekstart();
    public final static native int seekstop();
    public final static native int ledseek(int flag, int progress);

    static {
        System.loadLibrary("jnielc");
    }
}

This is the way I am doing with Visual Studio Community 2017 and Android XAMARIN Forms

using Java.Lang;
using System;
using System.Runtime.InteropServices;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace SalaReunion
{
    [XamlCompilation(XamlCompilationOptions.Compile)]

    public partial class Agenda : ContentPage
    {


        [DllImport("libjnielc.so", EntryPoint = "ledseek", ExactSpelling = true)]
        public static extern int ledseek(int flag, int progress);

        [DllImport("libjnielc.so", EntryPoint = "ledred", ExactSpelling = true)]
        public static extern int ledred(int fd);

        [DllImport("libjnielc.so", EntryPoint = "seekstart", ExactSpelling = true)]
        public static extern int seekstart();

        [DllImport("libjnielc.so", EntryPoint = "seekstop", ExactSpelling = true)]
        public static extern int seekstop();


        public static int seek_red = 0xa1;

        public Agenda()
        {

            try
            {
                string mensaje = fnLibreria();

                int inicio = seekstart();
                int rojo = ledseek(flag: seek_red, progress: 50);
                int fin = seekstop();

            }
            catch (UnsatisfiedLinkError e)
            {
                Console.WriteLine(e.Message);
            }

            InitializeComponent();
        }

        public string fnLibreria()
        {
            try
            {
                JavaSystem.LoadLibrary("jnielc");

                return "bien";
            }
            catch (UnsatisfiedLinkError e)
            {
                return e.Message;
            }
        }
    }
}

When I run the application into the Tablet I got the following output:

12-25 22:54:40.190 D/Mono    ( 1883): DllImport attempting to load: 'libjnielc.so'.
12-25 22:54:40.192 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:40.192 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:40.193 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:40.193 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:40.193 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.193 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.194 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.194 W/Mono    ( 1883): DllImport unable to load library 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
Resolved pending breakpoint at 'Agenda.xaml.cs:55,1' to string SalaReunion.Agenda.fnLibreria () [0x00002].
Resolved pending breakpoint at 'Agenda.xaml.cs:34,1' to void SalaReunion.Agenda..ctor () [0x00008].
12-25 22:54:40.249 D/Mono    ( 1883): DllImport attempting to load: 'libjnielc.so'.
12-25 22:54:40.250 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:40.251 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:40.251 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:40.251 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:40.252 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.252 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.252 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.252 W/Mono    ( 1883): DllImport unable to load library 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.252 D/Mono    ( 1883): DllImport attempting to load: 'libjnielc.so'.
12-25 22:54:40.253 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:40.254 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:40.254 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:40.254 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:40.254 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.255 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.255 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.255 W/Mono    ( 1883): DllImport unable to load library 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:40.406 D/Mono    ( 1883): Assembly Ref addref SalaReunion.Android[0xb84cde88] -> System[0xb8748df8]: 5
12-25 22:54:56.576 D/Mono    ( 1883): DllImport attempting to load: 'libjnielc.so'.
12-25 22:54:56.584 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:56.587 D/Mono    ( 1883): DllImport error loading library '/storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//storage/emulated/0/Android/data/com.australti.salareunion/files/.__override__/libjnielc.so" not found'.
12-25 22:54:56.589 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:56.591 D/Mono    ( 1883): DllImport error loading library '/system/lib/libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm//system/lib/libjnielc.so" not found'.
12-25 22:54:56.592 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:56.593 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:56.595 D/Mono    ( 1883): DllImport error loading library 'libjnielc.so': 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
12-25 22:54:56.595 W/Mono    ( 1883): DllImport unable to load library 'dlopen failed: library "/data/app/com.australti.salareunion-1/lib/arm/libjnielc.so" not found'.
Unhandled Exception:

System.DllNotFoundException: libjnielc.so

I did add the folder "libs" then I add the folders arm64-v8a, armeabi, armeabi-v7a, x86 and x86_64 inside "libs" folder and I put the library "libjnielc.so" inside every subfolder.

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Since the so file is in the android project, so it couldn't be referenced by the forms project .
    Maybe you could try to use dependency service to call into platform-specific functionality from shared code.

  • jezhjezh Member, Xamarin Team Xamurai

    Have you resolved your problem?

  • arielexchilearielexchile Member

    Hi jexh,

    Thank you for your reply.

    I am still lost trying to fix the problem

Sign In or Register to comment.