pythonforandroid UnboundLocalError: local variable 'toolchain_version' referenced before assignment

332 views
Skip to first unread message

Abstract Donut

unread,
Dec 19, 2019, 11:45:24 PM12/19/19
to Kivy users support
Hi, I'm struggling to get p4a up and running, but I'm stumped with this error. Any help appreciated.

user:~/python/kivy/exercises/countdown$ p4a apk --debug --package=org.exampe.countdown --name "Count Down" --version 0.1 --bootstrap=sdl2 --requirements=python3,kivy
[INFO]:    Will compile for the following archs: armeabi-v7a
[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: /home/user/android/android-ndk-r17c/
[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/user/android/android-ndk-r17c/
[WARNING]: Make sure your NDK version is greater than 17. If you get build errors, download the recommended NDK 17c from https://developer.android.com/ndk/downloads/
[INFO]:    Found Android API target in $NDKAPI
[WARNING]: NDK API less than 21 is not supported
[INFO]:    Found virtualenv at /home/user/.local/bin/virtualenv
[WARNING]: ndk_platform doesn't exist: /home/user/android/android-ndk-r17c/platforms/android-19/arch-arm
[WARNING]: Could not find any toolchain for arm-linux-androideabi!
Traceback (most recent call last):
  File "/home/user/.local/bin/p4a", line 11, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/toolchain.py", line 668, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/toolchain.py", line 146, in wrapper_func
    user_ndk_api=self.ndk_api)
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/build.py", line 410, in prepare_build_environment
    self.toolchain_version = toolchain_version
UnboundLocalError: local variable 'toolchain_version' referenced before assignment

Message has been deleted

Robert Flatt

unread,
Dec 20, 2019, 12:47:16 PM12/20/19
to Kivy users support
The issue is probably earlier, perhaps the warnings 'unable to read NDK version'
So an install of 17c issue?

Here are some very old instructions for installing p4a, including NDK and SDK
and some updates

Abstract Donut

unread,
Dec 29, 2019, 5:10:48 PM12/29/19
to Kivy users support
Sorry to have ignored my own thread for so long. I think you are right about the NDK being installed incorrectly. I downloaded and unzipped the NDK from https://developer.android.com/ndk/downloads/older_releases but it doesn't have any platforms subdirectory or needed toolchains. Here's some screenshots from my file viewer.



I think I'm just misunderstanding how the NDK installation works. Can you tell what mistake I'm making from looking at this?

Robert Flatt

unread,
Dec 29, 2019, 7:11:38 PM12/29/19
to Kivy users support
[INFO]:    Found NDK dir in $ANDROIDNDK: /home/user/android/android-ndk-r17c/
[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/user/android/android-ndk-r17c/
 
I read this as saying there is an NDK install issue.
There is an error finding "source.properties" which is a file in the root level in the NDK directory.
And I do not see this file in your screen shot (there are several other things missing too).

I have no way to know why the NDK unzip is apparently corrupted.

My (r17c) NDK dir looks like (note: contains "source.properties") :

~>ls /home/bobf/androidtools/android-ndk-r17c
CHANGELOG
.md  ndk-build    ndk-which        shader-tools       sysroot
README
.md     ndk-depends  platforms        simpleperf         toolchains
build         ndk
-gdb      prebuilt         source.properties  wrap.sh
meta          ndk
-stack    python-packages  sources

So for you (after renaming existing dir) assuming /home/android contains android-ndk-r17c-linux-x86_64.zip
cd /home/android
unzip
-q android-ndk-r17c-linux-x86_64.zip

FYI To use this my .p4a contains in part:
--ndk_dir /home/bobf/androidtools/android-ndk-r17c
 One can also specify the location with $ANDROIDNDK, in place of using .p4a , the string values are the same.


And FYI when you update to python-for-android (2019.10.6) the minimum NDK version will be r19b  (I'm using r19c which seems to work)

Abstract Donut

unread,
Dec 29, 2019, 7:54:59 PM12/29/19
to Kivy users support
I didn't realize my unzip was different from the contents of the zip archive, I unzipped again and now the files seem to be there. Here are new screenshots.



I thought that would fix it but p4a creates the same warnings.

$ p4a apk
[INFO]:    Reading .p4a configuration
[WARNING]: --ndk-version is deprecated and no longer necessary, the value you passed is ignored

[INFO]:    Will compile for the following archs: armeabi-v7a
[INFO]:    Getting Android API version from user argument: 28
[INFO]:    Available Android APIs are (27, 28)
[INFO]:    Requested API target 28 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/user/android-ndk-r17c/

[WARNING]: Make sure your NDK version is greater than 17. If you get build errors, download the recommended NDK 17c from https://developer.android.com/ndk/downloads/
[INFO]:    Getting NDK API version (i.e. minimum supported API) from user argument

[INFO]:    Found virtualenv at /home/user/.local/bin/virtualenv
[WARNING]: ndk_platform doesn't exist: /home/user/android-ndk-r17c/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 "/home/user/.local/bin/p4a", line 11, in <module>
    sys.exit(main())
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/toolchain.py", line 668, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/toolchain.py", line 146, in wrapper_func
    user_ndk_api=self.ndk_api)
  File "/home/user/.local/lib/python3.6/site-packages/pythonforandroid/build.py", line 410, in prepare_build_environment
    self.toolchain_version = toolchain_version
UnboundLocalError: local variable 'toolchain_version' referenced before assignment

Abstract Donut

unread,
Dec 29, 2019, 7:58:06 PM12/29/19
to Kivy users support
Sorry, forgot to add, this is the .p4a adapted from the link you provided.
--dist_name=countdown
--private .
--package=com.user.countdown
--name "Count Down"
--bootstrap=sdl2
--requirements=python3,kivy
--arch=armeabi-v7a
--sdk_dir /home/user/android/
--ndk_dir /home/user/android-ndk-r17c/
--android_api 28
--ndk_version 17c
--ndk-api 21
--version <0.0.0>

Robert Flatt

unread,
Dec 29, 2019, 10:40:43 PM12/29/19
to Kivy users support
Well it is still an install issue, something is different from other installs but I can't see what (but I couldn't imagine how an unzip could be corrupted either - so that is my limitation). Are you certain there was no other file manipulation other than unzip?
 
Is it Linux permissions related? Are you logged on as "android" when you do this and not using "sudo" ?   (just guessing, I got nothing)

One thing to try is start again but use different directory names, for everything.
Not because the names are wrong, but because changing stuff may highlight or bypass the issue.

Btw later remove the <> from this line "--version <0.0.0>"

Abstract Donut

unread,
Dec 30, 2019, 12:39:53 AM12/30/19
to Kivy users support
Should I be using sudo for something in particular? I've done everything so far from my own default user.

Robert Flatt

unread,
Dec 30, 2019, 12:32:14 PM12/30/19
to Kivy users support
Some times people use sudo for the wrong reason, just checking.

Abstract Donut

unread,
Dec 30, 2019, 7:26:34 PM12/30/19
to Kivy users support
I just figured out that your initial solution was correct, the corrupted NDK was the reason for my problems. The error I received after fixing the NDK was only a problem with the new .p4a file, but it is working now. Thank you so much for the help!

Abstract Donut

unread,
Dec 30, 2019, 7:27:35 PM12/30/19
to Kivy users support
Also, your point about the brackets helped me, I wouldn't have noticed or figured that out myself, at least not quickly,

Robert Flatt

unread,
Dec 30, 2019, 9:26:02 PM12/30/19
to Kivy users support
Great news
Reply all
Reply to author
Forward
0 new messages