Skip to content

Commit 59cc895

Browse files
committed
[ndk] Make it raise an error if an old ndk is used
In order to avoid issues with old android's NDKs, we force to raise an error in case that an NDK version lower than the specified is detected. We also add the ability to extract the android's NDK letter version, which for now, will only be used to inform the user of the version which is using
1 parent 6f99407 commit 59cc895

File tree

1 file changed

+64
-12
lines changed

1 file changed

+64
-12
lines changed

pythonforandroid/recommendations.py

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,84 @@
66
from pythonforandroid.util import BuildInterruptingException
77

88
# We only check the NDK major version
9-
MIN_NDK_VERSION = 17
10-
MAX_NDK_VERSION = 17
9+
MIN_NDK_VERSION = 19
10+
MAX_NDK_VERSION = 19
1111

12-
RECOMMENDED_NDK_VERSION = '17c'
13-
OLD_NDK_MESSAGE = 'Older NDKs may not be compatible with all p4a features.'
12+
RECOMMENDED_NDK_VERSION = '19b'
1413
NEW_NDK_MESSAGE = 'Newer NDKs may not be fully supported by p4a.'
14+
NDK_DOWNLOAD_URL = 'https://developer.android.com/ndk/downloads/'
1515

1616

1717
def check_ndk_version(ndk_dir):
18-
# Check the NDK version against what is currently recommended
18+
"""
19+
Check the NDK version against what is currently recommended and raise an
20+
exception of :class:`~pythonforandroid.util.BuildInterruptingException` in
21+
case that the user tries to use an NDK lower than minimum supported,
22+
specified via attribute `MIN_NDK_VERSION`.
23+
24+
.. versionchanged:: 2019.06.06.1.dev0
25+
Added the ability to get android's ndk `letter version` and also
26+
rewrote to raise an exception in case that an NDK version lower than
27+
the minimum supported is detected.
28+
"""
1929
version = read_ndk_version(ndk_dir)
2030

2131
if version is None:
22-
return # if we failed to read the version, just don't worry about it
32+
warning(
33+
'Unable to read the ndk version, assuming that you are using an'
34+
' NDK greater than {min_supported} (the minimum ndk required to'
35+
' use p4a successfully).\n'
36+
'Note: If you got build errors, consider to download the'
37+
' recommended ndk version which is {rec_version} and try'
38+
' it again (after removing all the files generated with this'
39+
' build). To download the android NDK visit the following page: '
40+
'{ndk_url}'.format(
41+
min_supported=MIN_NDK_VERSION,
42+
rec_version=RECOMMENDED_NDK_VERSION,
43+
ndk_url=NDK_DOWNLOAD_URL,
44+
)
45+
)
46+
return
47+
48+
# create a dictionary which will describe the relationship of the android's
49+
# ndk minor version with the `human readable` letter version, egs:
50+
# Pkg.Revision = 17.1.4828580 => ndk-17b
51+
# Pkg.Revision = 17.2.4988734 => ndk-17c
52+
# Pkg.Revision = 19.0.5232133 => ndk-19 (No letter)
53+
minor_to_letter = {0: ''}
54+
minor_to_letter.update(
55+
{n + 1: chr(i) for n, i in enumerate(range(ord('b'), ord('b') + 25))}
56+
)
2357

2458
major_version = version.version[0]
59+
letter_version = minor_to_letter[version.version[1]]
60+
string_version = '{major_version}{letter_version}'.format(
61+
major_version=major_version, letter_version=letter_version
62+
)
2563

26-
info('Found NDK revision {}'.format(version))
64+
info('Found NDK version {}'.format(string_version))
2765

2866
if major_version < MIN_NDK_VERSION:
29-
warning('Minimum recommended NDK version is {}'.format(
30-
RECOMMENDED_NDK_VERSION))
31-
warning(OLD_NDK_MESSAGE)
67+
raise BuildInterruptingException(
68+
'Unsupported NDK version detected {user_version}\n'
69+
'* Note: Minimum supported NDK version is {min_supported}'.format(
70+
user_version=string_version, min_supported=MIN_NDK_VERSION
71+
),
72+
instructions=(
73+
'Please, go to the android ndk page ({ndk_url}) and download a'
74+
' supported version.\n*** The currently recommended NDK'
75+
' version is {rec_version} ***'.format(
76+
ndk_url=NDK_DOWNLOAD_URL,
77+
rec_version=RECOMMENDED_NDK_VERSION,
78+
)
79+
),
80+
)
3281
elif major_version > MAX_NDK_VERSION:
33-
warning('Maximum recommended NDK version is {}'.format(
34-
RECOMMENDED_NDK_VERSION))
82+
warning(
83+
'Maximum recommended NDK version is {}'.format(
84+
RECOMMENDED_NDK_VERSION
85+
)
86+
)
3587
warning(NEW_NDK_MESSAGE)
3688

3789

0 commit comments

Comments
 (0)