A guide to compile QGC Android

Hi I am new to QT and fairly new to programming as well. So sorry if I am not understanding the jargon. Now coming to the issue.
I am trying to compile the QgroundControl code for android.

Things I have done:
I have set up VDM in android studio
I have set up the android environment (JDK 21 NDK 21.3.6528147 SDK 11)

When compiling qmake and make steps seems to get excecuted properly without errors.
Problem is the Build Android APK
I have mostly followed all instructions in Overview · QGroundControl Developer Guide and the desktop version compiles no problem

I am really lost here, would be nice if anyone can help/point me to a helpful source

Yeah, good luck there. I’ve been trying to compile the android version for many months with only limited success.
Fact is the whole Android side is completely outdated:

  • Mismatch of Java version required from build to what is in use these days.
  • Outdated Gradle version.
  • Finally you’ll get a password related error when trying to build the APK package. (Once again due to mismatch of Java versions)

There are many such reports on here with some helpful answers but haven’t found anything providing full step by step guidance.

My own work-around:
Building Android version in QT until same error as you’ve got pops up. Then closing project and re-opening in Android Studio. This will usually trigger a Gradle upgrade which I proceed with and then finalize the APK build. - But sometimes the essential Android build package hasn’t been created in QT so this work-around won’t work either.

(Desktop versions build easier)

Hey Karl,

Thank you for your reply.
If you dont mind me asking what versions of everything you use to compile it after the gradle update.
Could you maybe post a picture of your preferences page and “build apk” details in QT

Thank you

The gradle update happens in Android Studio. From my experience don’t go past 7.6
(It starts with an upgrade to around 4.6, but if you refresh or re-load project it will offer to upgrade further)

My current QT was set to use Java 8 for the Android build kit as this was originally the requirement by QGC. However, I have, also managed to build with Java 11 (as currently stated in the QGC build instructions)

There are various versions of QGC (Android) already out there. Do you require your own build?

Yes, I need to do some modifications of the software and need that apk version. Have been trying for a week with no luck( but for now I am just trying to compile the stable daily build.) . Thank you for your settings ill try this out

I am sorry for disturbing.

I think I didn’t correctly use JDK 11 and ndk 19
I am now getting a new error in the make step.
But now I have JDK 11 and used Command line version 10 (only then JDK 11 works in QT)

the make step compiles successfully if NDK is set to version 21.

Any help is appreciated

Also replying to your previous comment . What do you mean reopen it in Android studio

In my case I did use NDK 21 as the 19 version keeps failing.
Both your screenshots indicate that you’ve used NDK 19. → Try NDK 21 instead.
Also stick with JDK 11 or no higher than 17.

Re. Android Studio:
I have also Android Studio installed and when the apk build fails in QT I close the project in Qt and start Android Studio and then load the project to finish apk build in there.

  • However, this only works if the Android build packages have been already created within QT.

Hey Karl,
I did what you said. compiled successfully but the apk didnt build on qt.
So I opened android studio, and I used the option import project(build.gradle …).
The android-build dir created a build.gradle file (so I assume this is how you import your project to android studio)

After which I was greeted by a java mismatch error which I managed to solve by installing newer gradle version 7.5 for this example.

Now I am getting this error seems to be related to line 37. Did you get this error ? Again many thanks

Looks to me that the Android Studio SDK hasn’t been installed as required.

But you could also google the error message and see what comes up. May just not be referenced internally in your OS.
If it is a Windows computer, have you re-started computer since installation of Android Studio?

Other than that looks like it is doing what it is supposed to do.

Hey Karl, I think I am really close to getting a workable apk. That being said let me tell you where I am at

These are the changes I did…

  1. I did a clean pull from git
  2. I created a folder named ANDROID_PACKAGE_SOURCE_DIR and copied the AndroidManifest.xml which exists in the repo.
  3. Now when I build it I get this error.

I think it would be help to show the changes I did in AndroidManifest.xml file.

I managed to get an apk tho but it just keeps crashing

Great, I think you’re there.

I assume you are talking about crashing using the emulator ?

  • I’ve never managed to get any of my apk’s working on the emulator, but they all seem to work fine on an actual device. ( I think it’s due to the fact that QGC is trying to communicate with the com ports but those are not there in the emulator)

Re. second screenshot. I’ve noticed you’ve got your build set for API 25. This is only useful for devices running up to Android 7. → Recommend changing that to API 32 in your build settings. (More files will have to be downloaded, but once installed can be used for future builds.)

Did you pull from master or stable ? …I’ve got in the past caught out with the master when someone had made changes but didn’t do any testing after. → Perhaps better sticking with stable branch.

Re. error: I think its a rather minor thing and may be linked to what I was saying above in regards to master branch.
I had similar issue as well once and simply stuck an icon in that folder with the name the build is looking for. → Important: Just adding a file to a folder might not work. Within QT you may have to right click on build tree and then select "Add File/Folder to build tree.

I am unsure of this distinction. I usually use this

git clone --recursive -j8 https : // github. com/mavlink/qgroundcontrol.git

could you tell me where is the stable version ?

Yeah I’ll do this, Keeping the min api level to 7 should still make it work on Android 7 I assume.

This probably is the problem, I’ll try out on my remote and update.

To clone stable version:

git clone --recursive -j8 GitHub - mavlink/qgroundcontrol: Cross-platform ground control station for drones (Android, iOS, Mac OS, Linux, Windows) --single-branch --branch Stable_V4.3

Hey Karl,

Thank you for your help I was able to compile it and deploy it. Also I was able to run it on my virtual machine as well as my device. Since there is very less resource on how to compile I’ll give a summary of the way I did it.

  1. Install this package Version 5.15.2
  2. Install Android Studio
  3. Configure Android environment in QT: How?
    i. Install JDK 11 - https://adoptium.net/temurin/releases/?arch=x64&package=jdk&version=11&os=windows and choose that location for JDK in QT
    ii For SDK location, go to SDK Manager in Android Studio copy the path shown there.
    iii Click Set up SDK and it will install necessary files required.
    If you have red after this follow this step
    open Android Studio> SDK Manager > SDK tools > (Check Show package Details ) > install Command line tools version 10.
    Go to the sdk folder>cmdline-tools> rename 10 to latest
    close qt open and it should work now (atleast it worked for me!)
  4. change your AndroidManifest.xml File inside QT
  5. Create a folder in your debug folder called ANDROID_PACKAGE_SOURCE_DIR and copy the androidManifest.xml file in there.
  6. Check the correct arch you need default is (arm v8)
  7. Now try to build, Hopefully it should run!