Getting QT Creator Working for Android Development – First Steps

  • report
    Disclaimer
    Click for Disclaimer
    This Post is over a year old (first published about 5 years ago). As such, please keep in mind that some of the information may no longer be accurate, best practice, or a reflection of how I would approach the same thing today.
  • infoFull Post Details
    info_outlineClick for Full Post Details
    Date Posted:
    Mar. 11, 2019
    Last Updated:
    Mar. 13, 2019
  • classTags
    classClick for Tags

This post was written as I worked through trying to get QT Creator to be able to, at the very least, build and run an example project for Android and see it on an emulator.

 

Errors encountered:

  • “Android build SDK not defined”
    • Under “Projects > Active Project > Build” you need to specify which Android Build APK to target / build for
      • If this dropdown is empty, it probably means that your SDK configuration is not set up properly. See below, and if you are using Android Studio, you might need to try manually downloading and installing the Android SDK separately on your hard drive
  • For “Select Android Device” when trying to run app, AVD emulator shows under “Incompatible Devices”, with “API Level of device is: -1”
    • I think that, at least in my situation, this was due to a XML mismatch between what avdmanager generates and what QTCreator is expecting. It looks like for older versions of the Android API, the AVD XML config file does not have the “AvdId” property, whereas newer ones do (or maybe it was because I created my new AVD from the command line avdmanager instead of Android Studio). Either way, it looks like QT needs “AvdId” to be in the XML file for it to parse it correctly.
      • You can find your generated AVD config XML file under C:\Users\[USERNAME]\.android\avd\[AVD_ID]
      • I simply added the missing AvdId property to my XML file that matched the ID and the folder name
      • Afterward, the AVD instance started showing under compatible devices, although in the Devices panel it still shows with “AVD Target: API -1” which is not correct.
  • Under “Build Settings > Build Steps > Build Android APK”, only SDK version 25 (“android-25”) appears selectable in the “Android Build SDK Dropdown”
    • After installing a new SDK, either through the QT GUI or the sdkmanager, I had to reset my SDK path field to get QT Creator to re-scan the directory, then completely close and open QT creator back up again
    • Also, make sure you have installed both the emulator image, as well as the “SDK Platform” under the android version you want
  • When trying to run on an emulator generated by Android Studio, you get this “AVD Start Error” : “emulator: ERROR: unknown skin name ‘nexus_5x’
    • Similar to another issue, this seems to be something to do with how QT parses android config files vs how Android Studio does. You need to find the “config.ini” file that goes with your emulator instance. For example, if you are trying to get the default Android Studio x86 emulator running, it might be at something like “C:\Users\Joshua\.android\avd\Nexus_5X_API_28_x86.avd\config.ini”
      • Open it, and look for the line with the keypair of “skin.path”. It probably looks like “skin.path=skins\nexus_5x”. You will want to change this to point to the actual full path of the skin, like “skin.path=C:\Users\Joshua\AppData\Local\Android\Sdk\skins\nexus_5x”
  • When trying to run on my actual Android phone, not the emulator, my phone shows up under “incompatible devices”, with a message about “ABI is incompatible”
    • In my case, I had selected the kit to target Android x86, but my phone (a OnePlus 2) has an ARM 64 processor. I just had to switch my kit before running and then it worked!
  • When trying to use any QtQuick submodules (e.g. qtquick.controls) I would get an error in my QML like “QML module not found (QtQuick.Controls)

    • This is probably an indicator that my kits are set up incorrectly, as QT *should* be able to automatically resolve QML dependencies for Android vs Desktop, but for whatever reason, in my case, it is not. I had to add conditional sections to my project/qmake file that modifies the QML_IMPORT_PATH variable to pull in the right QML sources based on Android version (based on tip here). See below:
    • # Android specific build settings
      android {
          log("ANDROID_TARGET_ARCH=")
          log($${ANDROID_TARGET_ARCH})
          equals(ANDROID_TARGET_ARCH, armeabi-v7a) {
              #[doAndroidArmStuff]
              QML_IMPORT_PATH += C:/Qt/5.12.1/android_armv7/qml
              QML_IMPORT_PATH += C:/Qt/5.12.1/android_armv7/qml/QtQuick
          }
          equals(ANDROID_TARGET_ARCH, arm64-v8a) {
              #[doAndroidArmStuff]
              QML_IMPORT_PATH += C:/Qt/5.12.1/android_arm64_v8a/qml
              QML_IMPORT_PATH += C:/Qt/5.12.1/android_arm64_v8a/qml/QtQuick
          }
          equals(ANDROID_TARGET_ARCH, armeabi) {
              #[doAndroidArmeabiStuff]
          }
          equals(ANDROID_TARGET_ARCH, x86)  {
              #[doAndroidx86Stuff]
              QML_IMPORT_PATH += C:/Qt/5.12.1/android_x86/qml
              QML_IMPORT_PATH += C:/Qt/5.12.1/android_x86/qml/QtQuick
          }
      }

Pre-requirements

  • Download and install Android Studio, since that will auto-install a bunch of helpful tools and emulators
  • Download and Install the Java JDK
    • Right now, version 8 works, whereas >8 breaks
    • Make sure to set windows user var JAVA_HOME to this path
  • Create a root level folder for easy access – C:/Android
    • Manually download the Android NDK and install there, like “C:\Android\ndk\android-ndk-r19b”
    • If you want to manually install Android SDK here, create C:\Android\sdk
      • Now, download and extract the command line SDK tools download from Google (the one that contains the sdkmanager)
      • Navigate to sdkmanager (should be under c:\Android\sdk\tools\bin after you extracted) and in cmd prompt, run “sdkmanager “platforms;android-25” or whatever version of the SDK you want to install

Setup

Now, go to Qt Creator > Tools > Options > Devices, and under “Android”, plug in the necessary paths (Java JDK, Android NDK & SDK)

QT Creator - Devices - Java and Android Settings

  • QT should automatically create kits for you and detect installed Android Platforms / Emulators
  • If you are using a manual SDK path outside of Android Studio, QT will also prompt you to auto-download and install extra tools it needs
    • However, it won’t install emulator stuff automatically…
    • It won’t auto download the emulator process, so make sure you check the install box for “Android Emulator”
    • it won’t auto download an emulator image, so you need to go to the “SDK Manager” tab and install at least one system image to use as an emulator (with AVD Manager). You usually want “Google APIs Intel x86 Atom System Image”
      • For example, here I have download an Android 7.1 image, and then created an AVD for it
      • QT Creator - SDK Manager for Android
      • QT Creator - GUI for Creating a new AVD targeting android-25
    • If the QT avd manager is not working (it wasn’t for me) you can manually provision with the cmd tool for it. This command is functionally equivalent to the result of the dialog above
      • avdmanager create avd -n “Android_a25_s7.1_x86” -k “system-images;android-25;google_apis;x86” -c 400M

Leave a Reply

Your email address will not be published.