From 2d4d4dbdc8898bf1a355cf03764e46b33af7c11d Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 30 Nov 2025 06:17:08 +0000 Subject: [PATCH 1/3] android build: bump openssl (1.1.1w -> 3.0.18) --- contrib/android/Dockerfile | 4 ++-- contrib/android/p4a_recipes/openssl/__init__.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/android/Dockerfile b/contrib/android/Dockerfile index 74f53928e..b0efecc4a 100644 --- a/contrib/android/Dockerfile +++ b/contrib/android/Dockerfile @@ -207,8 +207,8 @@ RUN cd /opt \ && /opt/venv/bin/python3 -m pip install --no-build-isolation --no-dependencies -e . # install python-for-android -ENV P4A_CHECKOUT_COMMIT="003451604321deb1f10d879b63450ec76db4a758" -# ^ from branch electrum_20240930_android_16kb_page_alignment (note: careful with force-pushing! see #8162) +ENV P4A_CHECKOUT_COMMIT="e91310fbf88857b2fbd9f9a5f591300ae5da90b5" +# ^ from branch electrum_20251211 (note: careful with force-pushing! see #8162) RUN cd /opt \ && git clone https://github.com/spesmilo/python-for-android \ && cd python-for-android \ diff --git a/contrib/android/p4a_recipes/openssl/__init__.py b/contrib/android/p4a_recipes/openssl/__init__.py index 3746e8ccc..fdbb7d662 100644 --- a/contrib/android/p4a_recipes/openssl/__init__.py +++ b/contrib/android/p4a_recipes/openssl/__init__.py @@ -6,14 +6,14 @@ from pythonforandroid.util import load_source util = load_source('util', os.path.join(os.path.dirname(os.path.dirname(__file__)), 'util.py')) -assert OpenSSLRecipe._version == "1.1" +assert OpenSSLRecipe._version == "3.0.18" assert OpenSSLRecipe.depends == [] assert OpenSSLRecipe.python_depends == [] class OpenSSLRecipePinned(util.InheritedRecipeMixin, OpenSSLRecipe): - url_version = "1.1.1w" - sha512sum = "b4c625fe56a4e690b57b6a011a225ad0cb3af54bd8fb67af77b5eceac55cc7191291d96a660c5b568a08a2fbf62b4612818e7cca1bb95b2b6b4fc649b0552b6d" + version = "3.0.18" + sha512sum = "6bdd16f33b83ae2a12777230c4ff00d0595bbc00253ac8c3ac31e1375e818fc74d7f491bd2e507ff33cab9f0498cfb28fa8690f75a98663568d40901523cdf3c" recipe = OpenSSLRecipePinned() From cfa052bc86fdb3c5dd26dae0a17d2eb686ab385f Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 30 Nov 2025 06:19:30 +0000 Subject: [PATCH 2/3] android build: switch from "cryptography" to "pycryptodomex" We had been using an ancient version of "cryptography" so far in our p4a fork, however it is not compatible with OpenSSL 3.0. (Previously we were building it with OpenSSL 1.1) Bumping "cryptography" is difficult, as building new versions of it from source requires a full rust toolchain. Instead, this commit switches to "pycryptodomex", as a replacement, which is much easier to build from source. --- contrib/android/buildozer_qml.spec | 2 +- .../android/p4a_recipes/pycryptodomex/__init__.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 contrib/android/p4a_recipes/pycryptodomex/__init__.py diff --git a/contrib/android/buildozer_qml.spec b/contrib/android/buildozer_qml.spec index e19bcac5a..75328a51e 100644 --- a/contrib/android/buildozer_qml.spec +++ b/contrib/android/buildozer_qml.spec @@ -76,7 +76,7 @@ requirements = plyer, libffi, libsecp256k1, - cryptography, + pycryptodomex, pyqt6sip, pyqt6, libzbar diff --git a/contrib/android/p4a_recipes/pycryptodomex/__init__.py b/contrib/android/p4a_recipes/pycryptodomex/__init__.py new file mode 100644 index 000000000..0e0a580bf --- /dev/null +++ b/contrib/android/p4a_recipes/pycryptodomex/__init__.py @@ -0,0 +1,15 @@ +from pythonforandroid.recipe import PythonRecipe + + +assert PythonRecipe.depends == ['python3'] +assert PythonRecipe.python_depends == [] + + +class PycryptodomexRecipe(PythonRecipe): + version = "3.23.0" + sha512sum = "951cebaad2e19b9f9d04fe85c73ab1ff8b515069c1e0e8e3cd6845ec9ccd5ef3e5737259e0934ed4a6536e289dee6aabac58e1c822a5a6393e86b482c60afc89" + url = "https://github.com/Legrandin/pycryptodome/archive/v{version}x.tar.gz" + depends = ["setuptools", "cffi"] + + +recipe = PycryptodomexRecipe() From 5b67f21bc4be20b6006c60065285e071ac8161e3 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 30 Nov 2025 05:57:03 +0000 Subject: [PATCH 3/3] android: add run-time patch to make pycryptodomex work to work around https://github.com/kivy/python-for-android/issues/1866 : > PyCryptodome >=3.6.0 crashes at runtime (since commit https://github.com/Legrandin/pycryptodome/commit/f5aa2c1618e97b6d773172fdd07794a0a6f05905). So actually the currently pinned version in the recipe does not work: > https://github.com/kivy/python-for-android/blob/80e4f059c1ee0da48a7c85167087dfe5928ac395/pythonforandroid/recipes/pycryptodome/__init__.py#L5 > > The issue at runtime is with ctypes. > > > Say I have a main script that just does the following (https://github.com/Legrandin/pycryptodome/blob/95ccce7ae82d3a36f1a8652dd2c645222d0128dd/lib/Crypto/Util/_raw_api.py#L200): > ``` > import ctypes > ctypes.pythonapi.PyObject_GetBuffer > ``` > > This works with cpython on my laptop, but with the p4a-compiled python on Android it fails: > > ``` > 06-14 19:06:27.053 15246 15274 I python : Android kivy bootstrap done. __name__ is __main__ > 06-14 19:06:27.053 15246 15274 I python : AND: Ran string > 06-14 19:06:27.053 15246 15274 I python : Run user program, change dir and execute entrypoint > 06-14 19:06:27.092 15246 15274 I python : Traceback (most recent call last): > 06-14 19:06:27.092 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/app/main.py", line 84, in > 06-14 19:06:27.093 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/__init__.py", line 369, in __getattr__ > 06-14 19:06:27.093 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/__init__.py", line 374, in __getitem__ > 06-14 19:06:27.094 15246 15274 I python : AttributeError: undefined symbol: PyObject_GetBuffer > ``` > > I have also tried to access some other attributes of `ctypes.pythonapi`, such as `Py_IncRef`, which raises the same exception. --- Unclear if the issue still affects newer p4a: upstream seems to think it's fixed, but there multiple comments in the thread saying otherwise. Anyway, rebasing p4a has other blockers atm. --- run_electrum | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/run_electrum b/run_electrum index e9b3ab865..3d75478c5 100755 --- a/run_electrum +++ b/run_electrum @@ -100,6 +100,13 @@ if not is_android: check_imports() +if is_android: + # hack to make pycryptodomex work on Android + # from https://github.com/kivy/python-for-android/issues/1866#issuecomment-927157780 + import ctypes + ctypes.pythonapi = ctypes.PyDLL("libpython%d.%d.so" % sys.version_info[:2]) # replaces ctypes.PyDLL(None) + + sys._ELECTRUM_RUNNING_VIA_RUNELECTRUM = True # used by logging.py from electrum.logging import get_logger, configure_logging # import logging submodule first