Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kivy: python for android + C++

Tags:

c++

python

kivy

I've used python-for_android to create a kivy based application running on android.

Some parts of my application have been optimized in c++ using cython.

I manage to compile all my code using python for android and a custom recipes.

My code also works perfectly with kivy under linux.

But on my android device, it failed to load some c++ function. For instance, I get the message :

ImportError: Cannot load library: reloc_library[1307]:  1839 cannot locate '_ZNSt9basic_iosIcSt11char_traitsIcEE4initEPSt15basic_streambufIcS1_E'...

Any idea ?

Thanks

like image 811
user984846 Avatar asked Jul 19 '13 12:07

user984846


People also ask

Can kivy be used for Android?

Kivy is a really interesting GUI framework that you can use to create desktop user interfaces and mobile applications on both iOS and Android. Kivy applications will not look like the native apps on any platform.

Is kivy better than flutter?

Key Differences between Kivy vs Flutter Though Kivy is good to create innovative applications with multi-touch functionalities, the user has to code for it, making it comparatively difficult for the user, unlike Flutter, which provides various ready-to-use widgets for creating the attractive UI of the applications.

Is kivy better than Django?

Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design; Kivy: *An open source Python framework *. It is an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.

Is Python kivy free for commercial use?

Kivy is a free and open source Python framework for developing mobile apps and other multitouch application software with a natural user interface (NUI).


2 Answers

I've finally managed to make my code work using C++ under android.

There were two difficulties :

1 - Access to c++ header from the arm environment created by push_arm. I had to add the correct includes in my recipe, and modify the default CXX var :

    #dirty hack
    export C_INCLUDE="-I$ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/$TOOLCHAIN_VERSION/include/ -I$ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/$TOOLCHAIN_VERSION/libs/armeabi/include/"
    export OLD_BOUBOU=$CC
    export CC="$CXX $C_INCLUDE"

    try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
    #try cp libgnustl_shared.so $LIBS_PATH/
    try cp $ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/libgnustl_shared.so $LIBS_PATH/

    export CC=$OLD_BOUBOU

2 - Find the shared library containing the libstl functions, and load it. This was the harder part :

After some research, I discover that stl functions are stored in libgnustl_shared.so, and not listdc++.so. So you have to embed this library in your apk.

This is the purpose of the line try cp $ANDROIDNDK/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/libgnustl_shared.so $LIBS_PATH/

Then, you have to load it. I've modified :

src/src/org/renpy/android/PythonActivity.java
src/src/org/renpy/android/PythonService.java
by adding this line after the others System.loadLibrary() :
System.loadLibrary("gnustl_shared");
like image 100
user984846 Avatar answered Oct 01 '22 04:10

user984846


I am currently trying to build pybox2d (with swig) via python-for-android.

The build seems to be fine unit i try to import Box2D ( from the app on the actual android device) i get a "cannot locate symbol __cxa_end_cleanup".

Unfortunately the above fix doies not help. Any other ideas?

Update: I could fix all issues. I had to link against stlport_shared.

All my work is in my fork of https://github.com/DerThorsten/python-for-android/ . It works with newer ndks then the orginal python-for-android. And it has Box2D.

like image 21
Thorsten B'eggs Avatar answered Oct 01 '22 04:10

Thorsten B'eggs