Skip to main content

Build native packages for Android

Project description

Build native packages for Android.

Requirements

  • Python;
  • Android SDK;

The Android SDK can be installed from Android Studio.

Then set the environment variable ANDROID_SDK_ROOT or ANDROID_HOME.

Finally, Python's distutils package must be patched for cross-compiling. The patch is in the patches directory. Apply it like so:

DESTLIB=$(python -c "import sysconfig; \
    print(sysconfig.get_config_var('DESTLIB'))")
patch -p2 -d $DESTLIB < patches/patch-Python-3.10.0.txt

This patch should apply to any version of Python.

You may need to use sudo.

Install androidenv

Install from the Python Package Index:

pip install androidenv

You can also copy the file androidenv.py to where you need it, it is self contained.

Usage

Build something from source:

cd thing
python -m androidenv setup.py build
python -m androidenv setup.py install

You really want to do this in a virtual environment.

Use the --find-library option to find libraries like libandroid or liblog:

python -m androidenv --find-library android log

Environment variables

This module works entirely with environment variables.

Input environment variables:

  • ANDROID_SDK_ROOT or ANDROID_HOME (required);
  • ABI (optional; armeabi-v7a or arm64-v8a);
  • API (optional);
  • DEBUG (optional; 0 or 1);

What is being built must respect the following evironment variables:

  • AR
  • AS
  • CC
  • CFLAGS
  • CPP
  • CPPFLAGS
  • CXX
  • CXXFLAGS
  • LD
  • LDFLAGS
  • PATH
  • RANLIB
  • READELF
  • STRIP

Many packages do, many don't. Python itself (distutils) does not respect RANLIB; CMake does not respect CPPFLAGS; and many more. Fixing that is your homework.

setup.cfg

Some useful configuration options when building for Android:

[build]
build-base = build
build-temp = build/tmp
build-lib = build/lib

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

androidenv-0.9.tar.gz (5.8 kB view details)

Uploaded Source

File details

Details for the file androidenv-0.9.tar.gz.

File metadata

  • Download URL: androidenv-0.9.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for androidenv-0.9.tar.gz
Algorithm Hash digest
SHA256 af405b7e007286f3bc207302387c1836fa685581ff9679f9acb093d392ec1682
MD5 68ee69ed8d8bfb541673b770a54d49b2
BLAKE2b-256 000d5e478ef9a54398c287d6cd907f54852ff2f848ac0517e75dcce92819c61b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page