kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.33k stars 1.84k forks source link

UnboundLocalError: local variable 'toolchain_version' referenced before assignment #2190

Closed AndreMiras closed 2 years ago

AndreMiras commented 4 years ago

Versions

Description

Building a the apps (in this case testapps/on_device_unit_tests) fails with a UnboundLocalError when the NDK directory doesn't exist.

Exact command used was:

python setup.py apk --sdk-dir ~/.buildozer/android/platform/android-sdk --ndk-dir ~/.buildozer/android/platform/android-ndk --requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,sqlite3,setuptools,numpy

Logs

python setup.py apk --sdk-dir ~/.buildozer/android/platform/android-sdk --ndk-dir ~/.buildozer/android/platform/android-ndk --requirements libffi,sdl2,pyjnius,kivy,python3,openssl,requests,sq
lite3,setuptools,numpy
found requirements
running apk
WARNING: You did not supply an Android package identifier, trying org.test.unit_tests_app instead.
         This may fail if this is not a valid identifier
Including test_app/app_flask.py
Including test_app/app_kivy.py
Including test_app/main.py
Including test_app/tools.py
Including test_app/widgets.py
Including test_app/constants.py
Including test_app/app_service.py
Including test_app/screen_service.kv
Including test_app/screen_unittests.kv
Including test_app/widgets.kv
Including test_app/screen_orientation.kv
Including test_app/screen_keyboard.kv
Including test_app/app_requirements.txt
Including test_app/static/colours.png
Including test_app/static/coloursinv.png
Including test_app/static/flask.css
Including test_app/static/Blanka-Regular.otf
Including test_app/templates/index.html
Including test_app/templates/page2.html
Including test_app/templates/base.html
Including test_app/templates/unittests.html
Including test_app/tests/__init__.py
Including test_app/tests/test_requirements.py
Including test_app/tests/mixin.py
[INFO]:    Will compile for the following archs: armeabi-v7a
[INFO]:    Getting Android API version from user argument: 27
[INFO]:    Available Android APIs are (27)
[INFO]:    Requested API target 27 is available, continuing.
[INFO]:    Getting NDK dir from from user argument
[INFO]:    Could not determine NDK version, no source.properties in the NDK dir.
[WARNING]: Unable to read the NDK version from the given directory /home/andre/.buildozer/android/platform/android-ndk.
[WARNING]: Make sure your NDK version is greater than 19. If you get build errors, download the recommended NDK 19c from https://developer.android.com/ndk/downloads/.
[INFO]:    Getting NDK API version (i.e. minimum supported API) from user argument
[INFO]:    ccache is missing, the build will not be optimized in the future.
/home/andre/workspace/python-for-android/venv/bin/python3: No module named cython
[WARNING]: Cython for python3 missing. If you are building for  a python 3 target (which is the default) then THINGS WILL BREAK.
[WARNING]: ndk_platform doesn't exist: /home/andre/.buildozer/android/platform/android-ndk/platforms/android-21/arch-arm
[WARNING]: Could not find toolchain subdirectory!
[WARNING]: Could not find any toolchain for arm-linux-androideabi!
Traceback (most recent call last):
  File "setup.py", line 79, in <module>
    setup(
  File "/usr/lib/python3.8/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.8/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.8/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/home/andre/workspace/python-for-android/pythonforandroid/bdistapk.py", line 79, in run
    main()
  File "/home/andre/workspace/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/andre/workspace/python-for-android/pythonforandroid/toolchain.py", line 688, in __init__
    getattr(self, command)(args)
  File "/home/andre/workspace/python-for-android/pythonforandroid/toolchain.py", line 144, in wrapper_func
    ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
  File "/home/andre/workspace/python-for-android/pythonforandroid/build.py", line 407, in prepare_build_environment
    self.toolchain_version = toolchain_version
UnboundLocalError: local variable 'toolchain_version' referenced before assignment

The fix is actually simple, but I would like it to be cover tested

tomatoes-prog commented 3 years ago

Sorry how did you solved the problem, I am currently having the same issue with the following logs


abe542@abe542-VirtualBox:~/Documents/KivyHelloWorld$ p4a aab --private . --package=org.example.myabb --name="My abb" --version=0.0.1 --bootstrap=sdl2 --requirements=hostpython3==3.7.5,python3==3.7.5,kivy==master --permission=INTERNET --sdk-dir=$HOME/Documents/android/sdk_new/ --android_api 29 --ndk-dir=/home/abe542/Documents/android/android-ndk-r20b-linux-x86_64/android-ndk-r20b --ndk-api 27 --arch=arm64-v8a --arch=armeabi-v7a --release
[INFO]:    Recipe hostpython3: version "3.7.5" requested
[INFO]:    Recipe python3: version "3.7.5" requested
[INFO]:    Recipe kivy: version "master" requested
[WARNING]: $ANDROIDNDKVER is deprecated and no longer necessary, the value you set is ignored
[INFO]:    Will compile for the following archs: arm64-v8a, armeabi-v7a
[INFO]:    Getting Android API version from user argument: 29
[INFO]:    Available Android APIs are (27, 29)
[INFO]:    Requested API target 29 is available, continuing.
[INFO]:    Getting NDK dir from from user argument
[INFO]:    Found NDK version 20b
[INFO]:    Getting NDK API version (i.e. minimum supported API) from user argument
[WARNING]: sysroot doesn't exist: /home/abe542/Documents/android/android-ndk-r20b-linux-x86_64/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/sysroot
[WARNING]: Could not find any toolchain for aarch64-linux-android!
Traceback (most recent call last):
  File "/home/abe542/.local/bin/p4a", line 8, in <module>
    sys.exit(main())
  File "/home/abe542/.local/lib/python3.7/site-packages/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/abe542/.local/lib/python3.7/site-packages/pythonforandroid/toolchain.py", line 728, in __init__
    getattr(self, command)(args)
  File "/home/abe542/.local/lib/python3.7/site-packages/pythonforandroid/toolchain.py", line 144, in wrapper_func
    user_ndk_api=self.ndk_api)
  File "/home/abe542/.local/lib/python3.7/site-packages/pythonforandroid/build.py", line 447, in prepare_build_environment
    self.sdk_dir, self.ndk_dir, arch, ndk_sysroot_exists, py_platform
  File "/home/abe542/.local/lib/python3.7/site-packages/pythonforandroid/build.py", line 90, in select_and_check_toolchain_version
    toolchain_version=toolchain_version,
UnboundLocalError: local variable 'toolchain_version' referenced before assignment

The command that i am running is

p4a aab --private . --package=org.example.myabb --name="My abb" --version=0.0.1 --bootstrap=sdl2 --requirements=hostpython3==3.7.5,python3==3.7.5,kivy==master --permission=INTERNET --sdk-dir=$HOME/Documents/android/sdk_new/ --android_api 29 --ndk-dir=/home/abe542/Documents/android/android-ndk-r20b-linux-x86_64/android-ndk-r20b --ndk-api 27 --arch=arm64-v8a --arch=armeabi-v7a --release

I know it is due the NDK and SDK configuration but, suspect it might be because of the arch parameters but I really dont know what i am doing wrong

rayzchen commented 2 years ago

2585 seems to be the same issue I'm having just on Termux. (Though GitHub actions also says the same thing)

rayzchen commented 2 years ago

Though the sdk dir and ndk dir are correct

misl6 commented 2 years ago

Closing as this has been silently fixed on our develop branch. Feel free to re-open if you're able to reproduce it on develop branch.

@rayzchen I will directly reply on #2585 about termux-related issue.