Android Question Corrupted libUART.so file

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi, I'm facing a problem related to a device that is used in unattended mode and very often the users power it off just unplugging the power (!)
Since the device uses a Library (UART from Rui Cardoso) if the device is unplugged while writing or accessing to the serial port, at the next restart very often we get the error:

B4X:
java.lang.UnsatisfiedLinkError: dlopen failed: "/data/app/~~WarzAMVAOewFFKtPB2Sg-w==/my.package.project-FlZNlfcNG9JD37T7TosccA==/lib/arm/libUART.so" has bad ELF magic: 00000000
The idea is to load the LibUART.so file directly in the project and then at each APP restart, the app copy that file from the DirAssets to DireInternal.
From DirInternal then create the class, instantiate it, use methods and events.
The problem is how to do all that with B4A?
I've tried this way:
This load successfully:
Dim jo As JavaObject
jo.InitializeStatic("java.lang.System").RunMethod("load", Array(DestinationPath & "/" & FileName))

B4X:
SerialPort = jo.InitializeNewInstance("com.project.UART", Null) ' Do not works. Never get here. See the below error

'Never get here:
jo = SerialPort
jo.RunMethod("Initialize", Array(Me, eventName_, Path_, BaudRate_, Flags_, bigEndian_, prefix_))

The error:
java.lang.ClassNotFoundException: java$lang$UART
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:289)
    at anywheresoftware.b4j.object.JavaObject.InitializeNewInstance(JavaObject.java:84)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.objects.Timer$TickTack.run(Timer.java:105)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7941)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:569)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1015)

I've the JAR file. I've also included it with:
B4X:
#AdditionalJar: UART
I've also added the JAR file to the File Manager in the B4A IDE, but nohing seems to work.

So, how can I replace the .so file on the fly knowing that:
- The system is unattended
- It is Android V13
- The device is not rooted
- The automated procedure I've to perform an Install intent each time the device restart, seems not to solve the problem because with "just" the corrupted libUART.so file, the app install seems to be skipped and the app does not start.
How can it is possible to solve this puzzle?

Thank you for your help.
 

MicroDrie

Well-Known Member
Licensed User
Longtime User
Looking at "DestinationPath & "/" & FileName" I suspect you're better off using the xui.SetDataFolder("AppName") and xui.DefaultFolder route (with possible sub directories) as I fear you'll now run into all sorts of Android folder restrictions. Have you also thought about using the B4XPage_CloseRequest routine to close everything properly according to the rules?
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi, the DestinationPath point to DirInternal but the problem is not that.
The load is succesfull.
Actually the problem is not even Android and even less B4A: the problem is THE CUSTOMER !!!
The system is not not designed to be abruptly unplugged while it is working just like a light bulb...
So looking at the "effect", I'seend and also reproduced the behaviour, writing a program that continuously write/read back from the serial port and unplugging the power, after some attempt I can corrupt the LibUART.so.

At moment I've put on the field probably a temporary solution: a POWER OFF software button on the screen that allow a proper shutdown after stopping any routine/service/timer that deal with the serial port.

But this is a temporary solution.
The final solution is to design an additional electronic board as "add-on" on the top of the electronic board I've already designed and produced in hundreds of units that act like a smart UPS.
But before doing that, what I'm looking for before be forced to do that is a way to "resolve" via software this kind of problem.
IF I could put at work, each time the app start, a "fresh" copy of the LibUART.so then I could instantiate it and in my imagination use it instead the one referenced into the "Library" tool of B4A.
So this possible solution lead into a discussion I've seen on the forum and that deal with "making" a B4A library from .so file.
But honestly this is out of my knowledge and also in all of posts in the forum about this topic I'm get lost because do not seems there is a clear answer about that.
Or maybe I'm wrong because not understood it.

So, the bottom line is: it is possible to "recover" the LibUART.so file when it is broken, supposing the overall structure on top of it is done and working in B4A?
There is somebody that could help in it?
The library is the one that can be found on this Forum and is the great one from Rui Cardoso: https://www.b4x.com/android/forum/threads/gpio-and-uart.100811/#content

Thank you all in advance.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…