How to use 3rd party library on android?
Posted: Sat Jun 08, 2019 10:04 am
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)
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;