diff options
author | Raphaël Cotty <raphael.cotty@gmail.com> | 2020-05-20 11:48:46 +0200 |
---|---|---|
committer | Raphaël Cotty <raphael.cotty@gmail.com> | 2020-06-04 07:55:24 +0000 |
commit | 3e2b35f2f3d8c1e9ba3d8248033dcdcc90cf80fe (patch) | |
tree | b881b8339ddc18fba81d37d793fa41810dfdb89a /tests/auto | |
parent | 5c0b5b590e83dd1fe0b8b381bb2c4b9e8e16d816 (diff) |
Android: Add option to use aapt2 instead of aapt in Android.sdk module
aapt has been deprecated (https://developer.android.com/studio/command-line/aapt2) and replaced by aapt2.
PropertyOption aaptFileName allows those value: "aapt" and "aapt2".
Default value is set to "aapt" for the moment.
Fixes: QBS-1562
Change-Id: I1970cafaa54a0e035c08ffe5f9967b712f5c5253
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/blackbox/tst_blackboxandroid.cpp | 175 |
1 files changed, 145 insertions, 30 deletions
diff --git a/tests/auto/blackbox/tst_blackboxandroid.cpp b/tests/auto/blackbox/tst_blackboxandroid.cpp index 040a1a6e2..e8d44188c 100644 --- a/tests/auto/blackbox/tst_blackboxandroid.cpp +++ b/tests/auto/blackbox/tst_blackboxandroid.cpp @@ -80,6 +80,7 @@ void TestBlackboxAndroid::android() QFETCH(QStringList, productNames); QFETCH(QList<QByteArrayList>, expectedFilesLists); QFETCH(QStringList, qmlAppCustomProperties); + QFETCH(bool, enableAapt2); const SettingsPtr s = settings(); Profile p(theProfileName(projectDir == "qml-app"), s.get()); @@ -103,6 +104,7 @@ void TestBlackboxAndroid::android() && ndkSamplesDirs.contains(projectDir)) QSKIP("NDK samples directory not present"); + const QString aaptVersion = enableAapt2 ? "aapt2" : "aapt"; QDir::setCurrent(testDataDir + "/" + projectDir); static const QStringList configNames { "debug", "release" }; @@ -110,11 +112,13 @@ void TestBlackboxAndroid::android() auto currentExpectedFilesLists = expectedFilesLists; const QString configArgument = "config:" + configName; QbsRunParameters resolveParams("resolve"); + resolveParams.buildDirectory = aaptVersion; resolveParams.arguments << configArgument << qmlAppCustomProperties; resolveParams.profile = p.name(); QCOMPARE(runQbs(resolveParams), 0); QbsRunParameters buildParams(QStringList{"--command-echo-mode", "command-line", configArgument}); + buildParams.buildDirectory = aaptVersion; buildParams.profile = p.name(); QCOMPARE(runQbs(buildParams), 0); for (const QString &productName : qAsConst(productNames)) { @@ -123,7 +127,8 @@ void TestBlackboxAndroid::android() QCOMPARE(m_qbsStdout.count("Generating BuildConfig.java"), isIncrementalBuild ? 0 : productNames.size()); QVERIFY(m_qbsStdout.contains(productName.toLocal8Bit() + ".apk")); - const QString apkFilePath = relativeProductBuildDir(productName, configName) + const QString apkFilePath = aaptVersion + "/" + relativeProductBuildDir(productName, + configName) + '/' + productName + ".apk"; QVERIFY2(regularFileExists(apkFilePath), qPrintable(apkFilePath)); const QString jarFilePath = androidPaths["jar"]; @@ -206,7 +211,6 @@ void TestBlackboxAndroid::android_data() .toString() == "clang"; return QByteArray("lib/${ARCH}/") + (usesClang ? "libc++_shared.so" : oldcxxLib); }; - bool usingOldQt = true; QStringList qmakeFilePaths = pQt.value(QStringLiteral("moduleProviders.Qt.qmakeFilePaths")). toStringList(); @@ -265,24 +269,56 @@ void TestBlackboxAndroid::android_data() QTest::addColumn<QStringList>("productNames"); QTest::addColumn<QList<QByteArrayList>>("expectedFilesLists"); QTest::addColumn<QStringList>("qmlAppCustomProperties"); + QTest::addColumn<bool>("enableAapt2"); + + const auto aaptVersion = [](bool enableAapt2) { + return QString("modules.Android.sdk.aaptName:") + (enableAapt2 ? "aapt2" : "aapt"); + }; + bool enableAapt2 = false; + QByteArrayList teaPotAppExpectedFiles; + teaPotAppExpectedFiles << commonFiles + expandArchs(archs, { + "resources.arsc", + "assets/Shaders/ShaderPlain.fsh", + "assets/Shaders/VS_ShaderPlain.vsh", + cxxLibPath("libgnustl_shared.so", false), + "lib/${ARCH}/libTeapotNativeActivity.so", + "res/layout/widgets.xml", + "res/mipmap-hdpi-v4/ic_launcher.png", + "res/mipmap-mdpi-v4/ic_launcher.png", + "res/mipmap-xhdpi-v4/ic_launcher.png", + "res/mipmap-xxhdpi-v4/ic_launcher.png"}); QTest::newRow("teapot") << "teapot" << QStringList("TeapotNativeActivity") - << (QList<QByteArrayList>() << commonFiles + expandArchs(archs, { - "resources.arsc", - "assets/Shaders/ShaderPlain.fsh", - "assets/Shaders/VS_ShaderPlain.vsh", - cxxLibPath("libgnustl_shared.so", false), - "lib/${ARCH}/libTeapotNativeActivity.so", - "res/layout/widgets.xml"})) - << QStringList(); + << (QList<QByteArrayList>() << teaPotAppExpectedFiles) + << QStringList{aaptVersion(enableAapt2)} << enableAapt2; + enableAapt2 = true; + QTest::newRow("teapot") + << "teapot" << QStringList("TeapotNativeActivity") + << (QList<QByteArrayList>() << teaPotAppExpectedFiles) + << QStringList{aaptVersion(enableAapt2)} << enableAapt2; + enableAapt2 = false; + QTest::newRow("minimal-native") + << "minimal-native" << QStringList("minimalnative") + << (QList<QByteArrayList>() << commonFiles + expandArchs({archs.first()}, { + "lib/${ARCH}/libminimalnative.so", + cxxLibPath("libstlport_shared.so", false), + "lib/${ARCH}/libdependency.so"})) + << QStringList{"products.minimalnative.multiplexByQbsProperties:[]", + "modules.qbs.architecture:" + archsStringList.first(), + aaptVersion(enableAapt2)} + << enableAapt2; + enableAapt2 = true; QTest::newRow("minimal-native") << "minimal-native" << QStringList("minimalnative") << (QList<QByteArrayList>() << commonFiles + expandArchs({archs.first()}, { + "resources.arsc", "lib/${ARCH}/libminimalnative.so", cxxLibPath("libstlport_shared.so", false), "lib/${ARCH}/libdependency.so"})) << QStringList{"products.minimalnative.multiplexByQbsProperties:[]", - "modules.qbs.architecture:" + archsStringList.first()}; + "modules.qbs.architecture:" + archsStringList.first(), + aaptVersion(enableAapt2)} + << enableAapt2; QByteArrayList qmlAppExpectedFiles; QByteArrayList qmlAppMinistroExpectedFiles; QByteArrayList qmlAppCustomMetaDataExpectedFiles; @@ -325,14 +361,12 @@ void TestBlackboxAndroid::android_data() "lib/${ARCH}/libQt5Qml.so", "lib/${ARCH}/libQt5QuickParticles.so", "lib/${ARCH}/libQt5Quick.so", - "lib/${ARCH}/libqmlapp.so", - "res/layout/splash.xml"}); + "lib/${ARCH}/libqmlapp.so"}); qmlAppMinistroExpectedFiles << commonFiles + expandArchs(ndkArchsForQt, { "resources.arsc", "assets/--Added-by-androiddeployqt--/qt_cache_pregenerated_file_list", cxxLibPath("libgnustl_shared.so", true), - "lib/${ARCH}/libqmlapp.so", - "res/layout/splash.xml"}); + "lib/${ARCH}/libqmlapp.so"}); qmlAppCustomMetaDataExpectedFiles << commonFiles + expandArchs(ndkArchsForQt, { "resources.arsc", "assets/--Added-by-androiddeployqt--/qml/QtQuick.2/plugins.qmltypes", @@ -371,8 +405,7 @@ void TestBlackboxAndroid::android_data() "lib/${ARCH}/libQt5Qml.so", "lib/${ARCH}/libQt5QuickParticles.so", "lib/${ARCH}/libQt5Quick.so", - "lib/${ARCH}/libqmlapp.so", - "res/layout/splash.xml"}); + "lib/${ARCH}/libqmlapp.so"}); qmlAppCustomProperties = QStringList{"modules.Android.sdk.automaticSources:false", "modules.qbs.architecture:" + archsForQt.first()}; } else { @@ -411,14 +444,12 @@ void TestBlackboxAndroid::android_data() "lib/${ARCH}/libQt5Quick_${ARCH}.so", "lib/${ARCH}/libQt5QmlModels_${ARCH}.so", "lib/${ARCH}/libQt5QmlWorkerScript_${ARCH}.so", - "lib/${ARCH}/libqmlapp_${ARCH}.so", - "res/layout/splash.xml"}); + "lib/${ARCH}/libqmlapp_${ARCH}.so"}); qmlAppMinistroExpectedFiles << commonFiles + expandArchs(ndkArchsForQt, { "resources.arsc", "assets/android_rcc_bundle.rcc", cxxLibPath("libgnustl_shared.so", true), - "lib/${ARCH}/libqmlapp_${ARCH}.so", - "res/layout/splash.xml"}); + "lib/${ARCH}/libqmlapp_${ARCH}.so"}); qmlAppCustomMetaDataExpectedFiles << commonFiles + expandArchs(ndkArchsForQt, { "resources.arsc", "assets/android_rcc_bundle.rcc", @@ -455,23 +486,57 @@ void TestBlackboxAndroid::android_data() "lib/${ARCH}/libQt5Quick_${ARCH}.so", "lib/${ARCH}/libQt5QmlModels_${ARCH}.so", "lib/${ARCH}/libQt5QmlWorkerScript_${ARCH}.so", - "lib/${ARCH}/libqmlapp_${ARCH}.so", - "res/layout/splash.xml"}); + "lib/${ARCH}/libqmlapp_${ARCH}.so"}); qmlAppCustomProperties = QStringList{"modules.Android.sdk.automaticSources:false"}; } + // aapt tool for the resources works with a directory option pointing to the parent directory + // of the resources (res). + // The Qt.android_support module adds res/values/libs.xml (from Qt install dir). So the res from + // Qt install res directory is added to aapt. This results in adding res/layout/splash.xml to + // the package eventhough the file is not needed. + // On the other hand aapt2 requires giving all the resources files. + // Also when enabling aapt2 the resources.arsc is always created, eventhough no resources is + // declared. + enableAapt2 = false; + QTest::newRow("qml app") + << "qml-app" << QStringList("qmlapp") + << (QList<QByteArrayList>() << (QByteArrayList() << qmlAppExpectedFiles + << "res/layout/splash.xml")) + << (QStringList() << qmlAppCustomProperties << aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = true; QTest::newRow("qml app") << "qml-app" << QStringList("qmlapp") << (QList<QByteArrayList>() << qmlAppExpectedFiles) - << qmlAppCustomProperties; + << (QStringList() << qmlAppCustomProperties << aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = false; + QTest::newRow("qml app using Ministro") + << "qml-app" << QStringList("qmlapp") + << (QList<QByteArrayList>() << (QByteArrayList() << qmlAppMinistroExpectedFiles + << "res/layout/splash.xml")) + << QStringList{"modules.Qt.android_support.useMinistro:true", + "modules.Android.sdk.automaticSources:false", + aaptVersion(enableAapt2)} << enableAapt2; + enableAapt2 = true; QTest::newRow("qml app using Ministro") << "qml-app" << QStringList("qmlapp") << (QList<QByteArrayList>() << qmlAppMinistroExpectedFiles) << QStringList{"modules.Qt.android_support.useMinistro:true", - "modules.Android.sdk.automaticSources:false"}; + "modules.Android.sdk.automaticSources:false", + aaptVersion(enableAapt2)} << enableAapt2; + enableAapt2 = false; + QTest::newRow("qml app with custom metadata") + << "qml-app" << QStringList("qmlapp") + << (QList<QByteArrayList>() << (QByteArrayList() << qmlAppCustomMetaDataExpectedFiles + << "res/layout/splash.xml")) + << QStringList{"modules.Android.sdk.automaticSources:true", + aaptVersion(enableAapt2)} << enableAapt2; + enableAapt2 = true; QTest::newRow("qml app with custom metadata") << "qml-app" << QStringList("qmlapp") << (QList<QByteArrayList>() << qmlAppCustomMetaDataExpectedFiles) - << QStringList("modules.Android.sdk.automaticSources:true"); + << QStringList{"modules.Android.sdk.automaticSources:true", + aaptVersion(enableAapt2)} << enableAapt2; + enableAapt2 = false; QTest::newRow("no native") << "no-native" << QStringList("com.example.android.basicmediadecoder") @@ -493,9 +558,41 @@ void TestBlackboxAndroid::android_data() "res/menu/action_menu.xml", "res/menu-v11/action_menu.xml", "res/raw/vid_bigbuckbunny.mp4"})) - << QStringList(); + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = true; + QTest::newRow("no native") + << "no-native" + << QStringList("com.example.android.basicmediadecoder") + << (QList<QByteArrayList>() << commonFiles + expandArchs(archs, { + "resources.arsc", + "res/drawable-hdpi-v4/ic_action_play_disabled.png", + "res/drawable-hdpi-v4/ic_action_play.png", + "res/drawable-hdpi-v4/ic_launcher.png", + "res/drawable-hdpi-v4/tile.9.png", + "res/drawable-mdpi-v4/ic_action_play_disabled.png", + "res/drawable-mdpi-v4/ic_action_play.png", + "res/drawable-mdpi-v4/ic_launcher.png", + "res/drawable/selector_play.xml", + "res/drawable-xhdpi-v4/ic_action_play_disabled.png", + "res/drawable-xhdpi-v4/ic_action_play.png", + "res/drawable-xhdpi-v4/ic_launcher.png", + "res/drawable-xxhdpi-v4/ic_launcher.png", + "res/layout/sample_main.xml", + "res/menu/action_menu.xml", + // I have no idea why this file is generated with aapt and not with aapt2 + //"res/menu-v11/action_menu.xml", + "res/raw/vid_bigbuckbunny.mp4"})) + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = false; QTest::newRow("aidl") << "aidl" << QStringList("io.qbs.aidltest") - << QList<QByteArrayList>{commonFiles} << QStringList(); + << (QList<QByteArrayList>() << (QByteArrayList() << commonFiles)) + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = true; + QTest::newRow("aidl") << "aidl" << QStringList("io.qbs.aidltest") + << (QList<QByteArrayList>() << (QByteArrayList() << commonFiles + << "resources.arsc")) + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = false; QTest::newRow("multiple libs") << "multiple-libs-per-apk" << QStringList("twolibs") @@ -504,7 +601,17 @@ void TestBlackboxAndroid::android_data() "lib/${ARCH}/liblib1.so", "lib/${ARCH}/liblib2.so", cxxLibPath("libstlport_shared.so", false)})) - << QStringList(); + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = true; + QTest::newRow("multiple libs") + << "multiple-libs-per-apk" + << QStringList("twolibs") + << (QList<QByteArrayList>() << commonFiles + expandArchs(archs, { + "resources.arsc", + "lib/${ARCH}/liblib1.so", + "lib/${ARCH}/liblib2.so", + cxxLibPath("libstlport_shared.so", false)})) + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; QByteArrayList expectedFiles1 = qbs::toList(qbs::toSet(commonFiles + expandArchs(QByteArrayList{"armeabi-v7a", "x86"}, { "resources.arsc", @@ -518,11 +625,19 @@ void TestBlackboxAndroid::android_data() "lib/${ARCH}/libp2lib1.so", "lib/${ARCH}/libp2lib2.so", cxxLibPath("libstlport_shared.so", false)}); + enableAapt2 = false; + QTest::newRow("multiple apks") + << "multiple-apks-per-project" + << (QStringList() << "twolibs1" << "twolibs2") + << QList<QByteArrayList>{expectedFiles1, expectedFiles2} + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; + enableAapt2 = true; + expectedFiles2 << "resources.arsc"; QTest::newRow("multiple apks") << "multiple-apks-per-project" << (QStringList() << "twolibs1" << "twolibs2") << QList<QByteArrayList>{expectedFiles1, expectedFiles2} - << QStringList(); + << QStringList(aaptVersion(enableAapt2)) << enableAapt2; } QTEST_MAIN(TestBlackboxAndroid) |