Qt Quick in Android as a View

This blog post is the first one in a series where we are going to have a look at one exciting feature coming as a Technology Preview in 6.7.0: the ability to use QML and Qt Quick in your otherwise non-Qt Android apps as an Android View! We've also created an Android Studio plugin to help you keep the workflow simple. In this first post, we'll have an overview of the feature, what it entails, why we are adding it, and where you could benefit from it. In the following posts, we will show how to use it along with some code examples and take a closer look at the tooling, testing, and some possible use cases, such as 3D. 

While it has been possible to deploy a Qt app on Android since Qt 5, that has required you to make your app with Qt first. While that is great if you want the app to be cross-platform, or don't want to delve too deep into Android-specific APIs, there can be some use cases where you cannot go "all in" with Qt. You may be only interested in developing an app for Android and other platforms are not a priority for you, or you may have an existing Android app. Maybe you expect to have to use a lot of Android APIs and aren't thrilled by using JNI to bridge the Android-specific Java or Kotlin code with Qt C++ and QML.  

Even when you want to keep your app an Android app first and foremost, maybe you would like to add things like 3D, animations, and custom-styled elements to your UI – and having Qt Quick makes this a breeze. So, in Qt 6.7.0, we introduced a much-requested feature: you can now use QML to add Qt Quick into your Android app as a View. You can use Java or Kotlin to write your app in Android Studio, have it be just like any other Android app, and just add Qt Quick to where you think it would shine! In case you already have existing QML code from another project and think it would fit nicely in your Android app, too, you can easily add it there.

morphing-example-landscape-3

QtQuick3D Morphing Example embedded into an Android app, with native Android Sliders replacing the Qt Quick ones.

Embedding QWindows into native UIs has been possible on many platforms, but doing it from Java brings an added layer of complexity. So, we have added a new Java class,  QtQuickView, that takes care of the necessary steps for you. It creates a foreign window representing itself and a QQuickView with a given QML source, which it will then parent to itself. It will also load the Qt libraries and set up the Qt runtime. All this happens under the hood, so you don't have to worry about making the JNI calls or monitoring the lifecycles of these windows. All you need to do is add the QtQuickView into your view hierarchy! 

To be able to use this class, you will first need to add Qt to your Android project. We have created an Android Studio plugin to help you do this; check out the documentation to see how to get and use it! The plugin allows you to create and import a Qt Quick Project and integrate it into the Android project's build chain. This plugin saves you the trouble of using Qt Creator to build the Qt project and manually copying the build artifacts, such as libraries, to the Android Project. 

This feature is still in its early phases, but we hope you are excited to give it a go and share your feedback and ideas on how to develop it further with us! In the next post, coming soon, we will go through all the steps of adding your Qt content to an Android Studio project, so stay tuned! 


Blog Topics:

Comments