skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. I struggled for 3 days and finally got it running.

    Goal: A simple kivy app running on a samsung tablet with one "Send Hello World"-Button. On button press it should send a "Hello World" message over the rosbridge to a second device.
    The second device (my laptop) is running the rosbridge-server and listener-node which prints the "Hello world" message to the console.

    Problem: When I used the spec file with all requierements listed the build process would fail because of a patch error caused by zope.interface. The solution was to make a first build just with zope.interface.
    After the first build add all the needed dependencies listed in the debug logcat.

    Kivy version: 2.1.0

    Important notes:

    • I don’t need the following code to build my apk like @benschnapp
      suggested

      from kivy.support import install_twisted_reactor

      install_twisted_reactor()

    • uncomment/add android.permissions = android.permission.INTERNET to buildozer.spec

    Build process:

    First build:

    requirements = python3, kivy, zope.interface

    Second build: Add the needed modules

    requirements = python3, kivy, zope.interface, roslibpy, autobahn, txaio, twisted, attrs, hyperlink, idna, cryptography

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search