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.
[Android Studio]: https://developer.android.com/studio/
[ANDROID_SDK_ROOT]: https://developer.android.com/studio/command-line/variables
[distutils]: https://docs.python.org/3/library/distutils.html
## 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][venv].
[venv]: https://docs.python.org/3/library/venv.html
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
Raw data
{
"_id": null,
"home_page": "https://github.com/mansourmoufid/python-androidenv",
"name": "androidenv",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "android",
"author": "Mansour Moufid",
"author_email": "mansourmoufid@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4f/c8/69533b74b74e5dda4d09d05803e353f6b3f73ef4c8b4d8ca76edb9c47ef2/androidenv-1.0.tar.gz",
"platform": null,
"description": "Build native packages for Android.\n \n \n ## Requirements\n \n - Python;\n - Android SDK;\n \n The Android SDK can be installed from [Android Studio][].\n \n Then set the environment variable [ANDROID_SDK_ROOT][] or ANDROID_HOME.\n \n Finally, Python's [distutils][] package must be patched for cross-compiling.\n The patch is in the patches directory. Apply it like so:\n \n DESTLIB=$(python -c \"import sysconfig; \\\n print(sysconfig.get_config_var('DESTLIB'))\")\n patch -p2 -d $DESTLIB < patches/patch-Python-3.10.0.txt\n \n This patch should apply to any version of Python.\n \n You may need to use sudo.\n \n \n [Android Studio]: https://developer.android.com/studio/\n [ANDROID_SDK_ROOT]: https://developer.android.com/studio/command-line/variables\n [distutils]: https://docs.python.org/3/library/distutils.html\n \n \n ## Install androidenv\n \n Install from the Python Package Index:\n \n pip install androidenv\n \n You can also copy the file androidenv.py to where you need it,\n it is self contained.\n \n \n ## Usage\n \n Build something from source:\n \n cd thing\n python -m androidenv setup.py build\n python -m androidenv setup.py install\n \n You really want to do this in a [virtual environment][venv].\n \n \n [venv]: https://docs.python.org/3/library/venv.html\n \n \n Use the --find-library option to find libraries like libandroid or liblog:\n \n python -m androidenv --find-library android log\n \n \n ## Environment variables\n \n This module works entirely with environment variables.\n \n Input environment variables:\n \n - ANDROID_SDK_ROOT or ANDROID_HOME (required);\n - ABI (optional; armeabi-v7a or arm64-v8a);\n - API (optional);\n - DEBUG (optional; 0 or 1);\n \n What is being built must respect the following evironment variables:\n \n - AR\n - AS\n - CC\n - CFLAGS\n - CPP\n - CPPFLAGS\n - CXX\n - CXXFLAGS\n - LD\n - LDFLAGS\n - PATH\n - RANLIB\n - READELF\n - STRIP\n \n Many packages do, many don't. Python itself (distutils) does not respect\n RANLIB; CMake does not respect CPPFLAGS; and many more. Fixing that is\n your homework.\n \n ### setup.cfg\n \n Some useful configuration options when building for Android:\n \n [build]\n build-base = build\n build-temp = build/tmp\n build-lib = build/lib\n ",
"bugtrack_url": null,
"license": "ISC",
"summary": "Build native packages for Android",
"version": "1.0",
"project_urls": {
"Homepage": "https://github.com/mansourmoufid/python-androidenv"
},
"split_keywords": [
"android"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4fc869533b74b74e5dda4d09d05803e353f6b3f73ef4c8b4d8ca76edb9c47ef2",
"md5": "42c74b67f668c16e1cd0fb9046b4111c",
"sha256": "e7a9677031f181f789f543a4cca61586684b52ee85bcd286ef8a2e271d95c620"
},
"downloads": -1,
"filename": "androidenv-1.0.tar.gz",
"has_sig": false,
"md5_digest": "42c74b67f668c16e1cd0fb9046b4111c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5789,
"upload_time": "2025-08-15T19:17:54",
"upload_time_iso_8601": "2025-08-15T19:17:54.773080Z",
"url": "https://files.pythonhosted.org/packages/4f/c8/69533b74b74e5dda4d09d05803e353f6b3f73ef4c8b4d8ca76edb9c47ef2/androidenv-1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-15 19:17:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mansourmoufid",
"github_project": "python-androidenv",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "androidenv"
}