Android Question JavaObject And java.lang.UnsatisfiedLinkError

MarcoRome

Expert
Licensed User
Longtime User
Hi all. I have this code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: Test AAR
    #VersionCode: 1
    #VersionName: 1.00
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalJar:  irlib-release.aar

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim jo As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    'Inizializzo oggetto JavaObject
    If FirstTime Then jo.InitializeContext

 '  jo.InitializeNewInstance("com.rft.irlib.IrHandler", Null)
'    'jo.InitializeStatic("com.rft.irlib.IrHandler")

    'PowerStart
    Dim batteria, memtot, memused, nfile As Int
    Dim sn, version As String
    Dim temperature As Float
 
    batteria = Cooffee.RunMethod("GetBattery", Null)
     Log("Batteria: " & batteria)
    memtot = Cooffee.RunMethod("GetMemTot", Null)
    Log("MemTot: " & memtot)

    memused = Cooffee.RunMethod("GetMemUsed", Null)
    Log("MemUsed: " & memused)
 
    nfile =  Cooffee.RunMethod("GetNFile", Null)
    Log("NFile: " & nfile)
 
    sn = Cooffee.RunMethod("GetSN", Null)
    Log("SN: " & sn)
 
    version = Cooffee.RunMethod("GetVersion", Null)
    Log("Version: " & version)
 
    temperature = Cooffee.RunMethod("GetTemperature", Null)
    Log("Temperature: " & temperature)

End Sub

Sub GetContext As JavaObject
   Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub

Sub Cooffee As JavaObject
   Dim jo As JavaObject
   Return jo.InitializeStatic("com.rft.irlib.IrHandler")
End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

1. If i dont add in line #AdditionalJar: irlib-release.aar ---> ".aar" i have error that jar isnt exist
2. When i try to compile i have this error:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/cooffee.testonlinecode-2/base.apk"],nativeLibraryDirectories=[/data/app/cooffee.testonlinecode-2/lib/arm64, /vendor/lib64, /system/lib64]]] couldn't find "libIrLib-jni.so"

The library libIrLib-jni.so i have in aar as in picture:

upload_2016-11-29_13-20-15.png



In attachment also library aar ( rename zip to aar )
Any idea ?
Thank you
Marco
 

Attachments

  • irlib-release.zip
    83.4 KB · Views: 251
Last edited:

MarcoRome

Expert
Licensed User
Longtime User
When i try with "old" library ( this is jar ) with same code i have another error.

The code is :

B4X:
#Region  Project Attributes
    #ApplicationLabel: Test JAR
    #VersionCode: 1
    #VersionName: 1.00
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalJar:  irlib-release-old

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim jo As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    'Inizializzo oggetto JavaObject
    If FirstTime Then jo.InitializeContext

'  jo.InitializeNewInstance("com.rft.irlib.IrHandler", Null)
'    'jo.InitializeStatic("com.rft.irlib.IrHandler")

    'PowerStart
    Dim batteria, memtot, memused, nfile As Int
    Dim sn, version As String
    Dim temperature As Float
    batteria = Cooffee.RunMethod("GetBattery", Null)
     Log("Batteria: " & batteria)
    memtot = Cooffee.RunMethod("GetMemTot", Null)
    Log("MemTot: " & memtot)

    memused = Cooffee.RunMethod("GetMemUsed", Null)
    Log("MemUsed: " & memused)
    nfile =  Cooffee.RunMethod("GetNFile", Null)
    Log("NFile: " & nfile)
    sn = Cooffee.RunMethod("GetSN", Null)
    Log("SN: " & sn)
    version = Cooffee.RunMethod("GetVersion", Null)
    Log("Version: " & version)
    temperature = Cooffee.RunMethod("GetTemperature", Null)
    Log("Temperature: " & temperature)

End Sub

Sub GetContext As JavaObject
   Return GetBA.GetField("context")
End Sub

Sub GetBA As JavaObject
  Dim jo As JavaObject
  Dim cls As String = Me
  cls = cls.SubString("class ".Length)
  jo.InitializeStatic(cls)
  Return jo.GetFieldJO("processBA")
End Sub

Sub Cooffee As JavaObject
   Dim jo As JavaObject
   Return jo.InitializeStatic("com.rft.irlib.IrHandler")
End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

The Error is:

** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
main_cooffee (java line: 409)
java.lang.ClassNotFoundException: com$rft$irlib$IrHandler
at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:288)
at anywheresoftware.b4j.object.JavaObject.InitializeStatic(JavaObject.java:74)
at cooffee.testonlinecode.main._cooffee(main.java:409)
at cooffee.testonlinecode.main._btn_start_click(main.java:374)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10814)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

The structure is the same ( look pictures )
upload_2016-11-29_14-3-16.png


but in this case dont give me error about SO library but "ClassNotFoundException" also if exist com.rft.irlib.IrHandler exist as see in pictures

jo.InitializeStatic("com.rft.irlib.IrHandler")

upload_2016-11-29_14-5-31.png


In attachment file jar, rename file zip in jar
Any idea ??
Thank you
Marco
 

Attachments

  • irlib-release-old.zip
    85.3 KB · Views: 231
Upvote 0
Top