From f9a8e47d13b7fec4f26c9f641271843f9ca65394 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Tue, 25 May 2021 19:34:25 +0300 Subject: Android: Copy the target lib to android-build as part of the apk step Make sure to copy the target's main lib file before building the APK. If the lib file is already there, i.e. copied by the underlying build system, this does nothing, but if the file is not copied by default like in cmake with Qt 6, this would copy it and would save us having to add *_prepare_apk_dir in cmake command. Also, this could allow us to remove the step "make install" from qmake step settings. After this we could revert 9dcbb8ca01e0981b6a3c7ea8dd278014343f48e3. Fixes: QTCREATORBUG-25367 Fixes: QTCREATORBUG-25216 Change-Id: I243a16a32e2ea97e175c893470480c9d2c9b1e27 Reviewed-by: Alessandro Portale --- src/plugins/android/androidbuildapkstep.cpp | 46 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/src/plugins/android/androidbuildapkstep.cpp b/src/plugins/android/androidbuildapkstep.cpp index d149b2033c..1e89531172 100644 --- a/src/plugins/android/androidbuildapkstep.cpp +++ b/src/plugins/android/androidbuildapkstep.cpp @@ -748,28 +748,54 @@ void AndroidBuildApkStep::doRun() auto setup = [this] { const auto androidAbis = AndroidManager::applicationAbis(target()); + const QString buildKey = target()->activeBuildKey(); + + QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(kit()); + if (!version) + return false; + for (const auto &abi : androidAbis) { FilePath androidLibsDir = buildDirectory() / "android-build/libs" / abi; - if (!androidLibsDir.exists() && !QDir{buildDirectory().toString()}.mkpath(androidLibsDir.toString())) - return false; - } + if (!androidLibsDir.exists()) { + if (!QDir{buildDirectory().toString()}.mkpath(androidLibsDir.toString())) { + const QString error = tr("The Android build folder %1 wasn't found and " + "couldn't be created.").arg(androidLibsDir.toString()); + emit addOutput(error, BuildStep::OutputFormat::ErrorMessage); + TaskHub::addTask(BuildSystemTask(Task::Error, error)); + return false; + } else if (version->qtVersion() >= QtSupport::QtVersionNumber{6, 0, 0} + && version->qtVersion() <= QtSupport::QtVersionNumber{6, 1, 1}) { + // 6.0.x <= Qt <= 6.1.1 used to need a manaul call to _prepare_apk_dir target, + // and now it's made directly with ALL target, so this code below ensures + // these versions are not broken. + const QString fileName = QString("lib%1_%2.so").arg(buildKey, abi); + const FilePath from = buildDirectory() / fileName; + const FilePath to = androidLibsDir / fileName; + if (!from.exists() || to.exists()) + continue; + + if (!QFile::copy(from.toString(), to.toString())) { + const QString error = tr("Couldn't copy the target's lib file %1 to the " + "Android build folder %2.") + .arg(fileName, androidLibsDir.toString()); + emit addOutput(error, BuildStep::OutputFormat::ErrorMessage); + TaskHub::addTask(BuildSystemTask(Task::Error, error)); + return false; + } + } + } - const QString buildKey = target()->activeBuildKey(); - BuildSystem *bs = buildSystem(); + } bool inputExists = QFile::exists(m_inputFile); if (inputExists && !AndroidManager::isQtCreatorGenerated(FilePath::fromString(m_inputFile))) return true; // use the generated file if it was not generated by qtcreator + BuildSystem *bs = buildSystem(); auto targets = bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(); if (targets.isEmpty()) return inputExists; // qmake does this job for us - - QtSupport::BaseQtVersion *version = QtSupport::QtKitAspect::qtVersion(kit()); - if (!version) - return false; - QJsonObject deploySettings = Android::AndroidManager::deploymentSettings(target()); QString applicationBinary; if (!version->supportsMultipleQtAbis()) { -- cgit v1.2.1