aboutsummaryrefslogtreecommitdiffstats
path: root/share
diff options
context:
space:
mode:
authorRaphael Cotty <raphael.cotty@gmail.com>2021-04-01 20:35:00 +0200
committerRaphaƫl Cotty <raphael.cotty@gmail.com>2021-05-26 05:15:03 +0000
commitd57614e1f1d2ffc9ef0c22178f1be87a900387f2 (patch)
treec6f4a7220cf8ff3de502cf6b5c6fd7724230e7bf /share
parentff04acd64d85d460e0f52a7ead233ae503e616d7 (diff)
Android: Add option to use dex compiler d8 instead of dx
d8 dex compiler was introduced in Build Tools 28.0.2 to replace dx. It is the default compiler used by gradle since version 4.4 Change-Id: I603c61f6f1a151f3c5be78385bf9648929e7d81b Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Diffstat (limited to 'share')
-rw-r--r--share/qbs/module-providers/Qt/templates/android_support.qbs9
-rw-r--r--share/qbs/modules/Android/sdk/sdk.qbs9
-rw-r--r--share/qbs/modules/Android/sdk/utils.js55
3 files changed, 66 insertions, 7 deletions
diff --git a/share/qbs/module-providers/Qt/templates/android_support.qbs b/share/qbs/module-providers/Qt/templates/android_support.qbs
index 4ce1364ea..a1975b890 100644
--- a/share/qbs/module-providers/Qt/templates/android_support.qbs
+++ b/share/qbs/module-providers/Qt/templates/android_support.qbs
@@ -14,7 +14,6 @@ Module {
property stringList extraPlugins // qmake: ANDROID_EXTRA_PLUGINS
property stringList extraLibs // qmake: ANDROID_EXTRA_LIBS
property bool verboseAndroidDeployQt: false
-
property string _androidDeployQtFilePath: FileInfo.joinPaths(_qtBinaryDir, "bin",
"androiddeployqt")
property string _qtBinaryDir
@@ -57,6 +56,8 @@ Module {
Android.sdk.customManifestProcessing: true
java._tagJniHeaders: false // prevent rule cycle
}
+ readonly property string _qtAndroidJarFileName: Utilities.versionCompare(version, "6.0") >= 0 ?
+ "Qt6Android.jar" : "QtAndroid.jar"
Properties {
condition: _enableSdkSupport && Utilities.versionCompare(version, "5.15") >= 0
&& Utilities.versionCompare(version, "6.0") < 0
@@ -301,8 +302,11 @@ Module {
filePath: "deployqt.list",
fileTags: "android.deployqt_list"
},
+ // androiddeployqt potentially copies more jar files but this one will always be there
+ // since it comes with Qt.core
{
- filePath: FileInfo.joinPaths(product.java.classFilesDir, "QtAndroid.jar"),
+ filePath: FileInfo.joinPaths(product.java.classFilesDir,
+ product.Qt.android_support._qtAndroidJarFileName),
fileTags: "bundled_jar"
}
]
@@ -353,6 +357,7 @@ Module {
var moveCmd = new JavaScriptCommand();
moveCmd.description = "processing androiddeployqt outout";
moveCmd.sourceCode = function() {
+ File.makePath(product.java.classFilesDir);
var libsDir = product.Qt.android_support._deployQtOutDir + "/libs";
var libDir = product.Android.sdk.packageContentsDir + "/lib";
var listFilePath = outputs["android.deployqt_list"][0].filePath;
diff --git a/share/qbs/modules/Android/sdk/sdk.qbs b/share/qbs/modules/Android/sdk/sdk.qbs
index 76f84dca6..b284c1f8f 100644
--- a/share/qbs/modules/Android/sdk/sdk.qbs
+++ b/share/qbs/modules/Android/sdk/sdk.qbs
@@ -167,6 +167,13 @@ Module {
property path apksignerFilePath: FileInfo.joinPaths(buildToolsDir, "apksigner")
property path aidlFilePath: FileInfo.joinPaths(buildToolsDir, "aidl")
property path dxFilePath: FileInfo.joinPaths(buildToolsDir, "dx")
+ property path d8FilePath: FileInfo.joinPaths(buildToolsDir, "d8")
+ property string dexCompilerName: "d8"
+ PropertyOptions {
+ name: "dexCompilerName"
+ allowedValues: ["dx", "d8"]
+ }
+ readonly property bool _useD8: dexCompilerName === "d8"
property path zipalignFilePath: FileInfo.joinPaths(buildToolsDir, "zipalign")
property path androidJarFilePath: FileInfo.joinPaths(sdkDir, "platforms", platform,
"android.jar")
@@ -430,7 +437,7 @@ Module {
condition: _enableRules
multiplex: true
inputs: ["java.class"]
- inputsFromDependencies: ["java.jar"]
+ inputsFromDependencies: ["java.jar", "bundled_jar"]
Artifact {
filePath: product.Android.sdk._generateAab ?
FileInfo.joinPaths(product.Android.sdk.packageContentsDir, "dex",
diff --git a/share/qbs/modules/Android/sdk/utils.js b/share/qbs/modules/Android/sdk/utils.js
index 264ad2da7..a10ca69fc 100644
--- a/share/qbs/modules/Android/sdk/utils.js
+++ b/share/qbs/modules/Android/sdk/utils.js
@@ -57,8 +57,21 @@ function availableBuildToolsVersions(sdkDir) {
}
function prepareDex(project, product, inputs, outputs, input, output, explicitlyDependsOn) {
- var dxFilePath = product.Android.sdk.dxFilePath;
- var args = ["--dex", "--output", output.filePath, product.java.classFilesDir];
+ var dexCompilerFilePath = product.Android.sdk._useD8 ? product.Android.sdk.d8FilePath
+ : product.Android.sdk.dxFilePath;
+ var args = ["--output", FileInfo.path(output.filePath)];
+
+ if (product.Android.sdk._useD8) {
+ args.push("--no-desugaring", "--release");
+ var classes = inputs["java.class"];
+ if (classes) {
+ args = args.concat(classes.map(function(javaClass) {
+ return FileInfo.relativePath(product.java.classFilesDir, javaClass.filePath) }));
+ }
+ } else {
+ args.unshift("--dex");
+ args.push(product.java.classFilesDir);
+ }
var jarFiles = [];
function traverseJarDeps(dep) {
@@ -80,8 +93,42 @@ function prepareDex(project, product, inputs, outputs, input, output, explicitly
args = args.concat(jarFiles);
- var cmd = new Command(dxFilePath, args);
- cmd.description = "creating " + output.fileName;
+ var cmd;
+ if (product.Android.sdk._useD8) {
+ cmd = new JavaScriptCommand();
+ cmd.args = args;
+ cmd.dexCompilerFilePath = dexCompilerFilePath;
+ cmd.description = "creating " + output.fileName;
+ cmd.workingDirectory = product.java.classFilesDir;
+ cmd.extendedDescription = dexCompilerFilePath + " " + args.join(' ');
+ cmd.highlight = "compiler";
+ cmd.sourceCode = function() {
+ // androiddeployqt copied jar files in product.java.classFilesDir
+ // but the rule only tags one jar file ("QtAndroid.jar"/"Qt6Android.jar")
+ // So to pass all files to d8, Qbs needs to read the directory
+ var bundledJarFilesDir = product.java.classFilesDir;
+ var bundledJarFiles = File.directoryEntries(bundledJarFilesDir, File.Files
+ | File.NoDotAndDotDot);
+ args = args.concat(bundledJarFiles.map(function(jarFile) {
+ return FileInfo.joinPaths(bundledJarFilesDir, jarFile) }));
+ var process = new Process();
+ var exitCode;
+ process.setWorkingDirectory(workingDirectory);
+ process.exec(dexCompilerFilePath, args, true);
+ try {
+ process.exec(dexCompilerFilePath, args, true);
+ } catch (e) {
+ throw new Error("Error while running dex compiler command: '"
+ + Process.shellQuote(dexCompilerFilePath, args) + "': " + e.toString());
+ } finally {
+ process.close();
+ }
+ }
+ } else {
+ cmd = new Command(dexCompilerFilePath, args);
+ cmd.description = "creating " + output.fileName;
+ cmd.workingDirectory = product.java.classFilesDir;
+ }
return [cmd];
}