Java Question Making B4A library with existing Java library.

mleffler

Member
Licensed User
Longtime User
A few months ago I was working on a USB library for FTDI based hardware. I am thinking about getting back to it finally. But first a few questions.

I have the .jar file for an existing Java library that works in Android. I assumed in order to convert it that I needed to add that .jar file to my Eclipse project then create new methods in a new Java file to call the methods in that original .jar file.

I was however looking at WarWounds YouTubePlayer and if I understand it he wrapped the original .jar file with a class in a new Java file. Then used an Intent to call it.

So based on this I wonder which of these methods is correct? Or is it like real life and it depends on many factors?

Erel: I like your tutorials on this subject but I cant seem to find one that mentions what to do when you already have the .jar file and just want to make it work in B4A.
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
In your eclipse IDE, you should add your original libraries the exact same way like you would add android.jar and b4ashared.jar.
Just go to your build path - add external jars and add your jar to the project.

This will make your methods and instances available for your project.

Next you'd need to add the DependsOn annotiation. You can do a search for that. You'll have to put your lib (the one you added) to your additional library folder. If you don't do that, you'll retrieve a nosuchmethodfound or something error.
The DependsOn annotiation will add the required library to your B4A library without having to check for it. (it's a replacement for the dummy xml file you had to make.)

Tomas
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that wrapping the FTDI library will be more complicated as it depends on native library (.so files). These file get loaded by calling System.loadLibrary. You will need to manually load these files in your wrapper.

As I wrote in another post, bot Agraham and myself tested the FTDI wrapper and it didn't work with the devices that we used.
 

mleffler

Member
Licensed User
Longtime User
Thanks, I have a couple other libraries that work for FTDI that I will be trying. I did try the FTDI one and I could not even get their test programs to work on my tablet so I am not even going to bother with them.

I'll check that the libraries I'm going to use have .so files. I dont think so I believe FTDI is the only library I have where they did that.
 

mleffler

Member
Licensed User
Longtime User
Started to create library need help.

I started on the FTDI library. I can create a .jar file and .xml that B4A accepts. The issue is when I compile a program I get a message about a symbol missing.

I attached a screen shot from Eclipse showing the start of this library.
Can anybody see what I'm doing wrong or if I am even close to doing this correctly?

FTDriver.jar is for the original library.

I thought a screenshot would be most useful. Let me know if you would like to see the code directly.

thanks,
 

Attachments

  • FTDILib.jpg
    FTDILib.jpg
    92.5 KB · Views: 474

XverhelstX

Well-Known Member
Licensed User
Longtime User
you should add a package name.
On top of your project add:

B4X:
package com.myorganisation.ftdi;

that "com.myorganisation.ftdi" can be anything else, but it needs to have some . in it.

mine is mostly

B4X:
package com.rootsoft.jarname;

Next a red underline will appear, and you should change the package declaration name to the new one. (not the default one.)

When you create a new class file, you should always specify your package name.

Tomas
 

mleffler

Member
Licensed User
Longtime User
Almost there but one more question.

I am converting a Class FTDriver which contains the following:

public FTDriver(UsbManager manager){ some code}

I'm sure that is a constructor but I have not been able to figure out how to wrap that . Anyone have any ideas?

I got the library converted and in B4A but when I run a program with it it just hangs. I guessing that I have converted the above code wrong. I did find out that the UsbManager in FTDriver is defined as android.hardware and the one inf B4A does not match so I cant seem to just pass them.


thanks,
 

Buks

Member
Licensed User
Longtime User
Note that wrapping the FTDI library will be more complicated as it depends on native library (.so files). These file get loaded by calling System.loadLibrary. You will need to manually load these files in your wrapper.

As I wrote in another post, bot Agraham and myself tested the FTDI wrapper and it didn't work with the devices that we used.

How would one go about to use an existing .jar file that is a wrapper for a .so file? It is clear how to include the .jar file, but what about the .so file that it requires?
 

hdtvirl

Active Member
Licensed User
Longtime User
Erel, I am having a go at writing a Wrapper Library for the Epson Point of Sales printer Driver.

You will need to copy the .so files to File.DirInternal (only if they do not already exist) and then call System.load to load these files.

Epson include a .jar file and a .so file I see form the above post you have to load the .so file from withing B4A can you give an example piece of code of how you would go about this.



I will post a copy of the Library if I get it working. I also need to check with Epson that their Library can be distributed as part of a wrapper library.

As I am only writing a wrapper Library and NOT modifying their original Library in anyway I don't see a problem. If I can get this working it will only increase their sales of ePOS printers into new B4A Android Applications !
But the way things are I would want that in writing from them.


Thanks in advance

Regards

BOB
 

hdtvirl

Active Member
Licensed User
Longtime User
Thank Erel for your response. I will give this a try this morning, I was getting errors back when trying to test the Library and this may sort it I hope.

Regards

BOB
 

lip

Active Member
Licensed User
Longtime User
Ftdi

I started on the FTDI library. I can create a .jar file and .xml that B4A accepts. The issue is when I compile a program I get a message about a symbol missing.

I attached a screen shot from Eclipse showing the start of this library.
Can anybody see what I'm doing wrong or if I am even close to doing this correctly?

FTDriver.jar is for the original library.

I thought a screenshot would be most useful. Let me know if you would like to see the code directly.

thanks,

Slightly on a tangent but I am intreagued by your FTDI library: I am developing an application in B4A on an Asus Transformer that talks to an RF transceiver. I started out using a transceiver with the FT232R chip plugged into the Asus USB port but could not find a way of communicating with it without rooting the Asus which would not be practical for users. I gave up and have now started using Bluetooth. A looked at the new FT311D chip in Accessory mode but it seems that you would still have to have a battery in the device that could not be powered by USB - so no better than bluetooth.

Did you find a way to talk directly to FT2xxx chips?
 

qsrtech

Active Member
Licensed User
Longtime User
Port ePOS Jar

Has anyone successfully ported the ePOS jar for b4A yet?
 
Top