How to use 3rd party library on android?

Multi-platform modular music creation studio
Post Reply
Ruben776
Posts: 1
Joined: Sat Jun 08, 2019 9:49 am

How to use 3rd party library on android?

Post 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;
User avatar
NightRadio
Site Admin
Posts: 3944
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

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

Post 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.
Post Reply