简体   繁体   中英

How does Kivy achieve cross-platform compatibility?

What allows Kivy to be cross-platform compatible?

In other words, how can the same Kivy source code generate apps on multiple kinds of hardware platforms, such as desktop, iOS, and Android?

I suppose there are two key extremes of achieving cross-platform compatibility:

  1. By implementing things in a different way on each platform so that Kivy is running different code on each one, but hiding that difference from the user by making the output appear the same.
  2. By using external APIs that are supported by all the different platforms, so that Kivy's own code is basically the same and the platforms themselves take care of making it work.

Kivy has a bit of both of these, but in particular all the drawing uses OpenGL ES 2 which is the second type: all of Kivy's drawing logic is just about identical across all supported platforms. Of course there are other types too, eg when working out display metrics such as the pixel density Kivy uses a different method on each platform but doesn't expose any of that detail to the user.

Of course things are much more nuanced when considering things as a whole. For instance, Kivy uses SDL2 as a library for creating a window, setting its size/pos handling pause/resume etc., so Kivy's code is of the second type here as it calls SDL2 in the same way on every platform. However, SDL2 is not itself platform-native and is of the first type, implementing its API differently on different platforms but exposing the same API to Kivy on each one.

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