Page 1 of 1

How to use 3rd party library on android?

Posted: Sat Jun 08, 2019 10:04 am
by Ruben776
I have hard time fnding out how to load and use compiled .so library in firemonkey application. I've managed to setup project in a way that it compiles and library is bundled in apk but can't load it when application starts. Is system.LoadLibrary() enough or do I need some java wrapper for the lib?

edit: my code looks like this now, still can't get past library loading stage. TPath.GetLibraryPath returns correct path to where library is located ( I checked with adb pull)

Code: Select all

{$IFDEF MSWINDOWS}
    LIBNAME = 'sunvox.dll';
{$ENDIF}
{$IFDEF ANDROID}
    LIBNAME = 'libsunvox.so';
{$ENDIF}

function sv_load_dll:integer;
var libPath:system.string;
begin
  g_sv_dll:= 0 ;
  libPath:=TPath.Combine(tpath.GetLibraryPath,libname);
  {$IFDEF ANDROID}
  g_sv_dll:=dlopen(MarshaledAString(libPath), RTLD_LAZY);
  {$ENDIF}
  {$IFDEF MSWINDOWS}
  g_sv_dll := LoadLibrary(MarshaledString(libPath));
  {$ENDIF}
  result:=g_sv_dll;
  if( g_sv_dll = 0 )then exit;

  sv_audio_callback:=tsv_audio_callback(import('sv_audio_callback' ));
 ...
end;

Re: How to use 3rd party library on android?

Posted: Sat Jun 08, 2019 8:10 pm
by NightRadio
So what exactly is the problem? Some errors?
Please check the android/sample_project/SunVox Player sources.
It the library is loaded by system.LoadLibrary(), then you need to call init(), open_slot(), etc.