Skip to content

Commit f7f8cea

Browse files
authored
NDK 23 + Gradle 7 support (#2550)
* Adds NDK 23 and Gradle 7 support * Updates gradle and android gradle plugin version + avoid using a deprecated property * Cleanup + fix some broken recipes * Cleanup + icu now seems that is not needing stl_shared anymore * Updates docs and MIN_NDK_VERSION (MAX_NDK_VERSION could be 24, but needs to be tested)
1 parent a0f8d3e commit f7f8cea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+153
-370
lines changed

ci/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class TargetPython(Enum):
3232
'zope_interface',
3333
# Requires zope_interface, which is broken.
3434
'twisted',
35+
# genericndkbuild is incompatible with sdl2 (which is build by default when targeting sdl2 bootstrap)
36+
'genericndkbuild',
3537
])
3638

3739
BROKEN_RECIPES = {

ci/makefiles/android.mk

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Downloads and installs the Android SDK depending on supplied platform: darwin or linux
22

33
# Those android NDK/SDK variables can be override when running the file
4-
ANDROID_NDK_VERSION ?= 19b
4+
ANDROID_NDK_VERSION ?= 23b
55
ANDROID_SDK_TOOLS_VERSION ?= 6514223
66
ANDROID_SDK_BUILD_TOOLS_VERSION ?= 29.0.3
77
ANDROID_HOME ?= $(HOME)/.android
@@ -22,7 +22,7 @@ ANDROID_SDK_TOOLS_DL_URL=https://dl.google.com/android/repository/$(ANDROID_SDK_
2222

2323
ANDROID_NDK_HOME=$(ANDROID_HOME)/android-ndk
2424
ANDROID_NDK_FOLDER=$(ANDROID_HOME)/android-ndk-r$(ANDROID_NDK_VERSION)
25-
ANDROID_NDK_ARCHIVE=android-ndk-r$(ANDROID_NDK_VERSION)-$(TARGET_OS)-x86_64.zip
25+
ANDROID_NDK_ARCHIVE=android-ndk-r$(ANDROID_NDK_VERSION)-$(TARGET_OS).zip
2626
ANDROID_NDK_DL_URL=https://dl.google.com/android/repository/$(ANDROID_NDK_ARCHIVE)
2727

2828
$(info Target install OS is : $(target_os))
@@ -59,7 +59,7 @@ extract_android_sdk:
5959
extract_android_ndk:
6060
mkdir -p $(ANDROID_NDK_FOLDER) \
6161
&& unzip -q $(ANDROID_NDK_ARCHIVE) -d $(ANDROID_HOME) \
62-
&& ln -sfn $(ANDROID_NDK_FOLDER) $(ANDROID_NDK_HOME) \
62+
&& mv $(ANDROID_NDK_FOLDER) $(ANDROID_NDK_HOME) \
6363
&& rm -f $(ANDROID_NDK_ARCHIVE)
6464

6565
# updates Android SDK, install Android API, Build Tools and accept licenses

doc/source/quickstart.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ named ``tools``, and you will need to run extra commands to install
120120
the SDK packages needed.
121121

122122
For Android NDK, note that modern releases will only work on a 64-bit
123-
operating system. **The minimal, and recommended, NDK version to use is r19b:**
123+
operating system. **The minimal, and recommended, NDK version to use is r23b:**
124124

125125
- `Go to ndk downloads page <https://developer.android.com/ndk/downloads/>`_
126126
- Windows users should create a virtual machine with an GNU Linux os
@@ -154,7 +154,7 @@ variables necessary for building on android::
154154

155155
# Adjust the paths!
156156
export ANDROIDSDK="$HOME/Documents/android-sdk-27"
157-
export ANDROIDNDK="$HOME/Documents/android-ndk-r19b"
157+
export ANDROIDNDK="$HOME/Documents/android-ndk-r23b"
158158
export ANDROIDAPI="27" # Target API version of your application
159159
export NDKAPI="21" # Minimum supported API version of your application
160160
export ANDROIDNDKVER="r10e" # Version of the NDK you installed

pythonforandroid/archs.py

+14-53
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
from distutils.spawn import find_executable
22
from os import environ
3-
from os.path import join, split, exists
3+
from os.path import join
44
from multiprocessing import cpu_count
5-
from glob import glob
65

7-
from pythonforandroid.logger import warning
86
from pythonforandroid.recipe import Recipe
97
from pythonforandroid.util import BuildInterruptingException, build_platform
108

119

1210
class Arch:
1311

14-
toolchain_prefix = None
15-
'''The prefix for the toolchain dir in the NDK.'''
16-
1712
command_prefix = None
1813
'''The prefix for NDK commands such as gcc.'''
1914

@@ -30,8 +25,7 @@ class Arch:
3025

3126
common_cppflags = [
3227
'-DANDROID',
33-
'-D__ANDROID_API__={ctx.ndk_api}',
34-
'-I{ctx.ndk_sysroot}/usr/include/{command_prefix}',
28+
'-I{ctx.ndk_sysroot}/usr/include',
3529
'-I{python_includes}',
3630
]
3731

@@ -62,20 +56,6 @@ def __str__(self):
6256
def ndk_lib_dir(self):
6357
return join(self.ctx.ndk_sysroot, 'usr', 'lib', self.command_prefix, str(self.ctx.ndk_api))
6458

65-
@property
66-
def ndk_platform(self):
67-
warning("ndk_platform is deprecated and should be avoided in new recipes")
68-
ndk_platform = join(
69-
self.ctx.ndk_dir,
70-
'platforms',
71-
'android-{}'.format(self.ctx.ndk_api),
72-
self.platform_dir)
73-
if not exists(ndk_platform):
74-
BuildInterruptingException(
75-
"The requested platform folder doesn't exist. If you're building on ndk >= r22, and seeing this error, one of the required recipe is using a removed feature."
76-
)
77-
return ndk_platform
78-
7959
@property
8060
def include_dirs(self):
8161
return [
@@ -97,13 +77,10 @@ def target(self):
9777
@property
9878
def clang_path(self):
9979
"""Full path of the clang compiler"""
100-
llvm_dirname = split(
101-
glob(join(self.ctx.ndk_dir, 'toolchains', 'llvm*'))[-1]
102-
)[-1]
10380
return join(
10481
self.ctx.ndk_dir,
10582
'toolchains',
106-
llvm_dirname,
83+
'llvm',
10784
'prebuilt',
10885
build_platform,
10986
'bin',
@@ -190,12 +167,10 @@ def get_env(self, with_flags_in_cc=True):
190167
)
191168

192169
# Compiler: `CC` and `CXX` (and make sure that the compiler exists)
193-
environ['PATH'] = '{clang_path}:{path}'.format(
194-
clang_path=self.clang_path, path=environ['PATH']
195-
)
196-
cc = find_executable(self.clang_exe, path=environ['PATH'])
170+
env['PATH'] = self.ctx.env['PATH']
171+
cc = find_executable(self.clang_exe, path=env['PATH'])
197172
if cc is None:
198-
print('Searching path are: {!r}'.format(environ['PATH']))
173+
print('Searching path are: {!r}'.format(env['PATH']))
199174
raise BuildInterruptingException(
200175
'Couldn\'t find executable for CC. This indicates a '
201176
'problem locating the {} executable in the Android '
@@ -219,21 +194,18 @@ def get_env(self, with_flags_in_cc=True):
219194
execxx=self.clang_exe_cxx,
220195
ccache=ccache)
221196

222-
# Android's binaries
223-
command_prefix = self.command_prefix
224-
env['AR'] = '{}-ar'.format(command_prefix)
225-
env['RANLIB'] = '{}-ranlib'.format(command_prefix)
226-
env['STRIP'] = '{}-strip --strip-unneeded'.format(command_prefix)
197+
# Android's LLVM binutils
198+
env['AR'] = f'{self.clang_path}/llvm-ar'
199+
env['RANLIB'] = f'{self.clang_path}/llvm-ranlib'
200+
env['STRIP'] = f'{self.clang_path}/llvm-strip --strip-unneeded'
201+
env['READELF'] = f'{self.clang_path}/llvm-readelf'
202+
env['OBJCOPY'] = f'{self.clang_path}/llvm-objcopy'
203+
227204
env['MAKE'] = 'make -j{}'.format(str(cpu_count()))
228-
env['READELF'] = '{}-readelf'.format(command_prefix)
229-
env['NM'] = '{}-nm'.format(command_prefix)
230-
env['LD'] = '{}-ld'.format(command_prefix)
231205

232206
# Android's arch/toolchain
233207
env['ARCH'] = self.arch
234208
env['NDK_API'] = 'android-{}'.format(str(self.ctx.ndk_api))
235-
env['TOOLCHAIN_PREFIX'] = self.toolchain_prefix
236-
env['TOOLCHAIN_VERSION'] = self.ctx.toolchain_version
237209

238210
# Custom linker options
239211
env['LDSHARED'] = env['CC'] + ' ' + ' '.join(self.common_ldshared)
@@ -251,8 +223,6 @@ def get_env(self, with_flags_in_cc=True):
251223
),
252224
)
253225

254-
env['PATH'] = environ['PATH']
255-
256226
# for reproducible builds
257227
if 'SOURCE_DATE_EPOCH' in environ:
258228
for k in 'LC_ALL TZ SOURCE_DATE_EPOCH PYTHONHASHSEED BUILD_DATE BUILD_TIME'.split():
@@ -264,9 +234,7 @@ def get_env(self, with_flags_in_cc=True):
264234

265235
class ArchARM(Arch):
266236
arch = "armeabi"
267-
toolchain_prefix = 'arm-linux-androideabi'
268237
command_prefix = 'arm-linux-androideabi'
269-
platform_dir = 'arch-arm'
270238

271239
@property
272240
def target(self):
@@ -290,12 +258,9 @@ class ArchARMv7_a(ArchARM):
290258

291259
class Archx86(Arch):
292260
arch = 'x86'
293-
toolchain_prefix = 'x86'
294261
command_prefix = 'i686-linux-android'
295-
platform_dir = 'arch-x86'
296262
arch_cflags = [
297263
'-march=i686',
298-
'-mtune=intel',
299264
'-mssse3',
300265
'-mfpmath=sse',
301266
'-m32',
@@ -304,26 +269,22 @@ class Archx86(Arch):
304269

305270
class Archx86_64(Arch):
306271
arch = 'x86_64'
307-
toolchain_prefix = 'x86_64'
308272
command_prefix = 'x86_64-linux-android'
309-
platform_dir = 'arch-x86_64'
310273
arch_cflags = [
311274
'-march=x86-64',
312275
'-msse4.2',
313276
'-mpopcnt',
314277
'-m64',
315-
'-mtune=intel',
316278
'-fPIC',
317279
]
318280

319281

320282
class ArchAarch_64(Arch):
321283
arch = 'arm64-v8a'
322-
toolchain_prefix = 'aarch64-linux-android'
323284
command_prefix = 'aarch64-linux-android'
324-
platform_dir = 'arch-arm64'
325285
arch_cflags = [
326286
'-march=armv8-a',
287+
'-fPIC'
327288
# '-I' + join(dirname(__file__), 'includes', 'arm64-v8a'),
328289
]
329290

pythonforandroid/bootstraps/common/build/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip

pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.5.4'
8+
classpath 'com.android.tools.build:gradle:7.1.2'
99
}
1010
}
1111

@@ -41,6 +41,9 @@ android {
4141

4242

4343
packagingOptions {
44+
jniLibs {
45+
useLegacyPackaging = true
46+
}
4447
{% if debug_build -%}
4548
doNotStrip '**/*.so'
4649
{% else %}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{% if args.enable_androidx %}
22
android.useAndroidX=true
33
android.enableJetifier=true
4-
{% endif %}
5-
android.bundle.enableUncompressedNativeLibs=false
4+
{% endif %}

pythonforandroid/bootstraps/sdl2/build/templates/AndroidManifest.tmpl.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
{{ args.extra_manifest_application_arguments }}
6363
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
6464
android:hardwareAccelerated="true"
65-
>
65+
android:extractNativeLibs="true" >
6666
{% for l in args.android_used_libs %}
6767
<uses-library android:name="{{ l }}" />
6868
{% endfor %}

pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
android:allowBackup="{{ args.allow_backup }}"
5151
{% if args.backup_rules %}android:fullBackupContent="@xml/{{ args.backup_rules }}"{% endif %}
5252
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
53-
android:hardwareAccelerated="true" >
53+
android:hardwareAccelerated="true"
54+
android:extractNativeLibs="true" >
5455
{% for l in args.android_used_libs %}
5556
<uses-library android:name="{{ l }}" />
5657
{% endfor %}

pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
5353
android:hardwareAccelerated="true"
5454
android:usesCleartextTraffic="true"
55+
android:extractNativeLibs="true"
5556
{% if debug %}android:debuggable="true"{% endif %}
5657
>
5758
{% for l in args.android_used_libs %}

0 commit comments

Comments
 (0)