Python compiler to apk

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.

Читайте также:  What is context in java examples

Launching Visual Studio Code

Your codespace will open once ready.

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

Latest commit

* Made p4a apk build command more general - readme * Fix twice spelled - readme * updated p4a build command

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

Источник

3 Ways to Convert Python App into APK

In August 2020, I started a medium blog series called Building Android App in Python, where I explained the usage of Kivy and Kivymd. These libraries allow you to create cross-platform apps using Python. In that series, I described how android apps are configured in Python, it’s limitations, and various key elements that build up an android app. At the end of the series (3rd part), I mentioned that I will convert an app into APK and deploy it on a cloud platform. Here is the article about the same! Here I will discuss three ways in which this conversion can be performed. If you haven’t followed this series or you are unaware of this library then I highly recommend you that check out the first part of the series:

Building Android Apps With Python: Part -1

Step by Step Guide to Build Android Apps using Python

The Challenge

The Python apps build with Kivy cannot be directly transferred to android phones as these devices only support APK (Android Application Package) and we need to package them properly. This conversion process is only possible on a Linux system (for now) as the main components of this conversion, buildozer and python-for-android are currently supported on Linux based systems only. This adds up a challenge for budding developers who generally who use a windows machine for all the coding purpose. Other challenges include failed app conversions, app crashing on the start, or not able to connect to the internet. While some issues need extra attention from your side, I will provide you 3 different ways to successfully convert the Python app to APK.

Before moving ahead, let’s look at the flow of the conversion:

  1. Making sure that the app entry point file is named as main.py
  2. Installing the dependencies.
  3. Initialize the buildozer
  4. Edit the specs file
  5. Start the process

We will see 1,2 and 4 steps in detail in upcoming sections as they don’t require any explicit change but it is necessary to understand how to configure the buildozer specs properly.

The buildozer spec file is automatically generated while initializing the buildozer. The file contains the whole configuration and the app is built following this only. There are a few lines that need to be modified in that file before proceeding with the next steps (There are a total of 339 lines in the actual file):

The source code for both the apps (Python file, APK, and buildozer spec) can be found at this GitHub repository.

If you don’t want to use the APK generated into your devices then you simply host them online using a free service called Appetize.io which allows you to run android apps in browsers!

Conclusion

In this article, we saw how to configure the deployment file needed to convert the Python file into APK. Then we saw 3 different ways to do this conversion. A local machine is the best option but if don’t want to mess with your system then I would suggest Google Colab as it has great processing power. If you are looking for CI/CD type solution then GitHub actions will suit your requirements. With this, we come to an end of this article as well as the development series.

If you don’t want to miss such articles then make sure to follow me on medium to receive all the notifications. With that said, Sayonara!

You can connect with me here:

Источник

Create a package for Android¶

You can create a package for android using the python-for-android project. This page explains how to download and use it directly on your own machine (see Packaging your application into APK or AAB ) or use the Buildozer tool to automate the entire process. You can also see Packaging your application for the Kivy Launcher to run kivy programs without compiling them.

For new users, we recommend using Buildozer as the easiest way to make a full APK or AAB. You can also run your Kivy app without a compilation step with the Kivy Launcher app.

Kivy applications can be released on an Android market such as the Play store, with a few extra steps to create a fully signed AAB (Android App Bundle).

The Kivy project includes tools for accessing Android APIs to accomplish vibration, sensor access, texting etc. These, along with information on debugging on the device, are documented at the main Android page .

Buildozer¶

Buildozer is a tool that automates the entire build process. It downloads and sets up all the prerequisites for python-for-android, including the android SDK and NDK, then builds an apk that can be automatically pushed to the device.

Buildozer currently works only in Linux and macOS (You can still use it on Windows via WSL), and can significantly simplify the apk build.

Please find the installation instructions here

Including the “Targeting Android” section.

Afterwards, navigate to your project directory and run:

This creates a buildozer.spec file controlling your build configuration. You should edit it appropriately with your app name etc. You can set variables to control most or all of the parameters passed to python-for-android.

Finally, plug in your android device and run:

buildozer android debug deploy run 

to build, push and automatically run the apk on your device.

Buildozer has many available options and tools to help you, the steps above are just the simplest way to build and run your APK. The full documentation is available here. You can also check the Buildozer README at https://github.com/kivy/buildozer.

Packaging with python-for-android¶

You can also package directly with python-for-android, which can give you more control but requires you to manually download parts of the Android toolchain.

Packaging your application for the Kivy Launcher¶

The Kivy launcher is an Android application that runs any Kivy examples stored on your SD Card. To install the Kivy launcher, you must:

  1. Go on Google Play Store and search for Kivy Launcher from kivy org
  2. Click on Install
  3. Select your phone… And you’re done!

If you don’t have access to the Google Play Store on your phone/tablet, you can download and install the APK manually from https://github.com/kivy/kivy-launcher/releases

Once the Kivy launcher is installed, you can put your Kivy applications in the Kivy directory in your external storage directory (often available at /sdcard even in devices where this memory is internal), e.g.

/sdcard/kivy/yourapplication> 

should be a directory containing:

# Your main application file: main.py # Some info Kivy requires about your app on android: android.txt 

The file android.txt must contain:

title=Application Title> author=Your Name> orientation=portrait|landscape> 

These options are just a very basic configuration. If you create your own APK using the tools above, you can choose many other settings.

Installation of Examples¶

Kivy comes with many examples, and these can be a great place to start trying the Kivy launcher. You can run them as below:

#. Download the `Kivy demos for Android `_ #. Unzip the contents and go to the folder `kivydemo-for-android` #. Copy all the the subfolders here to 

Release on the market¶

If you have built your own APK with Buildozer or with python-for-android, you can create a release version that may be released on the Play store or other Android markets.

To do this, you must run Buildozer with the release parameter (e.g. buildozer android release ), or if using python-for-android use the —release option to build.py. This creates a release AAB in the bin directory, which you must properly sign and zipalign. The procedure for doing this is described in the Android documentation at https://developer.android.com/studio/publish/app-signing.html#signing-manually — all the necessary tools come with the Android SDK.

Targeting Android¶

Kivy is designed to operate identically across platforms and as a result, makes some clear design decisions. It includes its own set of widgets and by default, builds an APK or AAB with all the required core dependencies and libraries.

It is possible to target specific Android features, both directly and in a (somewhat) cross-platform way. See the Using Android APIs section of the Kivy on Android documentation for more details.

Источник

Оцените статью