Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: How to add shared objects (*.so) to an Android-Delphi-Project?


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


Permlink Replies: 6 - Last Post: Dec 16, 2014 11:04 PM Last Post By: Eli M
Stefan Schalk

Posts: 5
Registered: 11/9/06
How to add shared objects (*.so) to an Android-Delphi-Project?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 9:21 AM
I have to dynamically call shared objects (*.so files) in my Android project. (RAD Studio Delphi)
I use "dlopen" to open the shared object, but every attempt fails with "file not found".
I tried to add the shared objects to the deployment, but they are just treated as normal files.

How should I add the shared objects to my Delphi project to get them at the correct destination on Android?

Edited by: Stefan Schalk on Dec 11, 2014 9:23 AM
Eli M

Posts: 1,346
Registered: 11/9/13
Re: How to add shared objects (*.so) to an Android-Delphi-Project?
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 6:00 PM   in response to: Stefan Schalk in response to: Stefan Schalk
What worked for us was to deploy them to assets\internal which you can access with TPath.GetDocumentsPath. Also check out LoadLibrary() it is a wrapper around dlopen. Also if your SO file is dependent on other SO files you have to load them first. So load them in their dependency order.

http://blogs.embarcadero.com/davidi/2013/11/23/43005
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to add shared objects (*.so) to an Android-Delphi-Project?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 11, 2014 6:18 PM   in response to: Eli M in response to: Eli M
Eli wrote:

What worked for us was to deploy them to assets\internal which you
can access with TPath.GetDocumentsPath.

Whihc is documented on Embarcadero's DocWiki site:

http://docwiki.embarcadero.com/RADStudio/XE7/en/Creating_an_Android_App#Loading_and_Deploying_Files

--
Remy Lebeau (TeamB)
Stefan Schalk

Posts: 5
Registered: 11/9/06
Re: How to add shared objects (*.so) to an Android-Delphi-Project?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2014 2:52 AM   in response to: Eli M in response to: Eli M
Ok, that's working too with my shared objects - thank you for the hint!

But there should be an official way to include shared objects to an Android project under Delphi. To load them into the document folder can't be the right way, or? Using the NDK without Delphi let me specify the shared objects and they are installed somewhere in the Android and can be loaded just with the name of the shared object - without prepending a path.

I'm of the mind that Embarcadero should support the correct way to include shared objects to the Delphi project.
Am I right?

Embarcadero, please tell us the right way!
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: How to add shared objects (*.so) to an Android-Delphi-Project?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2014 5:27 AM   in response to: Stefan Schalk in response to: Stefan Schalk
Am 12.12.2014 11:52, schrieb Stefan Schalk:
Ok, that's working too with my shared objects - thank you for the hint!

But there should be an official way to include shared objects to an Android project under Delphi. To load them into the document folder can't be the right way, or? Using the NDK without Delphi let me specify the shared objects and they are installed somewhere in the Android and can be loaded just with the name of the shared object - without prepending a path.

I'm of the mind that Embarcadero should support the correct way to include shared objects to the Delphi project.
Am I right?

Embarcadero, please tell us the right way!

Hello,

as for Android .jar files can be added via project manager since XE7
now. Not sure about .so.

Greetings

Markus
Stefan Schalk

Posts: 5
Registered: 11/9/06
Re: How to add shared objects (*.so) to an Android-Delphi-Project?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 15, 2014 1:26 AM   in response to: Stefan Schalk in response to: Stefan Schalk
I found another (better?) way to get the shared objects deployed:
(TPath.GetLibraryPath instead of TPath.GetDocumentPath)

Just add them to the provisioning. They are listed as type "File".
Now change the remote path to the path of your application shared object (type "ProjectOutput").
My remote path was "library\lib\armeabi-v7a\".
The shared objects still wouldn't be found automatically just by name,
but we can access them using TPath.GetLibraryPath.

soHandle := LoadLibrary(PCHAR(TPath.Combine(TPath.GetLibraryPath, <Shared Object Name>)));

Don't forget to load all the dependent shared objects before.
Afterwards release the shared objects in reverse order with FreeLibrary.
Eli M

Posts: 1,346
Registered: 11/9/13
Re: How to add shared objects (*.so) to an Android-Delphi-Project?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2014 11:04 PM   in response to: Stefan Schalk in response to: Stefan Schalk
Awesome that you were able to get that working. Not sure where we were going wrong with that way. Maybe the dependency thing was biting us. Theoretically it should also be possible to do it with the JNI using System.LoadLibrary().

https://stackoverflow.com/questions/10184579/android-jni-calling-system-loadlibrary-causes-segv
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02