summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorTinja Paavoseppä <tinja.paavoseppa@qt.io>2022-01-19 13:35:50 +0200
committerTinja Paavoseppä <tinja.paavoseppa@qt.io>2022-05-20 08:08:02 +0300
commit9af1f3557a60e37f8b7bafb921d265d322f1fc16 (patch)
tree8a4b2ef422b02627e9d2055439b8489d1c40b652 /src/android
parentff153d9874f728c9ec3ab40b87f55ccf0239e538 (diff)
downloadqtbase-9af1f3557a60e37f8b7bafb921d265d322f1fc16.tar.gz
Add option to not include native libraries in APK
Sometimes it is not desirable to include the libraries in the APK, e.g. system and vendor apps could prefer having one set of libraries installed on the device. If unbundled deployment is specified, native libraries will not be included in the APK. With unbundled deployment, optional arguments can be passed to set the path to load the libraries on the device. [ChangeLog][Android][Deployment Changes] Adds option for Unbundled deployment, where native libraries are not packaged in the APK. Task-number: QAA-771 Change-Id: Ica51ef83a24dad58c7586bf610a58abe21fc1100 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/java/src/org/qtproject/qt/android/bindings/QtLoader.java73
-rw-r--r--src/android/templates/doc/src/android-manifest-file-configuration.qdoc17
-rw-r--r--src/android/templates/res/values/libs.xml1
3 files changed, 53 insertions, 38 deletions
diff --git a/src/android/java/src/org/qtproject/qt/android/bindings/QtLoader.java b/src/android/java/src/org/qtproject/qt/android/bindings/QtLoader.java
index 81304e23f6..66ba029ace 100644
--- a/src/android/java/src/org/qtproject/qt/android/bindings/QtLoader.java
+++ b/src/android/java/src/org/qtproject/qt/android/bindings/QtLoader.java
@@ -76,7 +76,6 @@ public abstract class QtLoader {
// These parameters matter in case of deploying application as system (embedded into firmware)
public static final String SYSTEM_LIB_PATH = "/system/lib/";
- public String[] SYSTEM_APP_PATHS = {"/system/priv-app/", "/system/app/"};
public String APPLICATION_PARAMETERS = null; // use this variable to pass any parameters to your application,
// the parameters must not contain any white spaces
@@ -255,33 +254,40 @@ public abstract class QtLoader {
if (useLocalLibs == 1) {
ArrayList<String> libraryList = new ArrayList<>();
-
- boolean apkDeployFromSystem = false;
- String apkPath = m_context.getApplicationInfo().publicSourceDir;
- File apkFile = new File(apkPath);
- if (apkFile.exists()) {
- for (String systemAppPath : SYSTEM_APP_PATHS) {
- apkDeployFromSystem = apkFile.getAbsolutePath().startsWith(systemAppPath);
- if (apkDeployFromSystem)
- break;
- }
- }
-
String libsDir = null;
String bundledLibsDir = null;
- if (apkDeployFromSystem) {
- String systemLibsPrefix = SYSTEM_LIB_PATH;
- if (m_contextInfo.metaData.containsKey("android.app.system_libs_prefix")) {
- systemLibsPrefix = m_contextInfo.metaData.getString("android.app.system_libs_prefix");
+
+ id = resources.getIdentifier("bundle_local_qt_libs", "string", packageName);
+ final int bundleLocalLibs = Integer.parseInt(resources.getString(id));
+ if (bundleLocalLibs == 0) {
+ String systemLibsPrefix;
+ final String systemLibsKey = "android.app.system_libs_prefix";
+ // First check if user has provided system libs prefix in AndroidManifest
+ if (m_contextInfo.applicationInfo.metaData != null &&
+ m_contextInfo.applicationInfo.metaData.containsKey(systemLibsKey)) {
+ systemLibsPrefix = m_contextInfo.applicationInfo.metaData.getString(systemLibsKey);
} else {
- Log.e(QtApplication.QtTAG, "It looks like app deployed as system app. "
- + "It may be necessary to specify path to system lib directory using "
- + "android.app.system_libs_prefix metadata variable in your AndroidManifest.xml");
+ // If not, check if it's provided by androiddeployqt in libs.xml
+ id = resources.getIdentifier("system_libs_prefix","string",
+ packageName);
+ systemLibsPrefix = resources.getString(id);
+ }
+ if (systemLibsPrefix.isEmpty()) {
+ systemLibsPrefix = SYSTEM_LIB_PATH;
+ Log.e(QtApplication.QtTAG, "It looks like app deployed using Unbundled "
+ + "deployment. It may be necessary to specify path to directory "
+ + "where Qt libraries are installed using either "
+ + "android.app.system_libs_prefix metadata variable in your "
+ + "AndroidManifest.xml or QT_ANDROID_SYSTEM_LIBS_PATH in your "
+ + "CMakeLists.txt");
Log.e(QtApplication.QtTAG, "Using " + SYSTEM_LIB_PATH + " as default path");
}
+
File systemLibraryDir = new File(systemLibsPrefix);
- if (systemLibraryDir.exists() && systemLibraryDir.isDirectory() && systemLibraryDir.list().length > 0) {
+ if (systemLibraryDir.exists() && systemLibraryDir.isDirectory()
+ && systemLibraryDir.list().length > 0) {
libsDir = systemLibsPrefix;
+ bundledLibsDir = systemLibsPrefix;
} else {
Log.e(QtApplication.QtTAG,
"System library directory " + systemLibsPrefix
@@ -300,7 +306,7 @@ public abstract class QtLoader {
}
}
- if (apkDeployFromSystem && libsDir == null)
+ if (libsDir == null)
throw new Exception("");
@@ -310,20 +316,17 @@ public abstract class QtLoader {
libraryList.add(libPrefix + lib + ".so");
}
- id = resources.getIdentifier("bundle_local_qt_libs", "string", packageName);
- final int bundleLocalLibs = Integer.parseInt(resources.getString(id));
-
- if (bundleLocalLibs == 1) {
- id = resources.getIdentifier("load_local_libs", "array", packageName);
- ArrayList<String> localLibs = prefferedAbiLibs(resources.getStringArray(id));
- for (String libs : localLibs) {
- for (String lib : libs.split(":")) {
- if (!lib.isEmpty())
- libraryList.add(libsDir + lib);
- }
+ id = resources.getIdentifier("load_local_libs", "array", packageName);
+ ArrayList<String> localLibs = prefferedAbiLibs(resources.getStringArray(id));
+ for (String libs : localLibs) {
+ for (String lib : libs.split(":")) {
+ if (!lib.isEmpty())
+ libraryList.add(libsDir + lib);
}
- if (bundledLibsDir != null)
- ENVIRONMENT_VARIABLES += "\tQT_BUNDLED_LIBS_PATH=" + bundledLibsDir;
+ }
+ if (bundledLibsDir != null) {
+ ENVIRONMENT_VARIABLES += "\tQT_PLUGIN_PATH=" + bundledLibsDir;
+ ENVIRONMENT_VARIABLES += "\tQML_PLUGIN_PATH=" + bundledLibsDir;
}
Bundle loaderParams = new Bundle();
diff --git a/src/android/templates/doc/src/android-manifest-file-configuration.qdoc b/src/android/templates/doc/src/android-manifest-file-configuration.qdoc
index f1ceee9205..c784040f45 100644
--- a/src/android/templates/doc/src/android-manifest-file-configuration.qdoc
+++ b/src/android/templates/doc/src/android-manifest-file-configuration.qdoc
@@ -145,7 +145,7 @@ The following is a list of such meta-data defined by Qt:
\table
\header
- \li meta-data name
+ \li Meta-data Name
\li Description
\row
\target android.app.lib_name
@@ -199,11 +199,23 @@ The following is a list of such meta-data defined by Qt:
by the app.
For more information, see
\l {QNativeInterface::}{QAndroidApplication::hideSplashScreen()}.
+\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
\target android.app.system_libs_prefix
\li android.app.system_libs_prefix
\li Specifies a custom system library path to use for library loading lookup.
- This is necessary when running as a system app.
+ 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
@@ -216,7 +228,6 @@ The main ones are:
\li \l {android.app.lib_name}
\li \l {android.app.background_running}
\li \l {android.app.arguments}
- \li \l {android.app.system_libs_prefix}
\endlist
\section2 Qt Permissions and Features
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>