I keep working on my Lines Game and probably I try to make it the best Lines Game in the world, but there is some disappointing incident that prevents it from being the best and makes it a usual game that glitches a bit. To see the glitch in action download the beta version of the game.
Adding Interstitial Ads to a QT application on Android platform is an interesting and relatively exciting job. I learned the following facts while doing it:
- To build my app with Google Play Services I add com.google.android.gms:play-services-ads:18.1.1 dependency to build.gradle and add com.google.android.gms.version and com.google.android.gms.ads.APPLICATION_ID to the manifest.
- I do not specify additional permissions (uses-permission attributes INTERNET, WRITE_EXTERNAL_STORAGE, ACCESS_NETWORK_STATE) required by ads, but they are detected automatically when I upload the app to Google Play store and the used is not prompted to allow them when the app starts.
- QT main thread (on which QML UI is run) is not Android UI thread. So I cannot call Java advertising API from QML or C++ directly, but all the calls should be queued with runOnUiThread method.
- To access Context required by Java advertising API I replace QtActivity with my own custom activity that implements all the advertising logic and forwards all the lifecycle events to original QtActivity.
- When the interstitial ad is open my activity is paused and stopped (onPaused / onStopped event handlers are called in Java and onApplicationStateChanged with Qt::ApplicationInactive / Qt::ApplicationSuspended respectively ) and when the interstitial ad is closed my activity is resumed but in different ways either with onRestart.
I tried to build QT 5.11.1 for Android on Windows, and “configure.bat” completed successfully, but “mingw32-make” failed with with the following error:
No rule to make target 'vulkan/qvulkanfunctions_p.h', needed by '.obj\qvulkaninstance.obj'.
It is the bug fixed in QT 5.11.2 that is planned on August/September 2018.
When I build the master branch and copied the following files from it to \qtbase\src\gui\vulkan manually:
and started “mingw32-make” again I got another error:
First I installed Android Studio. When it started I set an option to create the application with Native C++ support and Android NDK was automatically installed to C:\Users\AppData\Local\Android\Sdk\ndk-bundle, also I added Android-19 API level and somehow CMake was installed to C:\Users\AppData\Local\Android\Sdk\cmake\3.6.4111459. Then in QT Creator I opened Tools->Options->Devices->Android and specified the following paths:
If Android support is enabled in MS VS2015, it installs Android SDK without Google Play Services and I did not find an option in SDK Manager that installs them. When I started “C:\Program Files (x86)\Android\android-sdk\SDK Manager.exe” with admin privileges, it automatically offered to install some 9 packages:
Below I provided parameters of three Android phones I tested my Lines game with:
Screen Resolution column contains the information in the following format: <logical resolution> (<physical resolution>/<physical height available for applications in portrait orientation>.
DPIs with ‘~’ sign are measured manually because QT (or some Android API) provides incorrect Screen Size.
VS2015 has an exciting ability to debug a C++ application on Android Emulator, but in this article I will talk about no less exciting and more time expensive ability to debug a C++ application on a real Android device. The first thing we need to spend the time with is figuring out how to enable USB debugging mode on our Android device. On my ASUS Zenfone I need to go to Settings->About->Software Information and tap on Build Number 7 times, after that I have USB debugging check box in Settings->Developer Options that I should tap as well:
Cross platform (Android, iOS, UWP) OpenGLES 2 application can be easily created in VS2015 using “OpenGLES 2 Application (Android, iOS, Windows Universal)” project template: