Skip to content

Commit 71c9a99

Browse files
authored
Updates for Android NDK version 26 (#822)
This PR adjusts the buildroot for Android NDK version 26. This NDK version only supports clang, so it contains some cleanups of old non-clang pathways. The companion flutter/engine PR is flutter/engine#48254.
1 parent 52689fe commit 71c9a99

File tree

4 files changed

+78
-211
lines changed

4 files changed

+78
-211
lines changed

build/config/android/config.gni

+10-86
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
# This file contains common system config stuff for the Android build.
66

77
if (is_android) {
8-
has_chrome_android_internal =
9-
exec_script("//build/dir_exists.py",
10-
[ rebase_path("//clank", root_build_dir) ],
11-
"string") == "True"
12-
13-
if (has_chrome_android_internal) {
14-
import("//clank/config.gni")
15-
}
16-
178
if (!defined(default_android_sdk_root)) {
189
default_android_sdk_root = "//third_party/android_tools/sdk"
1910
default_android_sdk_version = "34"
@@ -25,22 +16,6 @@ if (is_android) {
2516
android_sdk_version = default_android_sdk_version
2617
android_sdk_build_tools_version = default_android_sdk_build_tools_version
2718

28-
android_default_keystore_path =
29-
"//build/android/ant/chromium-debug.keystore"
30-
android_default_keystore_name = "chromiumdebugkey"
31-
android_default_keystore_password = "chromium"
32-
33-
# This is a unique identifier for a given build. It's used for
34-
# identifying various build artifacts corresponding to a particular build of
35-
# chrome (e.g. where to find archived symbols).
36-
android_chrome_build_id = "\"\""
37-
38-
# Set to true to run findbugs on JAR targets.
39-
run_findbugs = false
40-
41-
# Set to true to enable the Errorprone compiler
42-
use_errorprone_java_compiler = false
43-
4419
# Unused. Required for GN files maintained in other buildroots.
4520
enable_java_templates = false
4621

@@ -92,69 +67,17 @@ if (is_android) {
9267

9368
zipalign_path = "$android_sdk_build_tools/zipalign"
9469

95-
# Subdirectories inside android_ndk_root that contain the sysroot for the
96-
# associated platform.
9770
if (current_cpu != "x64" && current_cpu != "arm64") {
98-
android_api_level = 19
71+
android_api_level = 21
9972
}
10073

10174
# Toolchain root directory for each build. The actual binaries are inside
10275
# a "bin" directory inside of these.
103-
_android_toolchain_version = "4.9"
104-
10576
llvm_android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}"
106-
107-
x86_android_toolchain_root = "$android_ndk_root/toolchains/x86-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
108-
arm_android_toolchain_root = "$android_ndk_root/toolchains/arm-linux-androideabi-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
109-
x86_64_android_toolchain_root = "$android_ndk_root/toolchains/x86_64-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
110-
arm64_android_toolchain_root = "$android_ndk_root/toolchains/aarch64-linux-android-${_android_toolchain_version}/prebuilt/${android_host_os}-${android_host_arch}"
111-
112-
x86_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/i686-linux-android/${android_api_level}"
113-
arm_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/arm-linux-androideabi/${android_api_level}"
114-
x86_64_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/x86_64-linux-android/${android_api_level}"
115-
arm64_android_lib = "$llvm_android_toolchain_root/sysroot/usr/lib/aarch64-linux-android/${android_api_level}"
116-
117-
# Location of libgcc. This is only needed for the current GN toolchain, so we
118-
# only need to define the current one, rather than one for every platform
119-
# like the toolchain roots.
120-
if (current_cpu == "x86") {
121-
android_prebuilt_arch = "android-x86"
122-
android_target_triple = "i686-linux-android"
123-
android_toolchain_root = "$x86_android_toolchain_root"
124-
android_lib = "$x86_android_lib"
125-
} else if (current_cpu == "arm") {
126-
android_prebuilt_arch = "android-arm"
127-
android_target_triple = "arm-linux-androideabi"
128-
android_toolchain_root = "$arm_android_toolchain_root"
129-
android_lib = "$arm_android_lib"
130-
} else if (current_cpu == "x64") {
131-
android_prebuilt_arch = "android-x86_64"
132-
android_target_triple = "x86_64-linux-android"
133-
android_toolchain_root = "$x86_64_android_toolchain_root"
134-
android_lib = "$x86_64_android_lib"
135-
} else if (current_cpu == "arm64") {
136-
android_prebuilt_arch = "android-arm64"
137-
android_target_triple = "aarch64-linux-android"
138-
android_toolchain_root = "$arm64_android_toolchain_root"
139-
android_lib = "$arm64_android_lib"
140-
} else {
141-
assert(false, "Need android libgcc support for your target arch.")
142-
}
143-
144-
android_tool_prefix = "$android_toolchain_root/bin/$android_target_triple-"
145-
android_readelf = "${android_tool_prefix}readelf"
146-
android_objcopy = "${android_tool_prefix}objcopy"
147-
android_gdbserver =
148-
"$android_ndk_root/prebuilt/$android_prebuilt_arch/gdbserver/gdbserver"
77+
android_toolchain_root = "$android_ndk_root/toolchains/llvm/prebuilt/${android_host_os}-${android_host_arch}"
14978

15079
# Toolchain stuff ------------------------------------------------------------
151-
152-
android_libcpp_root = "$android_ndk_root/sources/cxx-stl/llvm-libc++"
153-
if (component_mode == "shared_library") {
154-
android_libcpp_library = "c++_shared"
155-
} else {
156-
android_libcpp_library = "c++_static"
157-
}
80+
_android_lib_prefix = "$android_toolchain_root/sysroot/usr/lib"
15881

15982
if (component_mode == "shared_library") {
16083
# By appending .cr, we prevent name collisions with libraries already
@@ -168,20 +91,21 @@ if (is_android) {
16891

16992
if (current_cpu == "x86") {
17093
android_app_abi = "x86"
94+
_android_lib_dir = "i686-linux-android"
17195
} else if (current_cpu == "arm") {
172-
import("//build/config/arm.gni")
173-
if (arm_version < 7) {
174-
android_app_abi = "armeabi"
175-
} else {
176-
android_app_abi = "armeabi-v7a"
177-
}
96+
android_app_abi = "armeabi-v7a"
97+
_android_lib_dir = "arm-linux-androideabi"
17898
} else if (current_cpu == "x64") {
17999
android_app_abi = "x86_64"
100+
_android_lib_dir = "x86_64-linux-android"
180101
} else if (current_cpu == "arm64") {
181102
android_app_abi = "arm64-v8a"
103+
_android_lib_dir = "aarch64-linux-android"
182104
} else {
183105
assert(false, "Unknown Android ABI: " + current_cpu)
184106
}
185107

108+
android_lib = "$_android_lib_prefix/$_android_lib_dir/$android_api_level"
109+
186110
android_log_tag = "\"flutter\""
187111
}

build/config/compiler/BUILD.gn

+37-58
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ config("compiler") {
231231
}
232232
if (arm_use_thumb) {
233233
cflags += [ "-mthumb" ]
234-
if (is_android && !is_clang) { # Clang doesn't support this option.
235-
cflags += [ "-mthumb-interwork" ]
236-
}
237234
}
238235
if (!is_clang) {
239236
# Clang doesn't support these flags.
@@ -392,31 +389,16 @@ config("compiler") {
392389
"-fno-short-enums",
393390
"-nostdinc++",
394391
]
395-
if (!is_clang) {
396-
# Clang doesn't support these flags.
397-
cflags += [ "-finline-limit=64" ]
398-
}
399-
if (current_cpu == "arm64") {
400-
# TODO (https://github.com/flutter/flutter/issues/75348).
401-
cflags += [ "-mno-outline-atomics" ]
402-
}
403392

404393
defines += [ "ANDROID" ]
405394

406395
# The NDK has these things, but doesn't define the constants
407396
# to say that it does. Define them here instead.
408397
defines += [ "HAVE_SYS_UIO_H" ]
409398

410-
if (is_clang) {
411-
# Let clang find libgcc.
412-
ldflags += [ "--gcc-toolchain=" +
413-
rebase_path(android_toolchain_root, root_build_dir) ]
414-
}
415-
416399
ldflags += [
417400
"-Wl,--no-undefined",
418401
"-Wl,--exclude-libs,ALL",
419-
"-fuse-ld=lld",
420402

421403
# Enable identical code folding to reduce size.
422404
"-Wl,--icf=all",
@@ -426,20 +408,18 @@ config("compiler") {
426408
"-Wl,-z,max-page-size=65536",
427409
]
428410

429-
if (is_clang) {
430-
if (current_cpu == "arm") {
431-
cflags += [ "--target=arm-linux-androideabi" ]
432-
ldflags += [ "--target=arm-linux-androideabi" ]
433-
} else if (current_cpu == "arm64") {
434-
cflags += [ "--target=aarch64-linux-android" ]
435-
ldflags += [ "--target=aarch64-linux-android" ]
436-
} else if (current_cpu == "x86") {
437-
cflags += [ "--target=i686-linux-androideabi" ]
438-
ldflags += [ "--target=i686-linux-androideabi" ]
439-
} else if (current_cpu == "x64") {
440-
cflags += [ "--target=x86_64-linux-androideabi" ]
441-
ldflags += [ "--target=x86_64-linux-androideabi" ]
442-
}
411+
if (current_cpu == "arm") {
412+
cflags += [ "--target=arm-linux-androideabi${android_api_level}" ]
413+
ldflags += [ "--target=arm-linux-androideabi${android_api_level}" ]
414+
} else if (current_cpu == "arm64") {
415+
cflags += [ "--target=aarch64-linux-android${android_api_level}" ]
416+
ldflags += [ "--target=aarch64-linux-android${android_api_level}" ]
417+
} else if (current_cpu == "x86") {
418+
cflags += [ "--target=i686-linux-androideabi${android_api_level}" ]
419+
ldflags += [ "--target=i686-linux-androideabi${android_api_level}" ]
420+
} else if (current_cpu == "x64") {
421+
cflags += [ "--target=x86_64-linux-androideabi${android_api_level}" ]
422+
ldflags += [ "--target=x86_64-linux-androideabi${android_api_level}" ]
443423
}
444424
}
445425

@@ -561,40 +541,34 @@ config("runtime_library") {
561541

562542
# Android standard library setup.
563543
if (is_android) {
564-
if (is_clang) {
565-
# Work around incompatibilities between bionic and clang headers.
566-
defines += [
567-
"__compiler_offsetof=__builtin_offsetof",
568-
"nan=__builtin_nan",
569-
]
570-
}
544+
# Work around incompatibilities between bionic and clang headers.
545+
defines += [
546+
"__compiler_offsetof=__builtin_offsetof",
547+
"nan=__builtin_nan",
548+
]
571549

572550
ldflags += [ "-nostdlib" ]
573551

574-
cflags += [ "-D__ANDROID_API__=$android_api_level" ]
575-
576-
# libunwind and libandroid_support also live in $android_libcpp_root.
577-
lib_dirs += [ "$android_libcpp_root/libs/$android_app_abi" ]
578-
579-
if (android_api_level < 21) {
580-
libs += [ "android_support" ]
581-
}
582-
583-
if (current_cpu == "arm") {
584-
libs += [ "unwind" ]
585-
}
552+
ldflags += [
553+
"-Wl,--warn-shared-textrel",
554+
]
586555

587556
libs += [
588-
"gcc",
589557
"c",
590558
"dl",
591559
"m",
592560
]
593561

594-
# Clang with libc++ does not require an explicit atomic library reference.
595-
if (!is_clang) {
596-
libs += [ "atomic" ]
562+
lib_dirs += [ "${android_toolchain_root}/lib/clang/17/lib/linux/" ]
563+
current_android_cpu = current_cpu
564+
if (current_cpu == "arm64") {
565+
current_android_cpu = "aarch64"
566+
} else if (current_cpu == "x64") {
567+
current_android_cpu = "x86_64"
568+
} else if (current_cpu == "x86") {
569+
current_android_cpu = "i686"
597570
}
571+
libs += [ "clang_rt.builtins-${current_android_cpu}-android" ]
598572
}
599573

600574
# Linux standard library setup.
@@ -682,10 +656,15 @@ if (is_win) {
682656

683657
# Needed for compiling Skia with clang-12
684658
"-Wno-psabi",
685-
686-
# Needed for nlohmann/json.
687-
"-Wno-deprecated-literal-operator",
688659
]
660+
661+
if (!is_android) {
662+
default_warning_flags += [
663+
# Needed for nlohmann/json.
664+
"-Wno-deprecated-literal-operator",
665+
]
666+
}
667+
689668
if (!is_wasm) {
690669
default_warning_flags += [
691670
# Unqualified std::move is pretty common.

build/config/sysroot.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (current_toolchain == default_toolchain && target_sysroot != "") {
2121
sysroot = target_sysroot
2222
} else if (is_android) {
2323
import("//build/config/android/config.gni")
24-
sysroot = rebase_path("$llvm_android_toolchain_root/sysroot", root_build_dir)
24+
sysroot = rebase_path("$android_toolchain_root/sysroot", root_build_dir)
2525
} else if (is_linux && !is_chromeos) {
2626
if (use_default_linux_sysroot && !is_fuchsia) {
2727
if (current_cpu == "x64") {

0 commit comments

Comments
 (0)