Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XE7 android shared object - looking for ".so" template


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Nov 18, 2014 6:03 PM Last Post By: Kenneth McMillion
Kenneth McMillion

Posts: 14
Registered: 8/28/08
XE7 android shared object - looking for ".so" template  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 17, 2014 12:33 PM
Hi is there a .so template like this is for windows dll applications. I tried creating a blank fire monkey cross platform application and removing the form and building it with an exported function. I was doing some reading on creating a .so in eclipse and intellj and they have an option to set the isLIbrary flag - is there something like this in XE7 I tried changing the "program" to "library" but my test application still can't load the .so it can verify that it exist but just won't load it.

demolib
library demoLib;
 
uses
  System.StartUpCopy,
  androidapi.jni,
 
  FMX.Forms;
 
{$R *.res}
 
function MultiplyBy2(anum : integer) : integer; cdecl;
begin
   result := anum * 2;
end;
 
 
exports
  MultiplyBy2;
 
begin
 
end.

and code from my demo app to load it.


unit demolibTest;
 
interface
 
uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FMX.Controls.Presentation, FMX.Edit, FMX.StdCtrls,Posix.Dlfcn,
  System.IOUtils;
 
type
  TForm1 = class(TForm)
    btnNumber: TButton;
    edtNumber: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure btnNumberClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
  lib  : Thandle;
  so_path : string;
  MultiplyBy2 : function (anum : integer) : integer; cdecl;
 
 
 
implementation
 
{$R *.fmx}
{$R *.LgXhdpiPh.fmx ANDROID}
{$R *.Windows.fmx MSWINDOWS}
 
procedure TForm1.btnNumberClick(Sender: TObject);
var
  iMulti : integer;
begin
 
  if lib = 0 then
    exit;
 
 MultiplyBy2 := dlsym(lib,'MultiplyBy2');
 
 if not assigned(MultiplyBy2) then
    begin
      showmessage('dlsym MultiplyBy2 failed');
      exit;
    end;
 
  iMulti := MultiplyBy2(strtointdef(edtNumber.Text,0));
  showmessage(inttostr(iMulti));
end;
 
procedure TForm1.FormCreate(Sender: TObject);
var
  Marshaller : TMarshaller;
begin
 
 
  so_path := TPath.GetSharedDocumentsPath + PathDelim + 'libdemolib.so';
 
 
  if TFile.Exists(so_path) then
    showmessage('found: '+so_path)
    else
    showmessage('not found: '+so_path);
 
  lib := dlOpen(marshaller.AsAnsi(so_path).ToPointer,RTLD_LAZY);
 
  if lib = 0  then
    showmessage('not loaded: '+so_path)
    else
    showmessage('loaded: '+so_path);
end;
 
initialization
 // lib := THandle(dlOpen(demoLib,RTLD_LAZY));
finalization
  dlClose(lib);
end.
 


TIA
Eli M

Posts: 1,346
Registered: 11/9/13
Re: XE7 android shared object - looking for ".so" template  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 17, 2014 6:44 PM   in response to: Kenneth McMillion in response to: Kenneth McMillion
http://www.fmxexpress.com/bare-bones-android-app-with-ndk-shared-object-built-in-delphi-xe7-without-firemonkey/

program tester;
Uses
 SysUtils,
 Jni;
 
const
 NDKLibLog        = 'liblog.so'; // NDK Log
 ANDROID_LOG_INFO = 4;
 cFuncPrefix      = 'Java_com_kredix_Tester_';
 
Var
 curVM  : PJavaVM = nil;
 inx    : Integer = 0;
function __android_log_write(prio:longint;tag,text: MarshaledAString):longint; cdecl; external NDKLibLog;
procedure dbg( msg : MarshaledAString );
 begin
  __android_log_write(ANDROID_LOG_INFO,'JNI_Pascal', msg );
 end;
 
//
Function calc( value : integer ) : integer; cdecl;
 begin
  result := value + 1;
 end;
 
// java call pascal -----------------------------------------------------------
Function  pTest (env: PJNIEnv; this: jobject; value : integer): integer; cdecl;
 begin
  Dbg( MarshaledAString( 'pTest >> In:' +IntToStr(Value) + 'Out:' + IntToStr(Value+100)));
  Result := Value + Inx;
  Inc(Inx);
 end;
exports
 JNI_OnLoad    name 'JNI_OnLoad',
 JNI_OnUnload  name 'JNI_OnUnload',
 calc          name 'calc',
 pTest         name cFuncPrefix+'pTest';
begin
end.
Kenneth McMillion

Posts: 14
Registered: 8/28/08
Re: XE7 android shared object - looking for ".so" template  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 18, 2014 6:03 PM   in response to: Eli M in response to: Eli M
Thank you Eli - I have seen this one but I couldn't find the *.bat file that is referenced so it builds the windows platform and it references jni instead of androidapi.jni but I will look further into it

Eli M wrote:
http://www.fmxexpress.com/bare-bones-android-app-with-ndk-shared-object-built-in-delphi-xe7-without-firemonkey/

program tester;
Uses
 SysUtils,
 Jni;
 
const
 NDKLibLog        = 'liblog.so'; // NDK Log
 ANDROID_LOG_INFO = 4;
 cFuncPrefix      = 'Java_com_kredix_Tester_';
 
Var
 curVM  : PJavaVM = nil;
 inx    : Integer = 0;
function __android_log_write(prio:longint;tag,text: MarshaledAString):longint; cdecl; external NDKLibLog;
procedure dbg( msg : MarshaledAString );
 begin
  __android_log_write(ANDROID_LOG_INFO,'JNI_Pascal', msg );
 end;
 
//
Function calc( value : integer ) : integer; cdecl;
 begin
  result := value + 1;
 end;
 
// java call pascal -----------------------------------------------------------
Function  pTest (env: PJNIEnv; this: jobject; value : integer): integer; cdecl;
 begin
  Dbg( MarshaledAString( 'pTest >> In:' +IntToStr(Value) + 'Out:' + IntToStr(Value+100)));
  Result := Value + Inx;
  Inc(Inx);
 end;
exports
 JNI_OnLoad    name 'JNI_OnLoad',
 JNI_OnUnload  name 'JNI_OnUnload',
 calc          name 'calc',
 pTest         name cFuncPrefix+'pTest';
begin
end.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02