Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt5: fix some Android and iOS errors #15539

Merged
merged 8 commits into from
Apr 12, 2023
24 changes: 24 additions & 0 deletions recipes/qt/5.x.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ patches:
base_path: "qt5/qtwebengine/src/3rdparty"
- patch_file: "patches/337f28c9ab-5.15.8.patch"
base_path: "qt5/qtbase"
- patch_file: "patches/android-backtrace.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-openssl.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-new-ndk.diff"
base_path: "qt5/qtbase"
"5.15.7":
- patch_file: "patches/337f28c9ab.patch"
base_path: "qt5/qtbase"
Expand All @@ -70,6 +76,12 @@ patches:
base_path: "qt5/qtwebengine/src/3rdparty/chromium/third_party/skia"
- patch_file: "patches/0001-Find-fontconfig-using-pkg-config.patch"
base_path: "qt5/qtwebengine/src/3rdparty"
- patch_file: "patches/android-backtrace.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-openssl.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-new-ndk.diff"
base_path: "qt5/qtbase"
"5.15.6":
- patch_file: "patches/337f28c9ab.patch"
base_path: "qt5/qtbase"
Expand All @@ -95,6 +107,12 @@ patches:
base_path: "qt5/qtwebengine/src/3rdparty/chromium/third_party/skia"
- patch_file: "patches/0001-Find-fontconfig-using-pkg-config.patch"
base_path: "qt5/qtwebengine/src/3rdparty"
- patch_file: "patches/android-backtrace.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-openssl.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-new-ndk.diff"
base_path: "qt5/qtbase"
"5.15.5":
- patch_file: "patches/337f28c9ab-5.15.5.patch"
base_path: "qt5/qtbase"
Expand All @@ -120,3 +138,9 @@ patches:
base_path: "qt5/qtwebengine/src/3rdparty/chromium/third_party/skia"
- patch_file: "patches/0001-Find-fontconfig-using-pkg-config.patch"
base_path: "qt5/qtwebengine/src/3rdparty"
- patch_file: "patches/android-backtrace.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-openssl.diff"
base_path: "qt5/qtbase"
- patch_file: "patches/android-new-ndk.diff"
base_path: "qt5/qtbase"
31 changes: 22 additions & 9 deletions recipes/qt/5.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.android import android_abi
from conan.tools.apple import is_apple_os
from conan.tools.build import build_jobs, check_min_cppstd, cross_building
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
Expand All @@ -14,7 +15,7 @@
import textwrap
import shutil

required_conan_version = ">=1.52.0"
required_conan_version = ">=1.59.0"


class QtConan(ConanFile):
Expand Down Expand Up @@ -69,6 +70,7 @@ class QtConan(ConanFile):
"gui": [True, False],
"widgets": [True, False],

"android_sdk": [None, "ANY"],
"device": [None, "ANY"],
"cross_compile": [None, "ANY"],
"sysroot": [None, "ANY"],
Expand Down Expand Up @@ -111,6 +113,7 @@ class QtConan(ConanFile):
"gui": True,
"widgets": True,

"android_sdk": None,
"device": None,
"cross_compile": None,
"sysroot": None,
Expand Down Expand Up @@ -188,6 +191,9 @@ def config_options(self):
if self.settings.os != "Macos":
del self.options.qtmacextras

if self.settings.os != "Android":
del self.options.android_sdk

def configure(self):
# if self.settings.os != "Linux":
# self.options.with_libiconv = False # QTBUG-84708
Expand Down Expand Up @@ -276,8 +282,11 @@ def validate(self):
if self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "5":
raise ConanInvalidConfiguration("Compiling Qt WebEngine with gcc < 5 is not supported")

if self.settings.os == "Android" and self.options.get_safe("opengl", "no") == "desktop":
raise ConanInvalidConfiguration("OpenGL desktop is not supported on Android. Consider using OpenGL es2")
if self.settings.os == "Android":
if self.options.get_safe("opengl", "no") == "desktop":
raise ConanInvalidConfiguration("OpenGL desktop is not supported on Android. Consider using OpenGL es2")
if not self.options.get_safe("android_sdk", ""):
raise ConanInvalidConfiguration("Path to Android SDK is required to build Qt")

if self.settings.os != "Windows" and self.options.get_safe("opengl", "no") == "dynamic":
raise ConanInvalidConfiguration("Dynamic OpenGL is supported only on Windows.")
Expand Down Expand Up @@ -312,7 +321,7 @@ def validate(self):
if self.options.get_safe("qtwayland", False) and not self.dependencies.direct_host["xkbcommon"].options.with_wayland:
raise ConanInvalidConfiguration("The 'with_wayland' option for the 'xkbcommon' package must be enabled when the 'qtwayland' option is enabled")

if cross_building(self) and self.options.cross_compile == "None" and not is_apple_os(self):
if cross_building(self) and self.options.cross_compile == "None" and not is_apple_os(self) and self.settings.os != "Android":
raise ConanInvalidConfiguration("option cross_compile must be set for cross compilation "
"cf https://doc.qt.io/qt-5/configure-options.html#cross-compilation-options")

Expand Down Expand Up @@ -726,16 +735,15 @@ def build(self):
args.append('QMAKE_APPLE_DEVICE_ARCHS="arm64"')
elif self.settings.os == "Android":
args += [f"-android-ndk-platform android-{self.settings.os.api_level}"]
args += ["-android-abis %s" % {"armv7": "armeabi-v7a",
"armv8": "arm64-v8a",
"x86": "x86",
"x86_64": "x86_64"}.get(str(self.settings.arch))]
args += [f"-android-abis {android_abi(self)}"]

if self.settings.get_safe("compiler.libcxx") == "libstdc++":
args += ["-D_GLIBCXX_USE_CXX11_ABI=0"]
elif self.settings.get_safe("compiler.libcxx") == "libstdc++11":
args += ["-D_GLIBCXX_USE_CXX11_ABI=1"]

if self.options.get_safe("android_sdk", ""):
args += [f"-android-sdk {self.options.android_sdk}"]
if self.options.sysroot:
args += [f"-sysroot {self.options.sysroot}"]

Expand Down Expand Up @@ -940,6 +948,8 @@ def package_id(self):
self.info.settings.compiler.runtime = "MT/MTd"
else:
self.info.settings.compiler.runtime_type = "Release/Debug"
if self.settings.os == "Android":
del self.info.options.android_sdk

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Qt5")
Expand All @@ -957,6 +967,8 @@ def _add_build_module(component, module):
self.cpp_info.components[component].build_modules["cmake_find_package_multi"].append(module)

libsuffix = ""
if self.settings.os == "Android":
libsuffix = f"_{android_abi(self)}"
if not self.options.multiconfiguration:
if self.settings.build_type == "Debug":
if self.settings.os == "Windows" and is_msvc(self):
Expand Down Expand Up @@ -1429,8 +1441,9 @@ def _create_plugin(pluginname, libname, plugintype, requires):
self.cpp_info.components["qtNetwork"].frameworks.append("GSS")
if not self.options.openssl: # with SecureTransport
self.cpp_info.components["qtNetwork"].frameworks.append("Security")
if self.settings.os == "Macos":
if self.settings.os == "Macos" or (self.settings.os == "iOS" and Version(self.settings.compiler.version) >= "14.0"):
self.cpp_info.components["qtCore"].frameworks.append("IOKit") # qtcore requires "_IORegistryEntryCreateCFProperty", "_IOServiceGetMatchingService" and much more which are in "IOKit" framework
if self.settings.os == "Macos":
self.cpp_info.components["qtCore"].frameworks.append("Cocoa") # qtcore requires "_OBJC_CLASS_$_NSApplication" and more, which are in "Cocoa" framework
self.cpp_info.components["qtCore"].frameworks.append("Security") # qtcore requires "_SecRequirementCreateWithString" and more, which are in "Security" framework

Expand Down
19 changes: 19 additions & 0 deletions recipes/qt/5.x.x/patches/android-backtrace.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have have a link to an issue on bugreports.qt.io or to a patch on codereview.qt-project.org?
This level of android api should supported out of the box https://doc.qt.io/qt-5/android.html

Copy link
Contributor Author

@kambala-decapitator kambala-decapitator Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately, no such issue has been raised yet. I've also checked backports in https://invent.kde.org/qt/qt/qtbase/-/commits/kde/5.15 but there's also no such fix.

according to https://doc.qt.io/qt-5/android-getting-started.html Qt 5.15 has been tested only with NDK 20b and 21, pretty sure those toolchain versions don't have backtrace functions or execinfo.h.

I only found https://bugreports.qt.io/browse/QTBUG-108054 but that applies to Qt 6 only, and the patch can't be applied to Qt 5 because of heavy changes that Qt 6 made.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks for the clarifications

index 89f49324c..dedf78fe5 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -107,7 +107,13 @@
# define QLOGGING_HAVE_BACKTRACE
# endif
# elif (defined(__GLIBC__) && defined(__GLIBCXX__)) || (__has_include(<cxxabi.h>) && __has_include(<execinfo.h>))
-# define QLOGGING_HAVE_BACKTRACE
+# ifdef __ANDROID_API__
+# if __ANDROID_API__ >= 33
+# define QLOGGING_HAVE_BACKTRACE
+# endif
+# else
+# define QLOGGING_HAVE_BACKTRACE
+# endif
# endif
#endif

27 changes: 27 additions & 0 deletions recipes/qt/5.x.x/patches/android-new-ndk.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 49f62e8c5a8aef4c0b7fd6867a30e653d2f5dd98 Mon Sep 17 00:00:00 2001
From: Alexey Edelev <alexey.edelev@qt.io>
Date: Mon, 21 Nov 2022 15:03:17 +0100
Subject: [PATCH] Remove QMAKE_RANLIB and QMAKE_LINK_SHLIB from android/default_pre.prf

The values should come from android-clang mkspecs. The hardcoded
values don't work correctly with recent Android NDKs.

Pick-to: 6.4 6.2 5.15
Fixes: QTBUG-108662
Change-Id: Ie153a50ee0c49bd4f0704b588a4e2c87a05c1063
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
---

diff --git a/mkspecs/features/android/default_pre.prf b/mkspecs/features/android/default_pre.prf
index 9f90dcb..2328b72 100644
--- a/mkspecs/features/android/default_pre.prf
+++ b/mkspecs/features/android/default_pre.prf
@@ -76,8 +76,6 @@
else: equals(QT_ARCH, arm64-v8a): CROSS_COMPILE = $$NDK_LLVM_PATH/bin/aarch64-linux-android-
else: CROSS_COMPILE = $$NDK_LLVM_PATH/bin/arm-linux-androideabi-

-QMAKE_RANLIB = $${CROSS_COMPILE}ranlib
-QMAKE_LINK_SHLIB = $$QMAKE_LINK
QMAKE_LFLAGS =

QMAKE_LIBS_PRIVATE = -llog -lz -lm -ldl -lc
13 changes: 13 additions & 0 deletions recipes/qt/5.x.x/patches/android-openssl.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/network/ssl/ssl.pri b/src/network/ssl/ssl.pri
index 230c45c26..d7527949e 100644
--- a/src/network/ssl/ssl.pri
+++ b/src/network/ssl/ssl.pri
@@ -117,7 +117,7 @@ qtConfig(ssl) {

qtConfig(openssl-linked): {
android {
- build_pass|single_android_abi: LIBS_PRIVATE += -lssl_$${QT_ARCH} -lcrypto_$${QT_ARCH}
+ build_pass|single_android_abi: LIBS_PRIVATE += -lssl -lcrypto
} else: QMAKE_USE_FOR_PRIVATE += openssl
} else: \
QMAKE_USE_FOR_PRIVATE += openssl/nolink