From abf0d5005e357dd2fe59ccf02412687f72e56cb5 2013-05-22 07:12:28 From: Heikkinen Miikka Date: 2013-05-22 07:12:28 Subject: [PATCH] Fix qml application deployment for android Change-Id: I5a693f3ca7d6110505f8e6d276f53825e1a5961b Reviewed-by: Tomi Korpipää --- diff --git a/demos/demos.pri b/demos/demos.pri index 55935e8..b6955ba 100644 --- a/demos/demos.pri +++ b/demos/demos.pri @@ -14,3 +14,23 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets # staticlib config causes problems when building executables staticlib: CONFIG-=staticlib + +android { + # Workaround to fix android deployment, which seems to always look for target in + # OUT_PWD instead of DESTDIR. + QMAKE_POST_LINK += $$QMAKE_COPY $$CHART_BUILD_BIN_DIR/lib$${TARGET}.so $$OUT_PWD/lib$${TARGET}.so + + contains(TARGET, qml.*) { + charts_qmldir.files = $$CHART_BUILD_QML_PLUGIN_DIR/qmldir + charts_qmldir.path = /assets/imports/QtCommercial/Chart + charts_qmlplugin.files = $$CHART_BUILD_QML_PLUGIN_DIR/libqtcommercialchartqml.so + charts_qmlplugin.path = /libs/$$ANDROID_TARGET_ARCH + INSTALLS += charts_qmldir charts_qmlplugin + } else:contains(TARGET, quick2.*) { + charts_qmldir.files = $$CHART_BUILD_QML2_PLUGIN_DIR/qmldir + charts_qmldir.path = /assets/qml/QtCommercial/Chart + charts_qmlplugin.files = $$CHART_BUILD_QML2_PLUGIN_DIR/libqtcommercialchartqml2.so + charts_qmlplugin.path = /libs/$$ANDROID_TARGET_ARCH + INSTALLS += charts_qmldir charts_qmlplugin + } +} diff --git a/demos/qmlaxes/main.cpp b/demos/qmlaxes/main.cpp index 0513818..30b93a5 100644 --- a/demos/qmlaxes/main.cpp +++ b/demos/qmlaxes/main.cpp @@ -20,14 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); - +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlaxes/loader.qml")); viewer->setRenderHint(QPainter::Antialiasing, true); diff --git a/demos/qmlchart/main.cpp b/demos/qmlchart/main.cpp index 1d8d019..2d58ad4 100644 --- a/demos/qmlchart/main.cpp +++ b/demos/qmlchart/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlchart/loader.qml")); diff --git a/demos/qmlcustomizations/main.cpp b/demos/qmlcustomizations/main.cpp index 57c66de..5e3fd34 100644 --- a/demos/qmlcustomizations/main.cpp +++ b/demos/qmlcustomizations/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlcustomizations/loader.qml")); diff --git a/demos/qmlcustomlegend/main.cpp b/demos/qmlcustomlegend/main.cpp index 1609635..85b396b 100644 --- a/demos/qmlcustomlegend/main.cpp +++ b/demos/qmlcustomlegend/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif //viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlcustomlegend/loader.qml")); diff --git a/demos/qmlcustommodel/main.cpp b/demos/qmlcustommodel/main.cpp index 6f2ef20..51997a5 100644 --- a/demos/qmlcustommodel/main.cpp +++ b/demos/qmlcustommodel/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "declarativemodel.h" #include "customtablemodel.h" #include "qmlapplicationviewer.h" @@ -32,7 +33,12 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // @uri QmlCustomModel qmlRegisterUncreatableType(uri, 1, 0, "AbstractItemModel", diff --git a/demos/qmlf1legends/main.cpp b/demos/qmlf1legends/main.cpp index ca29113..44269f5 100644 --- a/demos/qmlf1legends/main.cpp +++ b/demos/qmlf1legends/main.cpp @@ -19,8 +19,9 @@ ****************************************************************************/ #include -//#include +#include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) @@ -28,7 +29,12 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) QScopedPointer app(createApplication(argc, argv)); QmlApplicationViewer viewer; - viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/imports")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer.setSource(QUrl("qrc:/qml/qmlf1legends/main.qml")); viewer.setRenderHint(QPainter::Antialiasing, true); diff --git a/demos/qmloscilloscope/main.cpp b/demos/qmloscilloscope/main.cpp index 62b2472..2ee7084 100644 --- a/demos/qmloscilloscope/main.cpp +++ b/demos/qmloscilloscope/main.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #include "qmlapplicationviewer.h" #include "datasource.h" @@ -27,7 +29,12 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif DataSource dataSource(viewer.data()); viewer->rootContext()->setContextProperty("dataSource", &dataSource); diff --git a/demos/qmlpolarchart/main.cpp b/demos/qmlpolarchart/main.cpp index 83eefcb..1d54631 100644 --- a/demos/qmlpolarchart/main.cpp +++ b/demos/qmlpolarchart/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlpolarchart/loader.qml")); diff --git a/demos/qmlweather/main.cpp b/demos/qmlweather/main.cpp index 74f3343..2493ecf 100644 --- a/demos/qmlweather/main.cpp +++ b/demos/qmlweather/main.cpp @@ -20,7 +20,9 @@ #include #include +#include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) @@ -28,7 +30,12 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) QScopedPointer app(createApplication(argc, argv)); QmlApplicationViewer viewer; - viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/imports")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto); QString appKey; if (argc > 1) { diff --git a/demos/quick2chart/main.cpp b/demos/quick2chart/main.cpp index 4f1466e..2f0e83b 100644 --- a/demos/quick2chart/main.cpp +++ b/demos/quick2chart/main.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #include "qtquick2applicationviewer.h" int main(int argc, char *argv[]) @@ -27,7 +29,12 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QtQuick2ApplicationViewer viewer; +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/qml")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("qml"))); +#endif viewer.setSource(QUrl("qrc:/qml/quick2chart/main.qml")); viewer.showExpanded(); diff --git a/demos/quick2oscilloscope/main.cpp b/demos/quick2oscilloscope/main.cpp index d1911df..1e20fa9 100644 --- a/demos/quick2oscilloscope/main.cpp +++ b/demos/quick2oscilloscope/main.cpp @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include "qtquick2applicationviewer.h" #include "datasource.h" @@ -29,7 +31,12 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QtQuick2ApplicationViewer viewer; +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/qml")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("qml"))); +#endif DataSource dataSource(&viewer); viewer.rootContext()->setContextProperty("dataSource", &dataSource); diff --git a/examples/examples.pri b/examples/examples.pri index 33c9b2b..4948dcb 100644 --- a/examples/examples.pri +++ b/examples/examples.pri @@ -14,3 +14,17 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets # staticlib config causes problems when building executables staticlib: CONFIG-=staticlib + +android { + # Workaround to fix android deployment, which seems to always look for target in + # OUT_PWD instead of DESTDIR. + QMAKE_POST_LINK += $$QMAKE_COPY $$CHART_BUILD_BIN_DIR/lib$${TARGET}.so $$OUT_PWD/lib$${TARGET}.so + + contains(TARGET, qml.*) { + charts_qmldir.files = $$CHART_BUILD_QML_PLUGIN_DIR/qmldir + charts_qmldir.path = /assets/imports/QtCommercial/Chart + charts_qmlplugin.files = $$CHART_BUILD_QML_PLUGIN_DIR/libqtcommercialchartqml.so + charts_qmlplugin.path = /libs/$$ANDROID_TARGET_ARCH + INSTALLS += charts_qmldir charts_qmlplugin + } +} diff --git a/examples/qmlpiechart/main.cpp b/examples/qmlpiechart/main.cpp index 04bc853..b698ca6 100644 --- a/examples/qmlpiechart/main.cpp +++ b/examples/qmlpiechart/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlpiechart/main.qml")); diff --git a/tests/auto/qml/tst_qml.cpp b/tests/auto/qml/tst_qml.cpp index 841070c..1ec19ac 100644 --- a/tests/auto/qml/tst_qml.cpp +++ b/tests/auto/qml/tst_qml.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "tst_definitions.h" class tst_QML : public QObject @@ -126,7 +127,12 @@ void tst_QML::checkPlugin() { QFETCH(QString, source); QDeclarativeEngine engine; - engine.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + engine.addImportPath(QString::fromLatin1("assets:/imports")); + engine.addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + engine.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif QDeclarativeComponent component(&engine); component.setData(source.toLatin1(), QUrl()); QVERIFY2(!component.isError(), qPrintable(componentErrors(&component))); diff --git a/tests/qmlchartaxis/main.cpp b/tests/qmlchartaxis/main.cpp index f298f30..dddac9a 100644 --- a/tests/qmlchartaxis/main.cpp +++ b/tests/qmlchartaxis/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlchartaxis/main.qml")); diff --git a/tests/qmlchartproperties/main.cpp b/tests/qmlchartproperties/main.cpp index bf99ea4..50ad6a4 100644 --- a/tests/qmlchartproperties/main.cpp +++ b/tests/qmlchartproperties/main.cpp @@ -20,13 +20,19 @@ #include #include +#include #include "qmlapplicationviewer.h" Q_DECL_EXPORT int main(int argc, char *argv[]) { QScopedPointer app(createApplication(argc, argv)); QScopedPointer viewer(QmlApplicationViewer::create()); - viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QLatin1String("imports"))); +#ifdef Q_OS_ANDROID + viewer->addImportPath(QString::fromLatin1("assets:/imports")); + viewer->engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else + viewer->addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("imports"))); +#endif // // viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto); viewer->setSource(QUrl("qrc:/qml/qmlchartproperties/loader.qml")); diff --git a/tests/quick2chartproperties/main.cpp b/tests/quick2chartproperties/main.cpp index 099d7a7..07a0b26 100644 --- a/tests/quick2chartproperties/main.cpp +++ b/tests/quick2chartproperties/main.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #include "qtquick2applicationviewer.h" int main(int argc, char *argv[]) @@ -27,7 +29,12 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QtQuick2ApplicationViewer viewer; +#ifdef Q_OS_ANDROID + viewer.addImportPath(QString::fromLatin1("assets:/qml")); + viewer.engine()->addPluginPath(QString::fromLatin1("%1/../%2").arg(QDir::homePath(), QString::fromLatin1("lib"))); +#else viewer.addImportPath(QString::fromLatin1("%1/%2").arg(QCoreApplication::applicationDirPath(), QString::fromLatin1("qml"))); +#endif viewer.setSource(QUrl("qrc:/qml/quick2chartproperties/main.qml")); viewer.showExpanded(); diff --git a/tests/tests.pri b/tests/tests.pri index 85e0705..662cdca 100644 --- a/tests/tests.pri +++ b/tests/tests.pri @@ -12,3 +12,23 @@ RCC_DIR = $$CHART_BUILD_DIR/tests/$$TARGET # staticlib config causes problems when building executables staticlib: CONFIG-=staticlib + +android { + # Workaround to fix android deployment, which seems to always look for target in + # OUT_PWD instead of DESTDIR. + QMAKE_POST_LINK += $$QMAKE_COPY $$CHART_BUILD_BIN_DIR/lib$${TARGET}.so $$OUT_PWD/lib$${TARGET}.so + + contains(TARGET, qml.*) { + charts_qmldir.files = $$CHART_BUILD_QML_PLUGIN_DIR/qmldir + charts_qmldir.path = /assets/imports/QtCommercial/Chart + charts_qmlplugin.files = $$CHART_BUILD_QML_PLUGIN_DIR/libqtcommercialchartqml.so + charts_qmlplugin.path = /libs/$$ANDROID_TARGET_ARCH + INSTALLS += charts_qmldir charts_qmlplugin + } else:contains(TARGET, quick2.*) { + charts_qmldir.files = $$CHART_BUILD_QML2_PLUGIN_DIR/qmldir + charts_qmldir.path = /assets/qml/QtCommercial/Chart + charts_qmlplugin.files = $$CHART_BUILD_QML2_PLUGIN_DIR/libqtcommercialchartqml2.so + charts_qmlplugin.path = /libs/$$ANDROID_TARGET_ARCH + INSTALLS += charts_qmldir charts_qmlplugin + } +}