GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - yan12125/python3-android: Python 3 cross-compilation tools for Android.

This repository was archived by the owner on Feb 24, 2023. It is now read-only.
BranchesTags
Open more actions menu
 
 

Latest commit

 

History

696 Commits
696 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
Android
Android
 
 
devscripts
devscripts
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.sh
build.sh
 
 
clean.sh
clean.sh
 
 
docker-build.sh
docker-build.sh
 
 

Repository files navigation

Python 3 Android

This is an experimental set of build scripts that will cross-compile Python 3.9.0 for an Android device.

Prerequisites

Building requires:

  1. Linux. This project might work on other systems supported by NDK but no guarantee.
  2. Android NDK r21 installed and environment variable $ANDROID_NDK points to its root directory. Older NDK may not work and NDK <= r18 is known to be incompatible.
  3. python3.9 binary from Python 3.9.0 on the building host. It's recommended to use exactly that Python version, which can be installed via pyenv. Don't forget to check that python3.9 is available in $PATH.
  4. tic binary from ncurses 6.2 on the building host. Slightly newer or older version may also work but no guarantee.
  5. A case-sensitive filesystem. The default filesystem on Windows and macOS is case-insensitive, and building may fail.

Running requires:

  1. Android 5.0 (Lollipop, API 21) or above
  2. arm, arm64, x86 or x86-64

Build

  1. Run ./clean.sh for good measure.
  2. For every API Level/architecture combination you wish to build for:
    • ARCH=arm ANDROID_API=21 ./build.sh to build everything!

Build using Docker/Podman

Download the latest NDK for Linux from https://developer.android.com/ndk/downloads and extract it.

docker run --rm -it -v $(pwd):/python3-android -v /path/to/android-ndk:/android-ndk:ro --env ARCH=arm --env ANDROID_API=21 python:3.9.0-slim /python3-android/docker-build.sh

Here /path/to/android-ndk should be replaced with the actual for NDK (e.g., /opt/android-ndk).

Podman is also supported. Simply replace docker with podman in the command above.

Installation

  1. Make sure adb shell works fine
  2. Copy all files in build to a folder on the device (e.g., /data/local/tmp/python3). Note that on most devices /sdcard is not on a POSIX-compliant filesystem, so the python binary will not run from there.
  3. In adb shell:
cd /data/local/tmp/build
. ./env.sh
python3

And have fun!

SSL/TLS

SSL certificates have old and new naming schemes. Android uses the old scheme yet the latest OpenSSL uses the new one. If you got CERTIFICATE_VERIFY_FAILED when using SSL/TLS in Python, you need to collect system certificates: (thanks @GRRedWings for the idea)

cd /data/local/tmp/build
mkdir -p etc/ssl
cat /system/etc/security/cacerts/* > etc/ssl/cert.pem

Path for certificates may vary with device vendor and/or Android version. Note that this approach only collects system certificates. If you need to collect user-installed certificates, most likely root access on your Android device is needed.

Check SSL/TLS functionality with:

import urllib.request
print(urllib.request.urlopen('https://httpbin.org/ip').read().decode('ascii'))

Known Issues

No big issues! yay

About

Python 3 cross-compilation tools for Android.

Topics

androidndkpythonpython3

Resources

Readme
0BSD license
Activity

Stars

91 stars

Watchers

0 watching

Forks

34 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.