简体   繁体   中英

Using Roslibpy on Android with Kivy and Buildozer

I am trying to create a simple Android app using Kivy and Buildozer that publishes a message to a Ros topic using roslibpy. The app works perfectly on Windows and Ubuntu, but crashes immediately on Android. I have been using logcat to debug on Android and have updated the buildozer.spec file with the roslibpy dependencies (autobahn, txaio, twisted). However, after adding twisted to the requirements, I still get the same error as before.

> buildozer android debug deploy run logcat

...

06-13 21:05:13.317 31150 31336 I python  :  Traceback (most recent call last):
06-13 21:05:13.318 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/app/main.py", line 5, in <module>
06-13 21:05:13.318 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/HelloKivyApp/arm64-v8a/roslibpy/__init__.py", line 113, in <module>
06-13 21:05:13.319 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/HelloKivyApp/arm64-v8a/roslibpy/ros.py", line 11, in <module>
06-13 21:05:13.319 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/HelloKivyApp/arm64-v8a/roslibpy/comm/__init__.py", line 9, in <module>
06-13 21:05:13.320 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/HelloKivyApp/arm64-v8a/roslibpy/comm/comm_autobahn.py", line 6, in <module>
06-13 21:05:13.320 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/HelloKivyApp/arm64-v8a/autobahn/twisted/__init__.py", line 36, in <module>
06-13 21:05:13.321 31150 31336 I python  :    File "/home/ben/sirrl/KivyMD/HelloKivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/HelloKivyApp/arm64-v8a/autobahn/twisted/util.py", line 32, in <module>
06-13 21:05:13.321 31150 31336 I python  :  ModuleNotFoundError: No module named 'twisted.internet'
06-13 21:05:13.322 31150 31336 I python  : Python for android ended.

I have tried clean builds, as well as all of the suggestions from How to build kivy and Twisted in Buildozer but have had no luck.

Here is buildozer.spec requirements I am using, I can post the full file if needed.

requirements = python3,kivy,kivymd,pillow,roslibpy,autobahn,txaio,twisted

Thanks for the help

I found this link describing how to use twisted in Kivy. https://kivy.org/doc/stable/guide/other-frameworks.html#server-app . You must run the following code at the top of main.py before importing roslibpy (or any library that depends on twisted)

from kivy.support import install_twisted_reactor
install_twisted_reactor()

import roslibpy

Unfortunatly, both kivy.support.install_twisted_reactor() and roslibpy.Ros(...).run() create and run an instance of the twisted reactor, and will cause an issue if both are called in the same program.

The solution I have found for this is to use kivy.support.install_twisted_reactor() on the first build (and after every clean build) which will fail on runtime with twisted.internet.error.ReactorAlreadyRunning , then remove kivy.support.install_twisted_reactor() and build and deploy again which should now work.

I'm sure there is a better way to do this in a more automated way that doesn't require multiple builds, but I have not found it yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM