Setting up Qt 6 for Android Development on Mac

Setting up Qt 6 for Android Development on Mac

Configure Android Environment

You can also configure it using Android Studio. The advantage is the use of a GUI, although it takes up a significant amount of space.

Configure JDK

Here, you can directly download it using brew.

1
brew install openjdk@17

Note that for Apple Silicon, the default path for the JDK downloaded via brew is

1
/opt/homebrew/opt/openjdk@17

You will need this path for later use. As for setting environment variables, add the following configuration to your .bashrc file:

1
2
export JAVA_HOME="/opt/homebrew/opt/openjdk@17"  # For Apple Silicon
export PATH="$JAVA_HOME/bin:$PATH"

Configure Android Environment via Creator

If your network conditions allow, you can use Qt Creator to automatically complete the installation.

Go to Devices - Android in Qt Creator.

image-20250308162742407

In Qt Creator, set the JDK location to the path where you installed the JDK via brew. Then, click on the SDK settings below. Qt Creator will detect and begin automatically installing any missing packages.

image-20250308163059027

image-20250308163105265

Follow the instructions to complete the setup.

image-20250308163107924

The result is:

image-20250308164215256

image-20250308164218601

Here, it’s important to note the correspondence between the JDK version and the cmdline tools. Qt Creator actually controls the Android SDK through the cmdline tools, but the cmdline tools are highly dependent on the JDK version. If your version is incorrect, you may encounter issues like these.

Additionally, Qt Creator also configures OpenSSL in the process.image-20250308164446236

Manually Configure Using the sdkmanager Command Line Tool

If the installation via Qt Creator fails, you can also complete the installation manually. This section serves as a guide, but the official documentation is already quite comprehensive. Visit the Android official site and download only the command line tools package.

image-20250308111930417

For detailed instructions on configuring the command line tools, see sdkmanager | Android Studio | Android Developers.

The main steps are as follows:

image-20250308112107209

My path is as follow

1
/Users/wadaxiyang/Library/Android/sdk

image-20250308160544242

Through similar commands, you can download the corresponding platform-tools, etc. This process is essentially the same as what Qt Creator does.

1
./sdkmanager "platform-tools" "platforms;android-33" --proxy_host=127.0.0.1 --proxy_port=9908 --proxy=http

Configure Android Virtual Machine

In fact, Qt Creator can also directly configure an Android virtual machine.

image-20250308165921399

Install image

image-20250308170250522

image-20250308165646023

image-20250308165704104

Connfig the AVD

image-20250308174812747

And start AVD

image-20250308174940137

Deploy to AVD

The installation process for Qt for Android is omitted here. You can refer to macOS Install Latest qt6_qt6 for Mac - CSDN Blog, which is well-written.

Use the official example to verify the setup.

image-20250308195316944

image-20250308195423549

Set up the emulator, noting that you need to start the AVD first.

image-20250308195951047

Running result

image-20250308200038597

Deploy to a Physical Device

Deploying to a physical device via USB is very similar to using AVD. Here, we mainly focus on signing the apk to enable direct installation.

image-20250308201727722

Follow the prompts to create and select accordingly.

image-20250308201912872

Afterwards, build to generate the apk in the corresponding directory. Note that the version I am providing here is the release version.

image-20250308202343260

Result

d2a775cde896ebd2e2f1b9c57348f1b8_720