diff options
Diffstat (limited to 'src/android/templates')
-rw-r--r-- | src/android/templates/.gitignore | 4 | ||||
-rw-r--r-- | src/android/templates/AndroidManifest.xml | 21 | ||||
-rw-r--r-- | src/android/templates/CMakeLists.txt | 30 | ||||
-rw-r--r-- | src/android/templates/build.gradle | 8 | ||||
-rw-r--r-- | src/android/templates/doc/src/android-manifest-file-configuration.qdoc | 287 | ||||
-rw-r--r-- | src/android/templates/res/values/libs.xml | 1 | ||||
-rw-r--r-- | src/android/templates/res/xml/qtprovider_paths.xml | 4 |
7 files changed, 339 insertions, 16 deletions
diff --git a/src/android/templates/.gitignore b/src/android/templates/.gitignore new file mode 100644 index 0000000000..90d41c1b2b --- /dev/null +++ b/src/android/templates/.gitignore @@ -0,0 +1,4 @@ +.gradle/ +.settings/ +.project +build/ diff --git a/src/android/templates/AndroidManifest.xml b/src/android/templates/AndroidManifest.xml index dc54a3400b..21ceaacc2e 100644 --- a/src/android/templates/AndroidManifest.xml +++ b/src/android/templates/AndroidManifest.xml @@ -13,16 +13,17 @@ android:smallScreens="true" /> <application android:name="org.qtproject.qt.android.bindings.QtApplication" - android:extractNativeLibs="true" android:hardwareAccelerated="true" android:label="-- %%INSERT_APP_NAME%% --" - android:requestLegacyExternalStorage="true"> + android:requestLegacyExternalStorage="true" + android:allowBackup="true" + android:fullBackupOnly="false"> <activity android:name="org.qtproject.qt.android.bindings.QtActivity" android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density" - android:label="-- %%INSERT_APP_NAME%% --" android:launchMode="singleTop" - android:screenOrientation="unspecified"> + android:screenOrientation="unspecified" + android:exported="true"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> @@ -35,10 +36,16 @@ <meta-data android:name="android.app.arguments" android:value="-- %%INSERT_APP_ARGUMENTS%% --" /> + </activity> + <provider + android:name="androidx.core.content.FileProvider" + android:authorities="${applicationId}.qtprovider" + android:exported="false" + android:grantUriPermissions="true"> <meta-data - android:name="android.app.extract_android_style" - android:value="minimal" /> - </activity> + android:name="android.support.FILE_PROVIDER_PATHS" + android:resource="@xml/qtprovider_paths"/> + </provider> </application> </manifest> diff --git a/src/android/templates/CMakeLists.txt b/src/android/templates/CMakeLists.txt index d0f1f4bf71..94f3243c22 100644 --- a/src/android/templates/CMakeLists.txt +++ b/src/android/templates/CMakeLists.txt @@ -1,18 +1,34 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + # Android template files -# special case skip regeneration -# special case begin set(template_files - AndroidManifest.xml - build.gradle) + "${CMAKE_CURRENT_SOURCE_DIR}/AndroidManifest.xml" + "${CMAKE_CURRENT_SOURCE_DIR}/build.gradle") set(template_directories - res) + "${CMAKE_CURRENT_SOURCE_DIR}/res") + +add_custom_target(Qt${QtBase_VERSION_MAJOR}AndroidTemplates + SOURCES + ${template_files} + "${CMAKE_CURRENT_SOURCE_DIR}/res/values/libs.xml" + "${CMAKE_CURRENT_SOURCE_DIR}/res/xml/qtprovider_paths.xml" +) + +qt_path_join(destination ${QT_INSTALL_DIR} ${INSTALL_DATADIR} "src/android/templates") -qt_path_join(destination ${QT_INSTALL_DIR} "src/android/templates") qt_copy_or_install(FILES ${template_files} DESTINATION "${destination}") qt_copy_or_install(DIRECTORY ${template_directories} DESTINATION "${destination}") -# special case end + +if(NOT QT_WILL_INSTALL) + qt_internal_copy_at_build_time(TARGET Qt${QtBase_VERSION_MAJOR}AndroidTemplates + FILES ${template_files} + DIRECTORIES ${template_directories} + DESTINATION ${destination} + ) +endif() diff --git a/src/android/templates/build.gradle b/src/android/templates/build.gradle index 94e8196756..f94ffbde54 100644 --- a/src/android/templates/build.gradle +++ b/src/android/templates/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.android.tools.build:gradle:7.4.1' } } @@ -18,6 +18,7 @@ apply plugin: 'com.android.application' dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar']) + implementation 'androidx.core:core:1.10.1' } android { @@ -34,10 +35,13 @@ android { * Changing them manually might break the compilation! *******************************************************/ - compileSdkVersion androidCompileSdkVersion.toInteger() + compileSdkVersion androidCompileSdkVersion buildToolsVersion androidBuildToolsVersion ndkVersion androidNdkVersion + // Extract native libraries from the APK + packagingOptions.jniLibs.useLegacyPackaging true + sourceSets { main { manifest.srcFile 'AndroidManifest.xml' diff --git a/src/android/templates/doc/src/android-manifest-file-configuration.qdoc b/src/android/templates/doc/src/android-manifest-file-configuration.qdoc new file mode 100644 index 0000000000..db0d3c7277 --- /dev/null +++ b/src/android/templates/doc/src/android-manifest-file-configuration.qdoc @@ -0,0 +1,287 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only + +/*! +\page android-manifest-file-configuration.html +\title Qt Android Manifest File Configuration +\ingroup androidplatform +\brief Provides details on the AndroidManifest.xml configuration. +\previouspage android-openssl-support.html +\nextpage android-services.html + +The Android Manifest is an XML file necessary for any Android app. It contains +app configuration for different settings and features that the app use, as well +as details on the app itself, such as, package name, app name, version, etc. +Permissions and hardware features can also be set from the manifest. + +Qt for Android maintains a version of \c {AndroidManifest.xml} with default +configuration that include features, permissions and other configuration +used by the build system which are needed for building and running Qt apps +on Android. + +\section1 Qt Project to Manifest Configuration + +Qt defines some \l {Android: App Manifest <meta-data>}{meta-data} that is passed +from the build systems and to \l {Deploying an Application on Android}{androiddeployqt} +which populates the manifest with the correct values without explicitly setting +these in the manifest file. Such \l {Android: App Manifest <meta-data>}{meta-data} +is assigned a value in the form \c {"-- %%INSERT_VALUE%% --"}, for example: + +\badcode +<manifest ... + android:versionCode="-- %%INSERT_VERSION_CODE%% --" + ... +</manifest> +\endcode + +This would be populated with the version code that is set in, for example, +\c CMake. + +\section1 Qt Default Configuration + +Qt sets the following manifest configuration by default: + +\table +\header + \li Section + \li Option + \li Description +\row + \li {1, 5} \l {Android: App Manifest <manifest>}{<manifest>} + \li package + \li Sets the package name. The default value is \c {org.qtproject.example.app_name}. +\row + \li \c {android:installLocation} + \li Sets the app's installation location, whether internal or external storage. + The default value is \c auto. +\row + \li android:versionCode + \li Sets the internal version code. Populated from \c ANDROID_VERSION_CODE (qmake) + and \c QT_ANDROID_VERSION_CODE (CMake). The default value is \c 1. +\row + \li android:versionName + \li Sets the public version name. Populated from \c ANDROID_VERSION_NAME (qmake) + and \c QT_ANDROID_VERSION_NAME (CMake). The default value is \c {1.0}. +\row + \li \c {<supports-screens>} + \li Sets the screen sizes that the app supports, + default values are \c anyDensity, \c largeScreens, + \c normalScreens, and \c smallScreens. +\row + \li {1, 6} \l {Android: App Manifest <application>}{<application>} + \li android:name + \li The application class name. Default value is + \c {org.qtproject.qt.android.bindings.QtApplication}. +\row + \li android:label + \li The application name label. Default value is the Qt project's target name. +\row + \li android:hardwareAccelerated + \li Sets hardware acceleration preference. The default value is \c true. +\row + \li android:requestLegacyExternalStorage + \li Whether to use Android scoped storage. The default value is \c true. +\row + \li android:allowBackup + \li Whether to allow the application to participate in the backup and restore + infrastructure. If this is set to \c false, no backup or restore of the + application will ever be performed. The default value is \c true. +\row + \li android:fullBackupOnly + \li Whether or not to use Auto Backup on devices where it is available. + The default value is \c false. +\row + \li {1, 6} \l {Android: App Manifest <activity>}{<activity>} + \li android:name + \li The activity class name. The default value is \c {org.qtproject.qt.android.bindings.QtActivity}. +\row + \li android:configChanges + \li Lists configuration changes that the activity handles. Default value is + \c orientation, \c uiMode, \c screenLayout, \c screenSize, + \c smallestScreenSize, \c layoutDirection, \c locale, \c fontScale, + \c keyboard, \c keyboardHidden, \c navigation, \c mcc, \c mnc, \c density. +\row + \li android:launchMode + \li The method used to launch the activity. The default value is \c singleTop. +\row + \li android:screenOrientation + \li The orientation of the activity's display on the device. The default value is \c unspecified. +\row + \li <intent-filter> + \li Specifies the types of intents that the activity can respond to. Default value is + \badcode + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + \endcode +\row + \li android:exported + \li Sets whether the activity can be launched by components of other applications. + The default value is \c true. +\endtable + +\section1 Qt Specific Meta-data + +In addition to the default manifest configuration that Qt sets, Qt defines +some meta-data that is valid for Qt apps only. Such meta-data is usually +under the \c <activity> section in the form: + +\badcode +<meta-data + android:name="meta-data-name" + android:value="meta-data-value" /> +\endcode + +The following is a list of such meta-data defined by Qt: + +\table +\header + \li Meta-data Name + \li Description +\row + \li android.app.lib_name \target android.app.lib_name + \li The filename of the native C++ library that is used by the activity. + \note This attribute is mandatory and shouldn't be removed. + Default value is the Qt project's target name. +\row + \li android.app.extract_android_style + \li The method used to extract the native Android Style information. + For more information, see \l {Style Extraction}. + The default value is \c minimal. +\row + \li android.app.background_running \target android.app.background_running + \li Sets whether the app keeps running tasks in the background. + Setting this to \c true is the equivalent of setting the environment + variable \c QT_BLOCK_EVENT_LOOPS_WHEN_SUSPENDED to \c 0. + The default value is \c false. + + \warning Setting this to \c true may cause unexpected crash if the + application tries to draw after \l {QGuiApplication::applicationStateChanged()} + signal is sent with a \l {Qt::ApplicationSuspended} state. +\row + \li android.app.arguments \target android.app.arguments + \li Sets a list of arguments to pass to the app \c {"arg1 arg2"}. + Populated from \c ANDROID_APPLICATION_ARGUMENTS (qmake) and + \c QT_ANDROID_APPLICATION_ARGUMENTS (CMake). + Default value is not set. +\row + \li android.app.splash_screen_drawable_portrait + \li Sets a drawable for a splash screen specific to portrait mode. + For example: \c {android:resource="@drawable/splash_portrait"}. + Default value is not set. +\row + \li android.app.splash_screen_drawable_landscape + \li Sets a drawable for a splash screen specific to landscape mode. + For example: \c {android:resource="@drawable/splash_landscape"}. + Default value is not set. +\row + \li android.app.splash_screen_drawable + \li Sets a drawable for a splash screen at the start of the app. + \note Orientation specific splash screens are checked first, + if not set, this is used instead. + For example: \c {android:resource="@drawable/splash"}. + Default value is not set. +\row + \li android.app.splash_screen_sticky + \li Sets whether the splash screen stays visible until explicitly hidden + by the app. + For more information, see + \l {QNativeInterface::}{QAndroidApplication::hideSplashScreen()}. +\row + \li android.app.trace_location + \li Specifies a location on device where the application can save tracing files. + For example: /storage/emulated/0/Android/data/<app_package_name>/files/. + This is needed when using Common Trace Format (CTF) tracing backend. + \note The application needs storage permission for the location. + Default: not set. +\endtable + +\section2 Application Specific Meta-data + +Some meta-data attributes are application-wide, and should be placed under +the \c <application> section: + +\table +\header + \li Meta-data Name + \li Description +\row + \li android.app.system_libs_prefix \target android.app.system_libs_prefix + \li Specifies a custom system library path to use for library loading lookup. + This is necessary when using Qt libraries installed outside an app's + default native (JNI) library directory. + The default value is \c {/system/lib/}. +\endtable + +\section2 Meta-data in Services + +Some meta-data attributes can also be used in \l {Android Services}{Services}. +The main ones are: + +\list + \li \l {android.app.lib_name} + \li \l {android.app.background_running} + \li \l {android.app.arguments} +\endlist + +\section2 Qt Permissions and Features + +Different Qt modules might require some Android permissions or features to +function properly, for example, Camera permission in \l {QtMultimedia}. +l{The androiddeployqt Tool} takes care of including such requirements into the +Android manifest during the build. Qt defines the following lines into the +manifest, which they get replaced by +the actual values: + +\badcode +<manifest ... + <!-- %%INSERT_PERMISSIONS --> + <!-- %%INSERT_FEATURES --> + ... +</manifest> +\endcode + +\note If those lines are removed from the project manifest, Qt won't be +able to include the correct permissions. So some functionalities +might not work properly. + +\section2 Style Extraction + +Qt uses different methods to determine how Qt Widgets and Qt Quick Controls +should be styled: + +\list + \li \c default or \c full: when using Qt Widgets or Qt Quick Controls 1. + \note This method uses some Android non-SDK interfaces, that are being + restricted and removed by Google starting from Android 9.0 (API 28). + For that reason, this is not recommended for Android 9.0 or greater. + \li \c minimal: when using Qt Quick Controls 2 and no Qt Widgets or Qt Quick + Controls 1. This is faster than using the default or full options. + \li \c none: no style extraction. +\endlist + +\section1 Qt Manifest before 6.2 Release + +Versions of Qt earlier than 6.2 used to have an additional set of meta-data +defined by Qt. These attributes used to manage dependencies and some were +used by the discontinued \c Ministro service. With Qt 6.2, they should be removed. +Here is a list of these attributes: + +\list + \li android.app.qt_sources_resource_id + \li android.app.repository + \li android.app.bundled_libs_resource_id + \li android.app.bundle_local_qt_libs + \li android.app.use_local_qt_libs + \li android.app.libs_prefix + \li android.app.load_local_libs_resource_id + \li android.app.load_local_jars + \li android.app.static_init_classes + \li android.app.qt_libs_resource_id + \li android.app.ministro_not_found_msg + \li android.app.ministro_needed_msg + \li android.app.fatal_error_msg +\endlist + +For more information on the Android Manifest, see +\l{Android: App Manifest}{Android App Manifest}. +*/ diff --git a/src/android/templates/res/values/libs.xml b/src/android/templates/res/values/libs.xml index beb15ca1d8..fe63866f72 100644 --- a/src/android/templates/res/values/libs.xml +++ b/src/android/templates/res/values/libs.xml @@ -17,4 +17,5 @@ <string name="static_init_classes"><!-- %%INSERT_INIT_CLASSES%% --></string> <string name="use_local_qt_libs"><!-- %%USE_LOCAL_QT_LIBS%% --></string> <string name="bundle_local_qt_libs"><!-- %%BUNDLE_LOCAL_QT_LIBS%% --></string> + <string name="system_libs_prefix"><!-- %%SYSTEM_LIBS_PREFIX%% --></string> </resources> diff --git a/src/android/templates/res/xml/qtprovider_paths.xml b/src/android/templates/res/xml/qtprovider_paths.xml new file mode 100644 index 0000000000..ae5b4b6074 --- /dev/null +++ b/src/android/templates/res/xml/qtprovider_paths.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<paths xmlns:android="http://schemas.android.com/apk/res/android"> + <files-path name="files_path" path="/"/> +</paths> |