[WISH] Compiler support for .so library files

warwound

Expert
Licensed User
Longtime User
Hi.

I'm creating a B4A library that uses a native .so filetype library.
There are two versions of the native library, in the Eclipse project libs folder they are stored as:

libs / armeabi / liblame.so

libs / armeabi-v7a / liblame.so

I can compile the B4A library so that the libs folder is included in the exported jar, and when i compile my B4A project and open the compiled .apk file i see my libs folder and both versions of the .so library files.

So i need to manually copy the correct version of the .so library file to the project's installed location.

I hoped to do this in the library, in the library class constructor but cannot find out:

1) How to access the APK libs folder?
2) How to detect if armeabi or armeabi-v7a version should be copied?

A solution would be to remove the .so files from the B4A library .jar and add them to the project's Files folder i though BUT we have no support for sub-folders in the Files folder and obviously cannot have 2 .so files with the same filename in the Files folder.
And it's a requirement of .so library files to be named according to the library name - i can't rename one of the .so files.

Once i have a solution for this i still need to be able to establish whether a device supports the armeabi-v7a version of the library or not.

Ideally the B4A compiler would do all of this automatically but that's not currently supported.

So i'll add this as a new feature request and also ask if anyone has any workarounds or other solutions to enable me to copy the correct .so library version to the installed app's internal lib folder?

Thanks.

Martin.
 

socialnetis

Active Member
Licensed User
Longtime User
How do you import this .so files into your eclipse folder? (the link provided does no longer exists)
 

warwound

Expert
Licensed User
Longtime User
How do you import this .so files into your eclipse folder? (the link provided does no longer exists)

Drag n drop them from a Windows Explorer window onto the 'lib' folder in your Eclipse project.
Eclipse will prompt you to copy the files or link to them - choose copy.

Martin.
 

socialnetis

Active Member
Licensed User
Longtime User
I have "src", "JRE System Library", "Referenced Libraries" and "doc" folders, do I have to manually create a "lib" flolder? or just copy them to src folder?
 

warwound

Expert
Licensed User
Longtime User
I have "src", "JRE System Library", "Referenced Libraries" and "doc" folders, do I have to manually create a "lib" flolder? or just copy them to src folder?

If there is no lib folder then you have to create it.
(Right click project name New > Folder).

You'll then have:

src
JRE System Library
Referenced Libraries
lib

Martin.
 

socialnetis

Active Member
Licensed User
Longtime User
Thanks for answering, but I can't get it to work.
I have this little Java class:

B4X:
public class imageproc {

   public Bitmap CartonFilter (Bitmap inputFrame){
      System.loadLibrary("opencv_core");
      Mat src = new Mat();
      return null;
   }
}

I now have a lib/armeabi and lib/armeabi-v7a folders with this file: libopencv_core.so

I can compile it to .jar. But when I want to use in my b4a project, y get a "java.lang.UnsatisfiedLinkError: Couldn't load opencv_core: findLibrary returned null"

In the APK I can see that the lib folder containing the .so files exists. What Am I doing wrong?
 

socialnetis

Active Member
Licensed User
Longtime User
The problem was that I had to load an other library (opencv_java, not opencv_core). Now I'm having other problems with some functions of the library that are really out my league and knowledge about image processing, so I guess I'm done trying to use this opencv library..

Thanks for the help!
 

aignatd

Member
Licensed User
Longtime User
I want load .so file on my eclipse project to create basic4android library.
do you have a working eclipse project ?
 

warwound

Expert
Licensed User
Longtime User
Here's the Lame library eclipse project.

The thing to remember is that when you compile and create a .jar file in eclipse you have to be sure that the projetc's lib folder is included.

If i right click the src folder and export a .jar file that doesn't happen.
When i export a .jar file i also have to check the box in the folder tree for lib.
(See screengrab).

I think if you right click the project title and export it'll include the lib folder, but i find too often that includes junk in the .jar file such as any javadoc that's in the doc folder.

Martin.
 

Attachments

  • Screenshot - 140514 - 11:48:38.png
    Screenshot - 140514 - 11:48:38.png
    73.3 KB · Views: 683
  • Lame_b4a_eclipse_project_20140514.zip
    295.7 KB · Views: 653

Krammig

Member
Licensed User
Longtime User
Hello Martin,

Just reading through the threads, thank you for uploading the Lame sample.

I have an .so from a device manufacturer and have used that successfully in an Eclipse based project. I now want to create the same project using B4A so I can more readily maintain the project. a couple of questions if you don't mind as I would appreciate a bit of guidance on this.

a)
I gather I simply cannot reference the .so directly from with the B4A app, correct ?

b)
so I need to create a .jar, correct ?

c)
so does the .jar act a a wrapper and interface between the .so and the B4A app, and thus I need to import the .jar into my B4A app ?

d)
will your sample app above be enough for me to more or less clone and using my .so and replacing the appropriate Function calls I should them be able to get the .so working in a B4A app ?

thanks
Harry
 

warwound

Expert
Licensed User
Longtime User
First your .so library needs to be wrapped in a java class (let's call it SOWrapper class) so that java can access the native .so library methods.

In a java/android/eclipse project this is all that needs to be done in order to use the .so library.
If you've already used the .so library in a java eclipse project then you most likely already have this class (SOWrapper).
Your java calls SOWrapper methods, SOWrapper calls .so library methods.

To use the .so library in b4a you need an additional wrapper class - you need to wrap the SOWrapper class (let's call this SOWrapperWrapper class).

b4a can only call methods of the SOWrapperWrapper class.
So any methods you need to use in b4a need to be methods of the SOWrapperWrapper class.

b4a calls SOWrapperWrapper methods, SOWrapperWrapper calls SOWrapper methods and SOWrapper calls native methods of the .so library.

Your b4a library eclipse project will therefore consist of a minimum of:
  • .so library file(not visible to b4a).
  • Java class that wraps the .so library file(not visible to b4a).
  • Java class that wraps the class that wraps the .so library file(visible to b4a).

Is your project confidential - are you covered by an NDA?
If not then i can help set up a basic eclipse project with everything in the right place and that'd just leave you to write the wrapper class.

Martin.
 

Krammig

Member
Licensed User
Longtime User
Martin thanks for the detail, I see it much more clearly now.

Your offer is much appreciated and I certainly would like to take you up on it. I have signed an NDA for the .so however it does allow for me to interface with 3rd parties as long as I can be assured they will respect the nature of the NDA, which I am sure you will.

What would you like me to send you, just the .so ? or more than that ? (would need to send it external to this forum though)

regards
Harry
 
Top