Kivy python android приложение

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Turn your Python application into an Android APK

License

kivy/python-for-android

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Python versions: Update documentation & CI testing

Git stats

Files

Failed to load latest commit information.

README.md

python-for-android is a packaging tool for Python apps on Android. You can create your own Python distribution including the modules and dependencies you want, and bundle it in an APK or AAB along with your own code.

  • Different app backends including Kivy, PySDL2, and a WebView with Python webserver.
  • Automatic support for most pure Python modules, and built in support for many others, including popular dependencies such as numpy and sqlalchemy.
  • Multiple architecture targets, for APKs optimised on any given device.
  • AAB: Android App Bundle support.

For documentation and support, see:

Follow the quickstart instructions to install and begin creating APKs and AABs.

Quick instructions: install python-for-android with:

pip install python-for-android 

(for the develop branch: pip install git+https://github.com/kivy/python-for-android.git )

Test that the install works with:

To build any actual apps, set up the Android SDK and NDK as described in the quickstart. Use the SDK/NDK API level & NDK version as in the quickstart, other API levels may not work.

With everything installed, build an APK with SDL2 with e.g.:

p4a apk --private PATH_TO_YOUR_APP_CODE --package=org.example.myapp --name "My application" --version 0.1 --bootstrap=sdl2 --requirements=python3,kivy 

If you need to deploy your app on Google Play, Android App Bundle (aab) is required since 1 August 2021:

For full instructions and parameter options, see the documentation.

If you need assistance, you can ask for help on our mailing list:

We love pull requests and discussing novel ideas. Check out the Kivy project contribution guide and feel free to improve python-for-android.

See our documentation for more information about the python-for-android development and release model, but don’t worry about the details. You just need to make a pull request, we’ll take care of the rest.

The following mailing list and IRC channel are used exclusively for discussions about developing the Kivy framework and its sister projects:

python-for-android is released under the terms of the MIT License. Please refer to the LICENSE file.

In 2015 these tools were rewritten to provide a new, easier-to-use and easier-to-extend interface. If you’d like to browse the old toolchain, its status is recorded for posterity at https://github.com/kivy/python-for-android/tree/old_toolchain.

In the last quarter of 2018 the python recipes were changed. The new recipe for python3 (3.7.1) had a new build system which was applied to the ancient python recipe, allowing us to bump the python2 version number to 2.7.15. This change unified the build process for both python recipes, and probably solved various issues detected over the years. These unified python recipes require a minimum target api level of 21, Android 5.0 — Lollipop. If you need to build targeting an api level below 21, you should use an older version of python-for-android (<=0.7.1).

On March of 2020 we dropped support for creating apps that use Python 2. The latest python-for-android release that supported building Python 2 was version 2019.10.6.

On August of 2021, we added support for Android App Bundle (aab). As a collateral, now We support multi-arch apk.

This project exists thanks to all the people who contribute. [Contribute].

Thank you to all our backers! 🙏 [Become a backer]

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

About

Turn your Python application into an Android APK

Источник

Kivy on Android¶

You can run Kivy applications on Android, on (more or less) any device with OpenGL ES 2.0 (Android 2.2 minimum). This is standard on modern devices; Google reports the requirement is met by 99.9% of devices.

Kivy APKs are normal Android apps that you can distribute like any other, including on stores like the Google Play Store. They behave properly when paused or restarted, may utilise Android services and have access to most of the normal java API as described below.

Follow the instructions below to learn how to package your app for Android , debug your code on the device , and use Android APIs such as for vibration and reading sensors.

Package for Android¶

The Kivy project provides all the necessary tools to package your app on Android, including building your own standalone APK or AAB that may be distributed on a market like the Google Play Store. This is covered fully in the Create a package for Android documentation.

Debugging your application on the Android platform¶

You can view the normal output of your code (stdout, stderr), as well as the normal Kivy logs, through the Android logcat stream. This is accessed through adb, provided by the Android SDK. You may need to enable adb in your device’s developer options, then connect your device to your computer and run:

You’ll see all the logs including your stdout/stderr and Kivy logger.

If you packaged your app with Buildozer, the adb tool may not be in your $PATH and the above command may not work. You can instead run:

to run the version installed by Buildozer, or find the SDK tools at $HOME/.buildozer/android/platform .

You can also run and debug your application using the Kivy Launcher. If you run your application this way, you will find log files inside the “/.kivy/logs” sub-folder within your application folder.

Using Android APIs¶

Although Kivy is a Python framework, the Kivy project maintains tools to easily use the normal java APIs, for everything from vibration to sensors to sending messages through SMS or email.

For new users, we recommend using Plyer . For more advanced access or for APIs not currently wrapped, you can use Pyjnius directly. Kivy also supplies an android module for basic Android functionality.

User contributed Android code and examples are available on the Kivy wiki.

Plyer¶

Plyer is a pythonic, platform-independent API to use features commonly found on various platforms, particularly mobile ones. The idea is that your app can call simply call a Plyer function, such as to present a notification to the user, and Plyer will take care of doing so in the right way regardless of the platform or operating system. Internally, Plyer uses Pyjnius (on Android), Pyobjus (on iOS) and some platform specific APIs on desktop platforms.

For instance, the following code would make your Android device vibrate, or raise a NotImplementedError that you can handle appropriately on other platforms such as desktops that don’t have appropriate hardware::

from plyer import vibrator vibrator.vibrate(10) # vibrate for 10 seconds 

Plyer’s list of supported APIs is growing quite quickly, you can see the full list in the Plyer README.

Pyjnius¶

Pyjnius is a Python module that lets you access java classes directly from Python, automatically converting arguments to the right type, and letting you easily convert the java results to Python.

Pyjnius can be obtained from github, and has its own documentation.

Here is a simple example showing Pyjnius’ ability to access the normal Android vibration API, the same result of the plyer code above:

# 'autoclass' takes a java class and gives it a Python wrapper from jnius import autoclass # Context is a normal java class in the Android API Context = autoclass('android.content.Context') # PythonActivity is provided by the Kivy bootstrap app in python-for-android PythonActivity = autoclass('org.renpy.android.PythonActivity') # The PythonActivity stores a reference to the currently running activity # We need this to access the vibrator service activity = PythonActivity.mActivity # This is almost identical to the java code for the vibrator vibrator = activity.getSystemService(Context.VIBRATOR_SERVICE) vibrator.vibrate(10000) # The value is in milliseconds - this is 10s 

This code directly follows the java API functions to call the vibrator, with Pyjnius automatically translating the api to Python code and our calls back to the equivalent java. It is much more verbose and java-like than Plyer’s version, for no benefit in this case, though Plyer does not wrap every API available to Pyjnius.

Pyjnius also has powerful abilities to implement java interfaces, which is important for wrapping some APIs, but these are not documented here — you can see Pyjnius’ own documentation.

Android module¶

Python-for-android includes a python module (actually cython wrapping java) to access a limited set of Android APIs. This has been largely superseded by the more flexible Pyjnius and Plyer as above, but may still occasionally be useful. The available functions are given in the python-for-android documentation.

This includes code for billing/IAP and creating/accessing Android services, which is not yet available in the other tools above.

Status of the Project and Tested Devices¶

These sections previously described the existence of Kivy’s Android build tools, with their limitations and some devices that were known to work.

The Android tools are now quite stable, and should work with practically any device; our minimum requirements are OpenGL ES 2.0 and Android 2.2. These are very common now — Kivy has even been run on an Android smartwatch!

As Kivy works fine on most devices, the list of supported phones/tablets has been retired — all Android devices are likely to work if they meet the conditions above.

Источник

Читайте также:  Java spring boot многопоточность
Оцените статью