Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Termux build fails #2585

Closed
3 of 5 tasks
rayzchen opened this issue Apr 20, 2022 · 8 comments
Closed
3 of 5 tasks

Termux build fails #2585

rayzchen opened this issue Apr 20, 2022 · 8 comments

Comments

@rayzchen
Copy link

rayzchen commented Apr 20, 2022

Checklist

  • the issue is indeed a bug and not a support request
  • issue doesn't already exist: https://github.com/kivy/python-for-android/issues
  • I have a short, runnable example that reproduces the issue
  • I reproduced the problem with the latest development version (p4a.branch = develop)
  • I used the grave accent (aka backticks) to format code or logs when appropriated

Versions

  • Python: 3.9
  • OS: Termux
  • Kivy: Not used
  • Cython: 0.29.28
  • OpenJDK: 1.8.0

Description

I am trying to use Termux to build a PySDL2 app, but python-for-android doesn't seem to find a certain toolchain.

buildozer.spec

not used

Spec file:

not used

Commands

Fresh copy of termux
Use Andronix to install Ubuntu 20.04
Command: curl https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/repo-fix.sh > repo.sh && chmod +x repo.sh && bash repo.sh && pkg update -y && pkg install wget curl proot tar -y && wget https://raw.githubusercontent.com/AndronixApp/AndronixOrigin/master/Installer/Ubuntu20/ubuntu20.sh -O ubuntu20.sh && chmod +x ubuntu20.sh && bash ubuntu20.sh

Run these commands inside proot:

apt-get update
apt-get install vim -y
vim main.py
# Add python code

apt-get install software-properties-common -y
add-apt-repository ppa:deadsnakes/ppa -y
apt-get install python3.9 python3-pip -y
pip install python-for-android pysdl2 pysdl2-dll cython

apt-get install wget curl unzip make openjdk-8-jdk -y
wget https://raw.githubusercontent.com/kivy/python-for-android/develop/ci/makefiles/android.mk
make -f android.mk

export ANDROIDSDK=/root/.android/android-sdk
export ANDROIDNDK=/root/.android/android-ndk
export ANDROIDAPI=27
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64/

dpkg --add-architecture i386
apt-get update
apt-get install -y build-essential ccache git zlib1g-dev python3 python3-dev libncurses5:i386 libstdc++6:i386 zlib1g:i386 openjdk-8-jdk unzip ant ccache autoconf libtool libssl-dev

p4a apk --private . --package=org.example.test --name "My application" --version 0.1 --bootstrap=sdl2 --requirements=python3,pysdl2 --arch arm64-v8a

Some i386 installs don't work

In current directory I have main.py:

import sdl2.ext
sdl2.ext.init()
window = sdl2.ext.Window("Hello World!", size=(640, 480))
window.show()
processor = sdl2.ext.TestEventProcessor()
processor.run(window)
sdl2.ext.quit()

Logs

root@localhost:~/p4a# p4a apk --private . --package=org.example.test --name "My application" --version 0.1 --bootstrap=sdl2 --requirements=python3,pysdl2 --arch arm64-v8a
[INFO]:    Will compile for the following archs: arm64-v8a
[INFO]:    Found Android API target in $ANDROIDAPI: 27
[INFO]:    Available Android APIs are (27)
[INFO]:    Requested API target 27 is available, continuing.
[INFO]:    Found NDK dir in $ANDROIDNDK: /root/.android/android-ndk
[INFO]:    Found NDK version 23b
[WARNING]: Maximum recommended NDK version is 19c, but newer versions may work.
[WARNING]: Newer NDKs may not be fully supported by p4a.
[WARNING]: NDK API target was not set manually, using the default of 21 = min(android-api=27, default ndk-api=21)
[INFO]:    ccache is missing, the build will not be optimized in the future.
[WARNING]: sysroot doesn't exist: /root/.android/android-ndk/toolchains/llvm/prebuilt/linux-aarch64/sysroot
[WARNING]: Could not find any toolchain for aarch64-linux-android!
Traceback (most recent call last):
  File "/usr/local/bin/p4a", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/usr/local/lib/python3.8/dist-packages/pythonforandroid/toolchain.py", line 728, in __init__
    getattr(self, command)(args)
  File "/usr/local/lib/python3.8/dist-packages/pythonforandroid/toolchain.py", line 141, in wrapper_func
    ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
  File "/usr/local/lib/python3.8/dist-packages/pythonforandroid/build.py", line 446, in prepare_build_environment
    self.toolchain_version = select_and_check_toolchain_version(
  File "/usr/local/lib/python3.8/dist-packages/pythonforandroid/build.py", line 90, in select_and_check_toolchain_version
    toolchain_version=toolchain_version,
UnboundLocalError: local variable 'toolchain_version' referenced before assignment
@kengoon
Copy link
Contributor

kengoon commented Apr 21, 2022

@rayzchen How did you get to install Android SDK and NDK

@rayzchen
Copy link
Author

apt-get install wget curl unzip make openjdk-8-jdk -y
wget https://raw.githubusercontent.com/kivy/python-for-android/develop/ci/makefiles/android.mk
make -f android.mk

This downloads the makefile in ci/makefiles/android.mk and runs it, which downloads both the NDK and SDK and sets them up in /root/.android/

@kengoon
Copy link
Contributor

kengoon commented Apr 26, 2022 via email

@kengoon
Copy link
Contributor

kengoon commented Apr 26, 2022

@rayzchen just read the content of the file and I discovered that the NDK and SDK version it installed is for x86_64 bit archs and not aarch64. Which simply means p4a is not supported on android phones with armeabi-v7a and aarch64

@rayzchen rayzchen reopened this May 26, 2022
@rayzchen
Copy link
Author

Ran same steps on a GitHub codespace yet it still tries to find toolchain for "aarch64-linux-android"

platform.platform() is 'Linux-5.4.0-1074-azure-x86_64-with-glibc2.31'

@rayzchen
Copy link
Author

Why does p4a say I have to specify an arch when the quick start doesn't?

@misl6
Copy link
Member

misl6 commented Jun 5, 2022

python-for-android should run on a instance that also Google supports with the build tools for Android. (Linux x86_64, macOS x86_64, macOS Apple Silicon).

This statement doesn't mean that you can't build for aarch64-linux-android if you're on a x64_64 machine as all the builds for Android are cross-compiled (I'm referring to: "just read the content of the file and I discovered that the NDK and SDK version it installed is for x86_64 bit archs and not aarch64. Which simply means p4a is not supported on android phones with armeabi-v7a and aarch64") .

@rayzchen I've seen you're using the stable version of python-for-android (the latest one available on PyPi), but you're also taking advantage of the android.mk file from develop branch: https://raw.githubusercontent.com/kivy/python-for-android/develop/ci/makefiles/android.mk, which installs the NDK required by the develop branch, not the master one, which is incompatible.

Please let me know if using wget https://raw.githubusercontent.com/kivy/python-for-android/master/ci/makefiles/android.mk instead of wget https://raw.githubusercontent.com/kivy/python-for-android/develop/ci/makefiles/android.mk fixes your issue.

@rayzchen
Copy link
Author

rayzchen commented Jun 5, 2022

It seems to be fixed! Thanks for the help.

@rayzchen rayzchen closed this as completed Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants