Android Tutorial Accessing third party Jar with #Additionaljar and JavaObject - Picasso

aviario

Active Member
Licensed User
Longtime User
Hello.

We try to print in bluetooth printer using the java library of vendor.
We have the library an a sample in Java. We use #additionaljar and javaobject to develop an sample, but we have a lot of errors.
Can you help us? Here we attached then sample in Java and our sample in b4a

Thanks.
 

Attachments

  • LinePrinterSample_Java.zip
    261.9 KB · Views: 541
  • SampleB4A_1.zip
    355.5 KB · Views: 531
  • SampleB4A_2.zip
    187.1 KB · Views: 490

hzytsoft

Member
Licensed User
Longtime User
hi @Erel
i use a LaserApi jar
i upload this jar and mytrycodezip
can u fix a simple demo code tell us how to use it
just like open
open ();close ()

and i post this jar doc:
import com.zz.function.LaserApi.LaserManager.java



public class LaserManager {

final static String RECEIVERACTION ;


final static String RECEIVERDATA;

open ();

close ();

SoftScan();

init();

getLaserMode();

setLaserMode();

closeLaster();

SetParam(byte[] buf, int num);

GetParam(byte[] buf, int num);

RequestRevision();

enScanSound();

disScanSound();

////////////////////////
////////////use way
/////////////////////////



1.use jar need:

<uses-permission android:name="com.zz.SystemService" />

2.first

LaserManager laserManager= new LaserManager(context);

3.

IntentFilter mIntentFilter = new IntentFilter();

mIntentFilter.addAction(LaserManager.RECEIVERACTION);

String scandata= intent.getStringExtra(LaserManager.RECEIVERDATA);

tks @Erel and ba4
 

Attachments

  • mytry.zip
    7.3 KB · Views: 491
  • A1_Function_Api_v2.4.jar
    52 KB · Views: 486

EvgenyB4A

Active Member
Licensed User
Longtime User
Hi
I try to use the 3rd party libray from the device manufacture. This is the serial port library.
I added the attribute:

#AdditionalJar
: dwin-serialportapi-v1.1

Sub btnOpenCom_Click
Dim UART As JavaObject
Dim fd As JavaObject
Dim port As Int = 1
UART.InitializeNewInstance("com.dwin.navy.serialportapi.SerialPortOpt", Null)

End Sub

I put breakpoint on "End Sub" and after pressing OpenCom button the program doesn't stop on breakpont as if stucked.
If I press any other button I get the error:

An error occurred:


(Line: 204) End Sub
java.lang.NullPointerException

Please let me know what is wrong.
 

Attachments

  • dwin-serialportapi-v1.1.jar
    3.4 KB · Views: 468

EvgenyB4A

Active Member
Licensed User
Longtime User
Run it in Release mode and check the error logs.
Thank very much for fast reply. I try in Release mode. After pressing the "OpenCom button I get message box" Unfortunately My program has stopped" and errors log as follows:
** Activity (main) Create, isFirst = true **

** Activity (main) Resume **

java.lang.ExceptionInInitializerError

at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:217)
at java.lang.Class.forName(Class.java:172)
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:251)
at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:61)
at b4a.myfirstprogram.main._btnopencom_click(main.java:379)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:163)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:159)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:77)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)

at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load serialport: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.dwin.navy.serialportapi.SerialPortJNI.<clinit>(SerialPortJNI.java:11)
... 23 more
 

EvgenyB4A

Active Member
Licensed User
Longtime User
Seems like your library is missing the native so file.
I have opened on my PC an APK from vendor and found this attached libserialport.so file in \libs\mips folder.
Where should I put this file?
 

Attachments

  • libserialport.zip
    4.8 KB · Views: 423

EvgenyB4A

Active Member
Licensed User
Longtime User
You need the arm file not mips.
The name of the folder is so important? In my mips folder the .so file is single.
By the way, the CPU of my Android device is MIPS and not ARM.
Another note- here: https://www.b4x.com/android/forum/threads/wish-compiler-support-for-so-library-files.21726/ in post #16 you noted: "The jar file should include a folder named lib. The so file should be inside this folder."
Can I ask my vendor to recompile his source so, that jar file will include a folder named lib?
Will it help?
 

EvgenyB4A

Active Member
Licensed User
Longtime User
In that case then you have the correct file. Which device are you using?

You can build the jar file yourself. It is a regular zip file. Use 7zip tool.

Try to change libs to lib.
How should I organize the adding of .so file?
should it look like: lib\mips\libserialport.so ?
 

shashkiranr

Active Member
Licensed User
Longtime User
Hi All,

I need to use Picasso to download images and just retrieve the bitmap. I dont want to put the imageview. How can this be done?

Regards,
SK
 

LucaMs

Expert
Licensed User
Longtime User
The first step is to download the third party jar and put it in the additional libraries folder.

Only a stupid question: can I change the name of a jar library?
I suppose yes.

The purpose is to distinguish the B4A libraries from those third-party Java.

(the question is stupid ALSO because I could just try it )
 

DonManfred

Expert
Licensed User
Longtime User
Only a stupid question: can I change the name of a jar library?
if you are talking about the filename of the jar. Yes, this should be possible. Changing the filename does not change the classes inside the jar.
You just need to adapt you @dependson directive (java wrapper) or #additionaljar (b4a) to include the right file
 

joilts

Member
Licensed User
Longtime User
Got an error message when compiling a project:

B4A version: 5.02 (1)
Parsing code. Error
Error parsing program.
Error description: Attribute not supported: additionaljar
Occurred on line: 80
#AdditionalJar: opencv

The problem is that the code is the same one that works at another project, just made a copy and paste. It is the same B4A, with same configuration paths.
The main difference (I think) is that the code that works is all in the Main, and I copied to a Activity Module at the error project. Can it be the motive?
Thanks for your time.

UPDATE: Copied the code to Main and it worked? Is it expected?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…