sputnikdev / eclipse-smarthome-bluetooth-binding-tinyb-transport

Eclipse Smarthome Bluetooth Binding TinyB Transport
1 stars 1 forks source link

java.lang.IllegalStateException: Could not load native libraries for TinyB #2

Open svagionitis opened 6 years ago

svagionitis commented 6 years ago

Hi @vkolotov,

First thanks for this bluetooth tinyb transport binding. I have the following issue:

I am building a custom image for a Raspberry Pi 3 using the aarch64 machine architecture. The java version is the following

# java -version
openjdk version "1.8.0_161-internal"
OpenJDK Runtime Environment (build 1.8.0_161-internal-b15)
OpenJDK 64-Bit Server VM (build 25.161-b15, mixed mode)

I can run openHAB2 with no issues. I have built the tinyb library v0.5.1 for the aarch64 architecture and put it in the /usr/lib directory

/usr/lib/libjavatinyb.so
/usr/lib/libtinyb.so
/usr/lib/libjavatinyb.so.0.5.0
/usr/lib/libtinyb.so.0
/usr/lib/java/tinyb.jar
/usr/lib/pkgconfig/tinyb.pc
/usr/lib/libtinyb.so.0.5.0
/usr/lib/libjavatinyb.so.0

In the openHAB2 addons directory I have put the org.eclipse.smarthome.binding.bluetooth-1.1.4.jar and the org.eclipse.smarthome.binding.bluetooth.transport.tinyb-1.1.1.jar files. I receive the following error:

2018-03-29 13:20:51.406 [ERROR] [me.binding.bluetooth.transport.tinyb] - [binding.bluetooth.transport.tinyb.activator(237)] The activate method has thrown an exception
java.lang.IllegalStateException: Could not load native libraries for TinyB
        at org.sputnikdev.esh.binding.bluetooth.transport.tinyb.activator.TinyBActivator.activate(TinyBActivator.java:19) [244:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.1.1]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
        at org.apache.felix.scr.impl.inject.BaseMethod.invokeMethod(BaseMethod.java:229) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.inject.BaseMethod.access$500(BaseMethod.java:39) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.inject.BaseMethod$Resolved.invoke(BaseMethod.java:650) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.inject.BaseMethod.invoke(BaseMethod.java:506) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.inject.ActivateMethod.invoke(ActivateMethod.java:307) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.inject.ActivateMethod.invoke(ActivateMethod.java:299) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.createImplementationObject(SingleComponentManager.java:298) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.createComponent(SingleComponentManager.java:109) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:906) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:879) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:749) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:675) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.AbstractComponentManager.enable(AbstractComponentManager.java:430) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.manager.ConfigurableComponentHolder.enableComponents(ConfigurableComponentHolder.java:657) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.BundleComponentActivator.initialEnable(BundleComponentActivator.java:341) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.Activator.loadComponents(Activator.java:390) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.Activator.access$200(Activator.java:54) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.scr.impl.Activator$ScrExtension.start(Activator.java:265) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.utils.extender.AbstractExtender.createExtension(AbstractExtender.java:254) [44:org.apache.felix.scr:2.0.12]
        at org.apache.felix.utils.extender.AbstractExtender.modifiedBundle(AbstractExtender.java:227) [44:org.apache.felix.scr:2.0.12]
        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:482) [?:?]
        at org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:415) [?:?]
        at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:232) [?:?]
        at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:444) [?:?]
        at org.eclipse.osgi.internal.framework.BundleContextImpl.dispatchEvent(BundleContextImpl.java:903) [?:?]
        at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [?:?]
        at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEventPrivileged(EquinoxEventPublisher.java:213) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:120) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxEventPublisher.publishBundleEvent(EquinoxEventPublisher.java:112) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxContainerAdaptor.publishModuleEvent(EquinoxContainerAdaptor.java:156) [?:?]
        at org.eclipse.osgi.container.Module.publishEvent(Module.java:476) [?:?]
        at org.eclipse.osgi.container.Module.start(Module.java:467) [?:?]
        at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) [?:?]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1253) [8:org.apache.felix.fileinstall:3.5.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1225) [8:org.apache.felix.fileinstall:3.5.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512) [8:org.apache.felix.fileinstall:3.5.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361) [8:org.apache.felix.fileinstall:3.5.8]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312) [8:org.apache.felix.fileinstall:3.5.8]

The same happens when I build the bluetooth tinyb transport binding myself, org.eclipse.smarthome.binding.bluetooth.transport.tinyb-1.1.2-SNAPSHOT.jar with the current master (using as dependency the current master of bluetooth manager tinyb.

Maybe I am missing something, I am not sure what to do next. I would appreciate a little help.

vkolotov commented 6 years ago

Hi @svagionitis, it might be that OH looks into a different folder for native libs. Could you please run this in the karaf console?

openhab> system:property | grep os.arch
os.arch=arm
openhab> system:property | grep os.name
org.osgi.framework.os.name=Linux
os.name=Linux
openhab> system:property | grep java.library.path
java.library.path=:/var/lib/openhab2/lib:/usr/share/openhab2/runtime/lib:/usr/java/packages/lib/arm:/lib:/usr/lib   

Could you please post your output here? E.g.

os.arch=arm
os.name=Linux
java.library.path=:/var/lib/openhab2/lib:/usr/share/openhab2/runtime/lib:/usr/java/packages/lib/arm:/lib:/usr/lib   

Make sure that you've put tinyb libs (both files) in one of those folders that specified in java.library.path property. Also make sure you have only one version of tinyb there.

If that's not working, please enable DEBUG level for TnyB transport in the karaf console (you should be running the latest SNAPSHOT version of TinyB transport):

openhab> log:info DEBUG org.sputnikdev.bluetooth.manager.transport.tinyb

Restart your OH and capture the logs from the beginning. It should give you a better explanation (exception). Please post the result here so I could add support for your arch in the transport for everyone (or if you can you could contribute yourself, your help will be much appreciated ;) ).

svagionitis commented 6 years ago

Hi @vkolotov,

Thanks your reply. Next following what you requested

os.arch=aarch64
os.name=Linux
java.library.path=/usr/lib/jvm/openjre-8/lib/aarch64/server:/usr/lib/jvm/openjre-8/lib/aarch64:/usr/lib/jvm/openjre-8/../lib/aarch64::/opt/openhab2/userdata/lib:/opt/openhab2/runtime/lib:/usr/java/packages/lib/aarch64:/lib:/usr/lib

I can see that the tinyb libraries are located in the /usr/lib which is included in the java.library.path and in no other place.

I enabled the DEBUG actually for the whole OH :), but here it is the specific output for the tinyb bluetooth binding (I have used the released org.eclipse.smarthome.binding.bluetooth.transport.tinyb-1.1.1.jar)

2018-03-30 11:44:21.449 [WARN ] [th.manager.impl.BluetoothManagerImpl] - Adapter discovery job error
java.lang.RuntimeException: Native library is out of date. Please update the native library.
        at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:317) [15:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.1.1]
        at org.sputnikdev.bluetooth.manager.transport.tinyb.TinyBFactory.getDiscoveredAdapters(TinyBFactory.java:153) [15:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.1.1]
        at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$AdapterDiscoveryJob.discoverAdapters(BluetoothManagerImpl.java:762) [16:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.1.4]
        at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$AdapterDiscoveryJob.run(BluetoothManagerImpl.java:755) [16:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.1.4]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
        at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
        at java.lang.Thread.run(Unknown Source) [?:?]
2018-03-30 11:44:21.507 [WARN ] [th.manager.impl.BluetoothManagerImpl] - Device discovery job error
java.lang.RuntimeException: Native library is out of date. Please update the native library.
        at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:317) [15:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.1.1]
        at org.sputnikdev.bluetooth.manager.transport.tinyb.TinyBFactory.getDiscoveredDevices(TinyBFactory.java:166) [15:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.1.1]
        at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$DeviceDiscoveryJob.discoverDevices(BluetoothManagerImpl.java:668) [16:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.1.4]
        at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$DeviceDiscoveryJob.run(BluetoothManagerImpl.java:661) [16:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.1.4]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
        at java.util.concurrent.FutureTask.runAndReset(Unknown Source) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) [?:?]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) [?:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
        at java.lang.Thread.run(Unknown Source) [?:?]

I have used both v0.5.0 and v0.5.1 for the tinyb libraries and I get the same error.

Yes I could create a PR for this but it might take sometime because I am not so familiar with Java :).

vkolotov commented 6 years ago

Hi @svagionitis , I know what's that. This error means that tinyb.jar library and native libraries are of different versions. How do you build tinyb? Just make sure you build it from the master branch: https://github.com/intel-iot-devkit/tinyb/commits/master

The latest commit is https://github.com/intel-iot-devkit/tinyb/commit/ac6d3082d06183c860eea97f451d5a92022348e0

When you build tinyb lib, its build process generates a hashtag which is put into native lib and into MANIFEST.MF file of the java lib file. The tinyb binding (transport) repacks tinyb library into OSGi compatible java archive. The generated hashtag is moved into MANIFEST file of the binding here: https://github.com/sputnikdev/bluetooth-manager-tinyb/blob/629bf989c348f564b562afd3f2f78c9ffd3e59ed/src/main/resources/META-INF/MANIFEST.MF#L7

You need to make sure that this hashtag (Specification-Version) matches to the tag of your tinyb native libs when you build them. It gets printed in your console when you build tinyb. As far as I can understand, that hashtag is based on git hash, that's why it is important that you build tinyb from the very last commit so hashtags are matched.

svagionitis commented 6 years ago

Hi @vkolotov,

That was the issue, that you described above. I was building the tinyb as described in the documentation though if I build from the master with the last commit the Specification-Version is not in the format that you described, but it's 0.5. Next following the output of the cmake

$ cmake -DBUILDJAVA=ON ../
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'glib-2.0>=2.40'
--   Found glib-2.0, version 2.48.2
-- Checking for module 'gio-2.0>=2.40'
--   Found gio-2.0, version 2.48.2
-- Checking for module 'gio-unix-2.0>=2.40'
--   Found gio-unix-2.0, version 2.48.2
INFO - libtinyb Version v0.5.1
-- Found Java: /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java (found version "1.8.0.162") 
-- Found JNI: /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/libjawt.so  
-- JNI_INCLUDE_DIRS=/usr/lib/jvm/java-1.8.0-openjdk-amd64/include;/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux;/usr/lib/jvm/java-1.8.0-openjdk-amd64/include
-- JNI_LIBRARIES=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/libjawt.so;/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/server/libjvm.so
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- Configuring done
-- Generating done
-- Build files have been written to: /tinyb.git/build
$ cat java/manifest.txt 
Manifest-Version: 1.0
Bundle-Date: 2018-04-05 15:07:22
Bundle-ManifestVersion: 2
Bundle-Name: tinyb
Bundle-SymbolicName: tinyb
Bundle-Version: 0.5.1
Export-Package: tinyb
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"

Name: tinyb/
Package-Title: tinyb
Package-Vendor: Intel Corp.
Package-Version: 0.5.1
Specification-Title: TinyB
Specification-Vendor: Intel Corp.
Specification-Version: 0.5

Now, I did a little of investigation of how to get the hashtag that you refer on your comment and I found out that if I use the following

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bef0609..9301b9c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,7 +20,7 @@ set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_

 # Make a version file containing the current version from git.
 include (GetGitRevisionDescription)
-git_describe (VERSION "--tags")
+git_describe (VERSION "")

 if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_HEAD-HASH-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
   message (WARNING " - Install git to compile a production libtinyb!")

then the cmake gives the following

$ cmake -DBUILDJAVA=ON ../
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'glib-2.0>=2.40'
--   Found glib-2.0, version 2.48.2
-- Checking for module 'gio-2.0>=2.40'
--   Found gio-2.0, version 2.48.2
-- Checking for module 'gio-unix-2.0>=2.40'
--   Found gio-unix-2.0, version 2.48.2
INFO - libtinyb Version v0.4.3-48-gac6d308
-- Found Java: /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java (found version "1.8.0.162") 
-- Found JNI: /usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/libjawt.so  
-- JNI_INCLUDE_DIRS=/usr/lib/jvm/java-1.8.0-openjdk-amd64/include;/usr/lib/jvm/java-1.8.0-openjdk-amd64/include/linux;/usr/lib/jvm/java-1.8.0-openjdk-amd64/include
-- JNI_LIBRARIES=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/libjawt.so;/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre/lib/amd64/server/libjvm.so
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
-- Configuring done
-- Generating done
-- Build files have been written to: /tinyb.git/build
$ cat java/manifest.txt 
Manifest-Version: 1.0
Bundle-Date: 2018-04-05 15:11:39
Bundle-ManifestVersion: 2
Bundle-Name: tinyb
Bundle-SymbolicName: tinyb
Bundle-Version: 0.4.3
Export-Package: tinyb
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"

Name: tinyb/
Package-Title: tinyb
Package-Vendor: Intel Corp.
Package-Version: 0.4.3
Specification-Title: TinyB
Specification-Vendor: Intel Corp.
Specification-Version: 0.4

Although the library version changed, to INFO - libtinyb Version v0.4.3-48-gac6d308, the Specification-Version is 0.4. I believe that there must be some change in the regexs that split the version into pieces, I will investigate further.

Regardless of the above, I was able to re-bundle the tinyb transport binding by changing this https://github.com/sputnikdev/bluetooth-manager-tinyb/blob/629bf989c348f564b562afd3f2f78c9ffd3e59ed/src/main/resources/META-INF/MANIFEST.MF#L7 to 0.5. Now it's working fine, without any issues.

I believe you can close this issue. Thanks again for all your help.

wang70880 commented 5 years ago

Hey guys. I encountered the same problem with yours, but I run OH2 on ubuntu 16.04. I can not solve the bug: Native library is out of date. Please update the native library. My TinyB is the same as @svagionitis and I didn't use the Bluetooth Manager based on TinyB library. I installed the bluetooth binding from Paper UI. Also I don't understand what the native library you guys mentioned means. What I can only check is that the tinyB version of mine is 0.5.1.

wang70880 commented 5 years ago

Can anyone give me some advice? Thanks!