Skip to content

Commit 5a62962

Browse files
Merge pull request #39 from OlivierLDff/support-multi-abi-qt
Support build with Qt5.14, 5.15 with new qtandroiddeploy config file.
2 parents 250fdb2 + 6c56d64 commit 5a62962

File tree

4 files changed

+61
-21
lines changed

4 files changed

+61
-21
lines changed

AddQtAndroidApk.cmake

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET)
7171

7272
# extract the full path of the source target binary
7373
set(QT_ANDROID_APP_PATH "$<TARGET_FILE:${SOURCE_TARGET}>") # full file path to the app's main shared library
74+
if(${Qt5Core_VERSION} VERSION_GREATER_EQUAL 5.14)
75+
set(QT_ANDROID_SUPPORT_MULTI_ABI ON)
76+
endif()
77+
78+
if(QT_ANDROID_SUPPORT_MULTI_ABI)
79+
# qtandroideploy will append by itself the ANDROID_ABI to the target name
80+
set(QT_ANDROID_APPLICATION_BINARY "${SOURCE_TARGET}")
81+
else()
82+
set(QT_ANDROID_APPLICATION_BINARY ${QT_ANDROID_APP_PATH})
83+
endif()
7484

7585
# define the application name
7686
if(ARG_NAME)
@@ -155,22 +165,35 @@ macro(add_qt_android_apk TARGET SOURCE_TARGET)
155165
message(WARNING "Failed to determine ANDROID_STL_PREFIX value for ANDROID_STL=${ANDROID_STL}")
156166
endif()
157167

158-
# define the STL shared library path
159-
# up until NDK r18, ANDROID_STL_SHARED_LIBRARIES is populated by the NDK's toolchain file
160-
# since NDK r19, the only option for a shared STL library is libc++_shared
161-
if(ANDROID_STL_SHARED_LIBRARIES)
162-
list(GET ANDROID_STL_SHARED_LIBRARIES 0 STL_LIBRARY_NAME) # we can only give one to androiddeployqt
163-
if(ANDROID_STL_PATH)
164-
set(QT_ANDROID_STL_PATH "${ANDROID_STL_PATH}/libs/${ANDROID_ABI}/lib${ANDROID_STL}.so")
168+
if(QT_ANDROID_SUPPORT_MULTI_ABI)
169+
# from Qt 5.14 qtandroideploy will find the correct stl.
170+
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs")
171+
else()
172+
# define the STL shared library path
173+
# up until NDK r18, ANDROID_STL_SHARED_LIBRARIES is populated by the NDK's toolchain file
174+
# since NDK r19, the only option for a shared STL library is libc++_shared
175+
if(ANDROID_STL_SHARED_LIBRARIES)
176+
list(GET ANDROID_STL_SHARED_LIBRARIES 0 STL_LIBRARY_NAME) # we can only give one to androiddeployqt
177+
if(ANDROID_STL_PATH)
178+
set(QT_ANDROID_STL_PATH "${ANDROID_STL_PATH}/libs/${ANDROID_ABI}/lib${ANDROID_STL}.so")
179+
else()
180+
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${ANDROID_STL}.so")
181+
endif()
182+
elseif(ANDROID_STL STREQUAL c++_shared)
183+
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/libc++_shared.so")
165184
else()
166-
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/lib${ANDROID_STL}.so")
185+
message(WARNING "ANDROID_STL (${ANDROID_STL}) isn't a known shared stl library."
186+
"You should consider setting ANDROID_STL to c++_shared (like Qt).")
187+
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/libc++_shared.so")
167188
endif()
168-
elseif(ANDROID_STL STREQUAL c++_shared)
169-
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/libc++_shared.so")
170-
else()
171-
message(WARNING "ANDROID_STL (${ANDROID_STL}) isn't a known shared stl library."
172-
"You should consider setting ANDROID_STL to c++_shared (like Qt).")
173-
set(QT_ANDROID_STL_PATH "${QT_ANDROID_NDK_ROOT}/sources/cxx-stl/${ANDROID_STL_PREFIX}/libs/${ANDROID_ABI}/libc++_shared.so")
189+
endif()
190+
191+
# From Qt 5.14 qtandroideploy "target-architecture" is no longer valid in input file
192+
# It have been replaced by "architectures": { "${ANDROID_ABI}": "${ANDROID_ABI}" }
193+
# This allow to package multiple ABI in a single apk
194+
# For now we only support single ABI build with this script (to ensure it work with Qt5.14 & Qt5.15)
195+
if(QT_ANDROID_SUPPORT_MULTI_ABI)
196+
set(QT_ANDROID_ARCHITECTURES "\"${ANDROID_ABI}\":\"${ANDROID_ABI}\"")
174197
endif()
175198

176199
# set the list of dependant libraries

AndroidManifest.xml.in

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
android:installLocation="auto"
55
xmlns:android="http://schemas.android.com/apk/res/android"
66
android:versionCode="@QT_ANDROID_APP_VERSION_CODE@">
7+
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
78
<application
89
android:label="@QT_ANDROID_APP_NAME@"
910
android:name="org.qtproject.qt5.android.bindings.QtApplication">
@@ -18,24 +19,32 @@
1819
<category android:name="android.intent.category.LAUNCHER"/>
1920
</intent-filter>
2021

22+
<!-- Application arguments -->
23+
<!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
24+
<!-- Application arguments -->
25+
2126
<meta-data android:name="android.app.lib_name" android:value="-- %%INSERT_APP_LIB_NAME%% --"/>
2227
<meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
2328
<meta-data android:name="android.app.repository" android:value="default"/>
2429
<meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
2530
<meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
2631
<!-- Deploy Qt libs as part of package -->
2732
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
28-
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
29-
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
33+
3034
<!-- Run with local libs -->
3135
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
3236
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
33-
<meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
37+
<meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
3438
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
3539
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
36-
<!-- Used to specify custom system library path to run with local system libs -->
40+
<!-- Used to specify custom system library path to run with local system libs -->
3741
<!-- <meta-data android:name="android.app.system_libs_prefix" android:value="/system/lib/"/> -->
3842
<!-- Messages maps -->
43+
<meta-data android:value="@string/ministro_not_found_msg" android:name="android.app.ministro_not_found_msg"/>
44+
<meta-data android:value="@string/ministro_needed_msg" android:name="android.app.ministro_needed_msg"/>
45+
<meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
46+
<meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
47+
<!-- Messages maps -->
3948

4049
<!-- Splash screen -->
4150
<!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->

build.gradle.in

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ android {
5454
lintOptions {
5555
abortOnError false
5656
}
57+
58+
// Do not compress Qt binary resources file
59+
aaptOptions {
60+
noCompress 'rcc'
61+
}
62+
5763
defaultConfig {
58-
minSdkVersion 16
59-
targetSdkVersion @QT_ANDROID_NATIVE_API_LEVEL@
64+
resConfigs "en"
6065
}
6166
}

qtdeploy.json.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
"tool-prefix": "@QT_ANDROID_TOOL_PREFIX@",
99
"toolchain-version": "@QT_ANDROID_TOOLCHAIN_VERSION@",
1010
"ndk-host": "@ANDROID_NDK_HOST_SYSTEM_NAME@",
11+
"architectures": {
12+
@QT_ANDROID_ARCHITECTURES@
13+
},
1114
"target-architecture": "@ANDROID_ABI@",
12-
"application-binary": "@QT_ANDROID_APP_PATH@",
15+
"application-binary": "@QT_ANDROID_APPLICATION_BINARY@",
1316
"android-package": "@QT_ANDROID_APP_PACKAGE_NAME@",
1417
"android-app-name": "@QT_ANDROID_APP_NAME@",
1518
"qml-root-path": "@CMAKE_SOURCE_DIR@",

0 commit comments

Comments
 (0)