termux / x11-packages

A set of packages using X11 Windows System.
Other
547 stars 145 forks source link

About kivy #638

Closed T-Dynamos closed 2 years ago

T-Dynamos commented 2 years ago

Screenshot_2022-03-13-17-49-25-125_com realvnc viewer android

Problem description

I successfully compiled kivy but unable to get window some error occurs

What steps will reproduce the bug?

[CRITICAL] [Window      ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - ImportError: dlopen failed: cannot locate symbol "XAllocClassHint" referenced by "/data/data/com.termux/files/usr/lib/python3.10/site-packages/kivy/graphics/cgl_backend/cgl_sdl2.cpython-310.so"

What is the expected behavior?

It should work

System information

termux-info:

Application version:
0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.org/apt/termux-main/ stable main
# x11-repo (sources.list.d/x11.list)
deb https://packages.termux.org/apt/termux-x11 x11 main
Updatable packages:
apt/stable 2.4.1-1 aarch64 [upgradable from: 2.4.1]
findutils/stable 4.9.0 aarch64 [upgradable from: 4.8.0]
freetype/stable 2.11.1 aarch64 [upgradable from: 2.11.0]
sdl2-image-static/x11 2.0.5-29 aarch64 [upgradable from: 2.0.5-28]
sdl2-image/x11 2.0.5-29 aarch64 [upgradable from: 2.0.5-28]
sdl2-mixer-static/x11 2.0.4-18 aarch64 [upgradable from: 2.0.4-17]
sdl2-mixer/x11 2.0.4-18 aarch64 [upgradable from: 2.0.4-17]
sdl2-net-static/x11 2.0.1-4 aarch64 [upgradable from: 2.0.1-3]
sdl2-net/x11 2.0.1-4 aarch64 [upgradable from: 2.0.1-3]
sdl2-ttf-static/x11 2.0.15-24 aarch64 [upgradable from: 2.0.15-23]
sdl2-ttf/x11 2.0.15-24 aarch64 [upgradable from: 2.0.15-23]
Android version:
7.0
Kernel build information:
Linux localhost 3.18.31-perf-g040a88f termux/termux-packages#1 SMP PREEMPT Thu Nov 7 00:28:25 WIB 2019 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
Redmi Note 4
xtkoba commented 2 years ago

This is basically due to android/ndk#201.

XAllocClassHint is defined in $PREFIX/lib/libX11.so, so you need to

export LDFLAGS+=" -lX11"

before building.

T-Dynamos commented 2 years ago

Can you show an example of working kivy on termux?

T-Dynamos commented 2 years ago

@xtkoba I tried reinstalling with pip but it installed in like few seconds previous build took like an hour . I am now retrying with pip cache purge

[CRITICAL] [Window      ] Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - RuntimeError: b'OpenGL support is either not configured in SDL or not available in current SDL video driver (x11) or platform'

Screenshot_2022-03-13-20-27-33-364_com realvnc viewer android

T-Dynamos commented 2 years ago

@xtkoba Thanks

xtkoba commented 2 years ago

No need to mention my name.

Note that currently sdl2 packages is not configured with OpenGL support: https://github.com/termux/x11-packages/issues/624.

Transferring to x11-packages repository.

T-Dynamos commented 2 years ago

Add mtdev also in requirements it was also giving error of dlopen failed unable to locate libmtdev.so.1 when I installed mtdev in termux it makes so file libmtdev.so so i made a symbolic link with ln -s libmtdev.so to libmtdev.so.1 and it worked . Same error as https://github.com/termux/x11-packages/issues/624#issuecomment-1057869114

xtkoba commented 2 years ago

As for mtdev,

--- a/kivy/lib/mtdev.py
+++ b/kivy/lib/mtdev.py
@@ -27,7 +27,7 @@

 # load library
 if 'KIVY_DOC' not in os.environ:
-    libmtdev = cdll.LoadLibrary('libmtdev.so.1')
+    libmtdev = cdll.LoadLibrary('libmtdev.so')

 # from linux/input.h
 MTDEV_CODE_SLOT          = 0x2f  # MT slot being modified
T-Dynamos commented 2 years ago

Are you done with it ? If not can I test it?

xtkoba commented 2 years ago

You can test the artifacts in PR #637 and see what happens. Do not forget to uninstall pip-managed kivy before installing the deb package. The PR is marked as draft because it is not going to be merged unless pip install kivy on device is severely broken.

I cannot reproduce the XAllocClassHint issue. (Maybe some dependencies are missing?)

T-Dynamos commented 2 years ago

In this build.sh this you have set ldflags to something else that you have suggest me ??

LDFLAGS+=" -lpython${_PYTHON_VERSION}"

You said that to keep it


export LDFLAGS+=" -lX11"

Screenshot_2022-03-14-18-30-30-813_com termux

Getting same error of sdl2 not configured with opengl even after installing deb file

Do i have to install sdl2 again?

xtkoba commented 2 years ago

In reply to the former part: -lpython3.10 is yet another workaround for android/ndk#201 that is necessary for building every Python extension. With cross building (or with current dependency) -X11 is not needed thus "cannot reproduce."

In reply to the latter part: it is expected because sdl2 package in our x11 repo is not configured with OpenGL (#624):

https://github.com/termux/x11-packages/blob/7a2a4536a0dd28fa1717e5dd01d5a06e4c3d7af0/packages/sdl2/build.sh#L34

These two parts are not much relevant to each other.

T-Dynamos commented 2 years ago

So now I have to rebuild sdl2 with --enable-video-opengl? Any why this can't be added in termux Getting this after build

sdl2 - RuntimeError: b'SDL not configured with OpenGL/GLX support'
xtkoba commented 2 years ago

You can test the artifacts in PR #639 and see what happens when combined with mesa.

T-Dynamos commented 2 years ago

Works fine and window work but gives error of cut buffer

[CRITICAL] [Cutbuffer   ] Unable to find any valuable Cutbuffer provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
xclip - FileNotFoundError: [Errno 2] No such file or directory: 'xclip'

And window crashes Ok fixed it by building xclip from https://github.com/astrand/xclip here but still window crashes Screenshot_2022-03-16-18-29-33-071_com realvnc viewer android

Yisus7u7 commented 2 years ago

@xtkoba

I think the error was the mesa update, kivy needs to use openGL in a basic way, the previous version of mesa worked without problems, but when you updated mesa, it was broken, when running any program that is going to use OpenGL, "Bad System call" appears, this did not happen before.

Screenshot_20220316-083107

T-Dynamos commented 2 years ago

@Yisus7u7 But glxgears works fine with huge fps Screenshot_2022-03-16-19-27-41-650_com realvnc viewer android Segmentation Fault in kivy IMG_20220316_193131

Yisus7u7 commented 2 years ago

But glxgears works fine with huge fps Screenshot_2022-03-16-19-27-41-650_com realvnc viewer android IMG_20220316_193131

Well, this may happen only in arm32

xtkoba commented 2 years ago

Not surprisingly.

T-Dynamos commented 2 years ago

I suggest you to check kivy python for Android recipes

https://github.com/kivy/python-for-android/tree/develop/pythonforandroid/recipes

Grimler91 commented 2 years ago

Segmentation Fault in kivy

How do you know that the issue is in kivy and not in the project you are trying to run? Try running some minimal kivy example instead

I suggest you to check kivy python for Android recipes

https://github.com/kivy/python-for-android/tree/develop/pythonforandroid/recipes

Not sure what we are suppose to "check" there

xtkoba commented 2 years ago

Those recipes do not seem to be for Termux. Note that Termux is pretending not to be Androind in many situations. Building sdl2 is one of them:

https://github.com/termux/x11-packages/blob/c3dd4344ab588c1e08d270d4b9aed5c73e7e5869/packages/sdl2/build.sh#L51-L55

T-Dynamos commented 2 years ago

Ok I am trying but I even tried running kivy on proot-distro Ubuntu arm64 have same segmentation fault error , but same project on arm32 proot-distro Ubuntu works well and One thing more my project was working fine on android with buildozer (kivy) apk architecture was https://github.com/T-Dynamos/SRAPS-App/blob/f95ca4d772b974d244b044398777874548839649/buildozer.spec#L222 armeabi-v7a , therefore I suggest to see kivy's python for android recipes here's my project link I was using kivymd module

https://github.com/T-Dynamos/SRAPS-App So i tried a simple program

import kivy
from kivy.app import App
from kivy.uix.label import Label

# Replace this with your
# current version
kivy.require('1.11.1')

# Defining a class
class MyFirstKivyApp(App):

    # Function that returns
    # the root widget
    def build(self):

        # Label with text Hello World is
        # returned as root widget
        return Label(text ="Hello World !")     

# Here our class is initialized
# and its run() method is called.
# This initializes and starts
# our Kivy application.
MyFirstKivyApp().run()          

Screenshot_2022-03-16-23-11-31-809_com realvnc viewer android It works so what's issue

T-Dynamos commented 2 years ago

Screenshot_2022-03-17-09-43-08-585_com realvnc viewer android Simple kivy programs seems to be work but including kivymd module just crashes with fish: Job 1, 'python3 main.py' terminated by signal SIGSEGV (Address boundary error)

xtkoba commented 2 years ago

@Yisus7u7 TL;DR:

export LD_PRELOAD="libandroid-shmem.so"

A little bit detail:

A basic thing that you should do when encounteing with "Bad system call" or similar is to strace the process.

With straceing the glxgears process I get the following line in the trace log:

--- SIGSYS {si_signo=SIGSYS, si_code=SYS_SECCOMP, si_call_addr=0x797ede3430, si_syscall=__NR_shmget, si_arch=AUDIT_ARCH_AARCH64} ---

This reminded me of https://github.com/termux/termux-packages/issues/8162 immediately. If the process called the shmget function defined in libandroid-shmem.so, then the system call shmget would never be called.

If I opened an issue about this, I would give it the title as follows:

[Bug]: libandroid-shmem not taking effect unless linked against main executable

[EDIT]: There is a workaround that makes LD_PRELOAD unnecessary. A preceding example is for res_init and res_search in krb5 package. I'll work on it.

mguinhos commented 2 years ago

Screenshot_20220321-122906_VNC Viewer.jpg

Looks like it is also Segfaulting somewere after mesa's blend_general_float() function. Due to an invalid memory acess. Dont think there is something to do with kivymd itself.

For now i am just watching how you guys will solve this, looks like pretty complicated.

mguinhos commented 2 years ago

This is very interesting, because the previous mesa version was working well with kivymd.

T-Dynamos commented 2 years ago

I think so kivymd uses pillow and there's problem with pillow

mguinhos commented 2 years ago

I think so kivymd uses pillow and there's problem with pillow

The problem is not Pillow. In fact it is mesa's fault. Kivy let you change kivy's image, font, and audio providers with the environment variables. Pillow is not a requirement.

https://kivy.org/doc/stable/guide/environment.html

mguinhos commented 2 years ago
export KIVY_GL_DEBUG=1
...
GL glClear( mask = 17664, )
GL glUseProgram( program = 1, )
GL glUniform1f( location = 3, x = 1.0, )
GL glUniform1i( location = 4, x = 0, )
GL glUniform4f( location = 2, x = 1.0, y = 1.0, z = 1.0, w = 1.0, )
GL glUniformMatrix4fv( location = 1, count = 1, transpose = 0, value*='0x7fedd72990', )
GL glUniformMatrix4fv( location = 0, count = 1, transpose = 0, value*='0x7fedd72990', )
GL glGetUniformLocation( program = 1, name*=b'frag_modelview_mat', )
GL glGetIntegerv( pname = 35725, params*='0x7fedd72584', )
GL glUniform4f( location = 2, x = 0.0, y = 0.0, z = 0.0, w = 0.0, )
GL glBindTexture( target = 3553, texture = 1, )
GL glGenBuffers( n = 1, buffers*='0x71953f6e78', )
GL glBindBuffer( target = 34963, buffer = 1, )
GL glBufferData( target = 34963, size = 96, data*='0x727b9beb70', usage = 35048, )
GL glGenBuffers( n = 1, buffers*='0x719565ed60', )
GL glBindBuffer( target = 34962, buffer = 2, )
GL glDrawElements( mode = 3, count = 74, type = 5123, indices*='0x0', )

Got a call trace, with the KIVY_GL_DEBUG environment variable, these are the last calls before crashing

mguinhos commented 2 years ago

Looks like there is something to do with the texturing or even shading.

mguinhos commented 2 years ago

But, Dont worry, this will be solved soon! Kivy is almost working!

The problem is neither of the python libraries.

xtkoba commented 2 years ago

Ah, I almost forgot this. Would you please open a new issue for the mesa crash? As discussed above, it seems to be independent of kivy. If possible, please provide a reproducing example that does not use kivy. Thanks.

T-DynamosFans commented 2 years ago

Couldn't believe on my eyes . I am @T-Dynamos Screenshot_2022-04-09-11-25-38-164_com realvnc viewer android Screenshot_2022-04-09-11-16-58-278_com realvnc viewer android termux-info

Application version:
0.117
Packages CPU architecture:
arm
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.org/apt/termux-main stable main
# game-repo (sources.list.d/game.list)
deb https://packages.termux.org/apt/termux-games games stable
# science-repo (sources.list.d/science.list)
deb https://packages.termux.org/apt/termux-science science stable
# x11-repo (sources.list.d/x11.list)
deb https://packages.termux.org/apt/termux-x11 x11 main
Updatable packages:
apt/stable 2.4.1-2 arm [upgradable from: 2.3.6]
bash/stable 5.1.16-1 arm [upgradable from: 5.1.16]
curl/stable 7.82.0-1 arm [upgradable from: 7.82.0]
gzip/stable 1.12 arm [upgradable from: 1.11-3]
libcap-ng/stable 2:0.8.3 arm [upgradable from: 1:0.8.3-pre1-0]
libcurl/stable 7.82.0-1 arm [upgradable from: 7.82.0]
libexpat/stable 2.4.8 arm [upgradable from: 2.4.7]
libgcrypt/stable 1.10.1 arm [upgradable from: 1.9.4]
libsqlite/stable 3.38.2 arm [upgradable from: 3.38.1]
perl/stable 5.34.1-1 arm [upgradable from: 5.34.1]
termux-keyring/stable 3.1 all [upgradable from: 3.0]
termux-tools/stable 0.173 all [upgradable from: 0.168]
unbound/stable 1.15.0 arm [upgradable from: 1.13.2-3]
util-linux/stable 2.38 arm [upgradable from: 2.37.4]
zlib/stable 1.2.12 arm [upgradable from: 1.2.11-5]
Android version:
10
Kernel build information:
Linux localhost 4.9.190-perf-gba91b47 #1 SMP PREEMPT Tue Mar 8 15:43:19 CST 2022 armv8l Android
Device manufacturer:
Xiaomi
Device model:
M2006C3MII

Working on arm . I used master branch of kivymd pip3 install https://github.com/kivymd/KivyMD/archive/refs/heads/master.zip Can you please include steps on Termux wiki to instl kivy?

Steps

apt install "sdl2*" "sdl2-*" -y
LDFLAGS+=" -lpython3.10"
pip3 install kivy

For kivymd

T-DynamosFans commented 2 years ago

Screenshot_2022-04-09-11-53-33-579_com realvnc viewer android Screenshot_2022-04-09-11-52-38-196_com realvnc viewer android But fps are too low like 2fps , but on a application it works fine . Do we have build some graphics drivers?

Yisus7u7 commented 2 years ago

@T-Dynamos

apt install gl4es

LD_LIBRARY_PATH=$PREFIX/lib/gl4es ./app.py
T-DynamosFans commented 2 years ago

For graphics drivers?

Yisus7u7 commented 2 years ago

For graphics drivers?

Yes

T-DynamosFans commented 2 years ago

And what does it means ?

Mesa: User error: GL_INVALID_OPERATION in glUniform1("t"@2 is float, not int)
Mesa: User error: GL_INVALID_OPERATION in glUniform1("t"@2 is float, not int)
T-DynamosFans commented 2 years ago

For graphics drivers?

Yes

I don't get it . Can you explain?

Yisus7u7 commented 2 years ago

Screenshot_20220409-021527

Yes, works slow...

T-DynamosFans commented 2 years ago

Ok let's try it on arm64 till then you can try with fps monitoring and these examples https://github.com/HeaTTheatR/Articles and this also https://github.com/T-Dynamos/SRAPS-App

T-DynamosFans commented 2 years ago

Screenshot_2022-04-09-18-11-53-516_com realvnc viewer android Termux-info

Application version:
0.118.0
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://packages-cf.termux.org/apt/termux-main stable main
# x11-repo (sources.list.d/x11.list)
deb https://packages.termux.org/apt/termux-x11 x11 main
# root-repo (sources.list.d/root.list)
deb https://packages.termux.org/apt/termux-root root stable
# sources.list.d/termux-desktop-xfce.list
deb [trusted=yes arch=all] https://Yisus7u7.github.io/termux-desktop-xfce/packages desktop-xfce extras
Updatable packages:
All packages up to date
Android version:
7.0
Kernel build information:
Linux localhost 3.18.31-perf-g040a88f #1 SMP PREEMPT Thu Nov 7 00:28:25 WIB 2019 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
Redmi Note 4

Its confirmed that issue is only on arm64 and simple kivy programs work with same slow speed as arm

T-DynamosFans commented 2 years ago

@xtkoba Please add arm64 tag and reopen issue