summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kde.org>2019-08-01 08:56:59 +0300
committerBogDan Vatra <bogdan@kde.org>2019-08-26 12:59:15 +0300
commit5bb178c479a247720fbc3fbb7f06a32b725193ac (patch)
tree61b07e76f1a553953d2632b6deb7ae742cfb725c /src/android
parent77de5a329c98c3787725cb3c0a50d8f369b9479c (diff)
Say hello to Android multi arch build in one go
Multi arch build in one go is need to support the new .aab packaging format. By default the users apps are built for all Android ABIs: arm64-v8a armeabi-v7a x86_64 x86 The user can pass ANDROID_ABIS to qmake to filter the ABIs during development, e.g. qmake ANDROID_ABIS="arm64-v8a armeabi-v7a" will build only for arm ABIs. [ChangeLog][Android] Android multi arch build in one go, needed to support the new .aab packaging format. Change-Id: I3a64caf9621c2a195863976a62a57cdf47e6e3b5 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/jar/jar.pro1
-rw-r--r--src/android/java/java.pro2
-rw-r--r--src/android/java/src/org/qtproject/qt5/android/bindings/QtLoader.java77
-rw-r--r--src/android/templates/AndroidManifest.xml5
-rw-r--r--src/android/templates/build.gradle2
-rw-r--r--src/android/templates/res/values/libs.xml9
-rw-r--r--src/android/templates/templates.pro2
7 files changed, 76 insertions, 22 deletions
diff --git a/src/android/jar/jar.pro b/src/android/jar/jar.pro
index ac6fc79968..24a83d56a1 100644
--- a/src/android/jar/jar.pro
+++ b/src/android/jar/jar.pro
@@ -1,6 +1,7 @@
TARGET = QtAndroid
CONFIG += java
+
DESTDIR = $$[QT_INSTALL_PREFIX/get]/jar
PATHPREFIX = $$PWD/src/org/qtproject/qt5/android/
diff --git a/src/android/java/java.pro b/src/android/java/java.pro
index 9d37eb1026..7f0dfa8a1b 100644
--- a/src/android/java/java.pro
+++ b/src/android/java/java.pro
@@ -1,3 +1,5 @@
+CONFIG += single_arch
+
CONFIG -= qt android_install
javaresources.files = \
diff --git a/src/android/java/src/org/qtproject/qt5/android/bindings/QtLoader.java b/src/android/java/src/org/qtproject/qt5/android/bindings/QtLoader.java
index d3b0600b2f..45941e8ed8 100644
--- a/src/android/java/src/org/qtproject/qt5/android/bindings/QtLoader.java
+++ b/src/android/java/src/org/qtproject/qt5/android/bindings/QtLoader.java
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2016, BogDan Vatra <bogdan@kde.org>
+ Copyright (c) 2019, BogDan Vatra <bogdan@kde.org>
Contact: http://www.qt.io/licensing/
Commercial License Usage
@@ -63,9 +63,12 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
import dalvik.system.DexClassLoader;
@@ -85,7 +88,6 @@ public abstract class QtLoader {
public static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
public static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
public static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
- public static final String QT_LIBS_RESOURCE_ID_KEY = "android.app.qt_libs_resource_id";
public static final String BUNDLED_IN_LIB_RESOURCE_ID_KEY = "android.app.bundled_in_lib_resource_id";
public static final String BUNDLED_IN_ASSETS_RESOURCE_ID_KEY = "android.app.bundled_in_assets_resource_id";
public static final String MAIN_LIBRARY_KEY = "main.library";
@@ -153,7 +155,7 @@ public abstract class QtLoader {
// this repository is used to push a new release, and should be used to test your application.
// * unstable - unstable repository, DO NOT use this repository in production,
// this repository is used to push Qt snapshots.
- public String[] m_qtLibs = null; // required qt libs
+ public ArrayList<String> m_qtLibs = null; // required qt libs
public int m_displayDensity = -1;
private ContextWrapper m_context;
protected ComponentInfo m_contextInfo;
@@ -191,6 +193,36 @@ public abstract class QtLoader {
}
// Implement in subclass
+ private final List<String> supportedAbis = Arrays.asList(Build.SUPPORTED_ABIS);
+ private String preferredAbi = null;
+
+ private ArrayList<String> prefferedAbiLibs(String []libs)
+ {
+ HashMap<String, ArrayList<String>> abisLibs = new HashMap<>();
+ for (String lib : libs) {
+ String[] archLib = lib.split(";", 2);
+ if (preferredAbi != null && !archLib[0].equals(preferredAbi))
+ continue;
+ if (!abisLibs.containsKey(archLib[0]))
+ abisLibs.put(archLib[0], new ArrayList<String>());
+ abisLibs.get(archLib[0]).add(archLib[1]);
+ }
+
+ if (preferredAbi != null) {
+ if (abisLibs.containsKey(preferredAbi)) {
+ return abisLibs.get(preferredAbi);
+ }
+ return new ArrayList<String>();
+ }
+
+ for (String abi: supportedAbis) {
+ if (abisLibs.containsKey(abi)) {
+ preferredAbi = abi;
+ return abisLibs.get(abi);
+ }
+ }
+ return new ArrayList<String>();
+ }
// this function is used to load and start the loader
private void loadApplication(Bundle loaderParams)
@@ -218,12 +250,14 @@ public abstract class QtLoader {
// add all bundled Qt libs to loader params
ArrayList<String> libs = new ArrayList<String>();
- if (m_contextInfo.metaData.containsKey("android.app.bundled_libs_resource_id"))
- libs.addAll(Arrays.asList(m_context.getResources().getStringArray(m_contextInfo.metaData.getInt("android.app.bundled_libs_resource_id"))));
+ if (m_contextInfo.metaData.containsKey("android.app.bundled_libs_resource_id")) {
+ int resourceId = m_contextInfo.metaData.getInt("android.app.bundled_libs_resource_id");
+ libs.addAll(prefferedAbiLibs(m_context.getResources().getStringArray(resourceId)));
+ }
String libName = null;
if (m_contextInfo.metaData.containsKey("android.app.lib_name")) {
- libName = m_contextInfo.metaData.getString("android.app.lib_name");
+ libName = m_contextInfo.metaData.getString("android.app.lib_name") + "_" + preferredAbi;
loaderParams.putString(MAIN_LIBRARY_KEY, libName); //main library contains main() function
}
@@ -278,7 +312,7 @@ public abstract class QtLoader {
try {
if (m_service != null) {
Bundle parameters = new Bundle();
- parameters.putStringArray(REQUIRED_MODULES_KEY, m_qtLibs);
+ parameters.putStringArray(REQUIRED_MODULES_KEY, (String[]) m_qtLibs.toArray());
parameters.putString(APPLICATION_TITLE_KEY, getTitle());
parameters.putInt(MINIMUM_MINISTRO_API_KEY, MINISTRO_API_LEVEL);
parameters.putInt(MINIMUM_QT_VERSION_KEY, QT_VERSION);
@@ -464,7 +498,8 @@ public abstract class QtLoader {
// why can't we load the plugins directly from libs ?!?!
String key = BUNDLED_IN_LIB_RESOURCE_ID_KEY;
if (m_contextInfo.metaData.containsKey(key)) {
- String[] list = m_context.getResources().getStringArray(m_contextInfo.metaData.getInt(key));
+ int resourceId = m_contextInfo.metaData.getInt(key);
+ ArrayList<String> list = prefferedAbiLibs(m_context.getResources().getStringArray(resourceId));
for (String bundledImportBinary : list) {
String[] split = bundledImportBinary.split(":");
@@ -603,7 +638,7 @@ public abstract class QtLoader {
if (m_contextInfo.metaData.containsKey("android.app.qt_libs_resource_id")) {
int resourceId = m_contextInfo.metaData.getInt("android.app.qt_libs_resource_id");
- m_qtLibs = m_context.getResources().getStringArray(resourceId);
+ m_qtLibs = prefferedAbiLibs(m_context.getResources().getStringArray(resourceId));
}
if (m_contextInfo.metaData.containsKey("android.app.use_local_qt_libs")
@@ -617,6 +652,7 @@ public abstract class QtLoader {
apkDeployFromSystem = true;
String libsDir = null;
+ String bundledLibsDir = null;
if (apkDeployFromSystem) {
String systemLibsPrefix = SYSTEM_LIB_PATH;
if (m_contextInfo.metaData.containsKey("android.app.system_libs_prefix")) {
@@ -633,8 +669,11 @@ public abstract class QtLoader {
} else {
String nativeLibraryPrefix = m_context.getApplicationInfo().nativeLibraryDir + "/";
File nativeLibraryDir = new File(nativeLibraryPrefix);
- if (nativeLibraryDir.exists() && nativeLibraryDir.isDirectory() && nativeLibraryDir.list().length > 0)
+ if (nativeLibraryDir.exists() && nativeLibraryDir.isDirectory() && nativeLibraryDir.list().length > 0) {
libsDir = nativeLibraryPrefix;
+ bundledLibsDir = nativeLibraryPrefix;
+ }
+
}
if (apkDeployFromSystem && libsDir == null)
@@ -643,8 +682,8 @@ public abstract class QtLoader {
if (m_qtLibs != null) {
String libPrefix = libsDir + "lib";
- for (int i = 0; i < m_qtLibs.length; i++)
- libraryList.add(libPrefix + m_qtLibs[i] + ".so");
+ for (String lib : m_qtLibs)
+ libraryList.add(libPrefix + lib + ".so");
}
if (m_contextInfo.metaData.containsKey("android.app.bundle_local_qt_libs")
@@ -654,22 +693,26 @@ public abstract class QtLoader {
String pluginsPrefix = dataPath + "qt-reserved-files/";
if (libsDir == null)
- throw new Exception("");
+ throw new Exception("Invalid libsDir");
cleanOldCacheIfNecessary(dataPath, pluginsPrefix);
extractBundledPluginsAndImports(pluginsPrefix, libsDir);
if (m_contextInfo.metaData.containsKey(BUNDLED_IN_LIB_RESOURCE_ID_KEY)) {
- String[] extraLibs = m_contextInfo.metaData.getString("android.app.load_local_libs").split(":");
- for (String lib : extraLibs) {
- if (!lib.isEmpty())
- libraryList.add(pluginsPrefix + lib);
+ int resourceId = m_contextInfo.metaData.getInt("android.app.load_local_libs_resource_id");
+ for (String libs : prefferedAbiLibs(m_context.getResources().getStringArray(resourceId))) {
+ for (String lib : libs.split(":")) {
+ if (!lib.isEmpty())
+ libraryList.add(libsDir + lib);
+ }
}
}
ENVIRONMENT_VARIABLES += "\tQML2_IMPORT_PATH=" + pluginsPrefix + "/qml"
+ "\tQML_IMPORT_PATH=" + pluginsPrefix + "/imports"
+ "\tQT_PLUGIN_PATH=" + pluginsPrefix + "/plugins";
+ if (bundledLibsDir != null)
+ ENVIRONMENT_VARIABLES += "\tQT_BUNDLED_LIBS_PATH=" + bundledLibsDir;
}
Bundle loaderParams = new Bundle();
diff --git a/src/android/templates/AndroidManifest.xml b/src/android/templates/AndroidManifest.xml
index aed8a3c888..75da314c2b 100644
--- a/src/android/templates/AndroidManifest.xml
+++ b/src/android/templates/AndroidManifest.xml
@@ -12,7 +12,7 @@
<supports-screens android:largeScreens="true" android:normalScreens="true" android:anyDensity="true" android:smallScreens="true"/>
- <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --">
+ <application android:hardwareAccelerated="true" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="-- %%INSERT_APP_NAME%% --" android:extractNativeLibs="true">
<activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|layoutDirection|locale|fontScale|keyboard|keyboardHidden|navigation|mcc|mnc|density"
android:name="org.qtproject.qt5.android.bindings.QtActivity"
android:label="-- %%INSERT_APP_NAME%% --"
@@ -36,10 +36,11 @@
<meta-data android:name="android.app.bundle_local_qt_libs" android:value="-- %%BUNDLE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
<meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
+
<!-- Run with local libs -->
<meta-data android:name="android.app.use_local_qt_libs" android:value="-- %%USE_LOCAL_QT_LIBS%% --"/>
<meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
- <meta-data android:name="android.app.load_local_libs" android:value="-- %%INSERT_LOCAL_LIBS%% --"/>
+ <meta-data android:name="android.app.load_local_libs_resource_id" android:resource="@array/load_local_libs"/>
<meta-data android:name="android.app.load_local_jars" android:value="-- %%INSERT_LOCAL_JARS%% --"/>
<meta-data android:name="android.app.static_init_classes" android:value="-- %%INSERT_INIT_CLASSES%% --"/>
<!-- Used to specify custom system library path to run with local system libs -->
diff --git a/src/android/templates/build.gradle b/src/android/templates/build.gradle
index 8d4aa63153..d2da115936 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:3.2.0'
+ classpath 'com.android.tools.build:gradle:3.5.0'
}
}
diff --git a/src/android/templates/res/values/libs.xml b/src/android/templates/res/values/libs.xml
index 4009a7785a..db777bf433 100644
--- a/src/android/templates/res/values/libs.xml
+++ b/src/android/templates/res/values/libs.xml
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<resources>
<array name="qt_sources">
- <item>https://download.qt.io/ministro/android/qt5/qt-5.9</item>
+ <item>https://download.qt.io/ministro/android/qt5/qt-5.14</item>
</array>
<!-- The following is handled automatically by the deployment tool. It should
@@ -12,12 +12,17 @@
</array>
<array name="qt_libs">
- <!-- %%INSERT_QT_LIBS%% -->
+ <!-- %%INSERT_QT_LIBS%% -->
</array>
<array name="bundled_in_lib">
<!-- %%INSERT_BUNDLED_IN_LIB%% -->
</array>
+
+ <array name="load_local_libs">
+ <!-- %%INSERT_LOCAL_LIBS%% -->
+ </array>
+
<array name="bundled_in_assets">
<!-- %%INSERT_BUNDLED_IN_ASSETS%% -->
</array>
diff --git a/src/android/templates/templates.pro b/src/android/templates/templates.pro
index 55387f3af7..9a64251ee3 100644
--- a/src/android/templates/templates.pro
+++ b/src/android/templates/templates.pro
@@ -1,3 +1,5 @@
+CONFIG += single_arch
+
CONFIG -= qt android_install
templates.files = \