Android Question How to copy .so file to /data/data/<package>/lib/ folder as part of apk installation?

daemon

Active Member
Licensed User
Longtime User
I'm trying to use a 3rd party library, which uses .so file and loads it using:
System.load("/data/data/" + context.getPackageName() + "/lib/" + library);

How to copy .so file to /data/data/<package>/lib/ folder as part of apk installation?

Since this is 3rd party library, I do not have control to change code for .so location.
 

Informatix

Expert
Licensed User
Longtime User
I'm trying to use a 3rd party library, which uses .so file and loads it using:
System.load("/data/data/" + context.getPackageName() + "/lib/" + library);

How to copy .so file to /data/data/<package>/lib/ folder as part of apk installation?

Since this is 3rd party library, I do not have control to change code for .so location.
Replace this by System.loadLibrary("library name"). With no path.
 
Upvote 0

daemon

Active Member
Licensed User
Longtime User
Replace this by System.loadLibrary("library name"). With no path.
I have no control over that code.

I have got a set of .jar file and .so file from 3rd party.
The .jar file loads .so file using above line - I do not have setup to rebuild .jar file.
I'm developing a wrapper library for B4A, which I'm building using Simple Library Compiler - editing project using Eclipse and compiling using SLC.
I'm able to include / use .jar file in B4A application (through B4A wrapper library) but it complains that it cannot load .so file.

I need to include .so file in B4A library such that when I compile B4A application using that library, .so file should be located at expected location.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
From what I remember from an attempt of mine, I got the answer from Erel here and it worked.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I have no control over that code.

I have got a set of .jar file and .so file from 3rd party.
The .jar file loads .so file using above line - I do not have setup to rebuild .jar file.
I'm developing a wrapper library for B4A, which I'm building using Simple Library Compiler - editing project using Eclipse and compiling using SLC.
I'm able to include / use .jar file in B4A application (through B4A wrapper library) but it complains that it cannot load .so file.

I need to include .so file in B4A library such that when I compile B4A application using that library, .so file should be located at expected location.
The problem is that the path for the lib is wrong with some Android versions. It's a stupid idea from the original author since you don't need to specify this path with the appropriate function. As a general rule of thumb, using fixed paths in Android is always a very bad idea.
I don't see for now how you can fix this.
EDIT: I checked the path on the devices that I have with me this morning and I confirm that on my phone the right path to .so files is /data/app-lib/.... On an device with an older version of Android, it's /data/data...
 
Last edited:
Upvote 0

daemon

Active Member
Licensed User
Longtime User
I checked the path on the devices that I have with me this morning and I confirm that on my phone the right path to .so files is /data/app-lib/.... On an device with an older version of Android, it's /data/data...

Actually, /data/data/package/lib is linked to /data/app-lib/package-N folder.

However, following the method I used, I could not locate .so file anywhere in the file system.
@Informatix, do you know any such B4A library that includes and uses .so file internally?

To check, I unzipped generated apk file too.
Then, I copied .so file to lib/armeabi/ folder, rebuilt the apk file and signed it again -> That method worked and I found .so file at correct location.

I wonder what is the correct way to include .so file in B4A generated apk.
 
Upvote 0

daemon

Active Member
Licensed User
Longtime User
@mc73, @Erel, my B4A library .jar has .so file correctly under lib/armeabi folder.

libso.png
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
@Informatix, do you know any such B4A library that includes and uses .so file internally?
LibGdx and OpenSL, among my libraries, use .so files. But they do not call an external JAR; they load directly the .SO. Thus, I just had to place the .SO in the "lib" folder of my Eclipse project.
Did you try to include yourself the folder of the SO file in one of your JAR files (this way, it will be included automatically in your APK)?
 
Upvote 0

daemon

Active Member
Licensed User
Longtime User
Oh. Yesterday was just a bad day. Today rebooted my machine, cleaned up all projects and built everything again.... and it works!

Sorry for trouble, guys and appreciate your help. Thank you.
 
Upvote 0
Top