QT5.15.2 builds Android compilation environment and uses emulator to debug (full)

1. Install QT5.15.2

Address: Download
My computer is Windows, so I choose Windows.

Since the official installation process is very, very slow, you must follow the steps to install it, otherwise it will be so slow that you will doubt your life.
1) Open “Command Prompt” (Start -> Windows System -> Command Prompt) or “win + R” -> enter cmd
Find the exe just now
Enter the following command on the command line (the location of the exe depends on your actual location), and then press Enter

D:\ChromeCoreDownloads\qt-unified-windows-x64-4.6.1-online --mirror https://mirrors.ustc.edu.cn/qtproject


2) Log in to your account (register if you don’t have one)
QT5.15.2 installation options are as follows (next step):
1,

2,

3. (You can choose the installation location you like)

4. Choose the components you like (or just follow me), but Android and sources must be selected.

5.

6. Just follow the next step for other steps and wait for the installation…

2. Installation tools

1. Download the required tools

ps:Password 1234
JDK: Java language software development kit, that is, the sdk used for java development. This time, jdk8 is used (download)
SDK (oftware development kit): Software development kit, a collection of relevant documents, API necessary materials, examples and tools to assist in the development of a certain type of software can be called “SDK”. (download)
(latest download)

openssl: Configuration is optional, but downloading is recommended (download)

2. Installation

0. Create folder

(Take D drive as an example), create a Android_tool folder, and then create two more folders OpenSSL, SDK under it

1. Install JDK

Open jdk-8u371-windows-x64.exe and install it to the c drive by default (just keep going to the next step and operate with your eyes closed)


Install jdk and just keep going to the next step.


If the c drive has these two files, it means the installation is successful.

2. Install SDK

①Copy and decompress the newly downloaded android-sdk_r24.4.1-windows.zip and commandlinetools-win-9123335_latest.zip to “D:\Android_tool\SDK”

②Enter D:\Android_tool\SDK\android-sdk_r24.4.1-windows\android-sdk-windows and open SDK Manager.exe

③Select the tools you need, you can refer to mine (the example uses Android10 Android7.0)




Extras It is recommended to select all, the lack of some components may affect the operation of QT
ps: The installation of the second Android Auto Desktop Head Unit emulator may be unsuccessful, but it doesn’t matter

④Click the install button

⑤All licenses accepted

This is done, then click install and wait for installation…

PS: If avd and sdk may be updated in the middle, then restart the SDK and continue downloading



Download completed!

4. Create simulator avd

① Open AVD Manager.exe

② Create a new simulator (take Android7.0 armeabi-v7a as an example)



Setup is complete.

4. Decompress openssl

① Copy and decompress the android_openssl-master.zip you just downloaded to “D:\Android_tool\OpenSSL”

3. Build QT Android compilation environment

① Open QT5.15.2, find the menu bar -> Edit -> preferences
Open the SDK Manager.exe you just installed and copy the sdk path to QT’s Android SDK path


② Click the Set SDK button
Download SDK toolkit




This completes the installation.

③ QT configure OpenSSL
Put the path to the Openssl file you just decompressed into QT settings


④ Solve Error in Android settings

Many CSDNs have mentioned this reason (please refer to the article https://blog.csdn.net/yy_xzz/article/details/132135255)
The problems that arise are as follows:
×Android SDK Command-line Tools run.
×Android Platform-Tools installed.
The problem shows that the cmdline tools tool has been installed but not running, and the android platform sdk has not been installed. You need to re-download the old version of cmdtools to replace the latest version, and the problem is solved.

So replace all the files in the cmdline-tools folder in the newly decompressed “commandlinetools-win-9123335_latest” to cmdline-tools\latest under sdk


Reopen QT and enter the preference interface just now


Wait for the installation to be completed!

Such an interface means that the configuration is successful.

4. Debugging the first Android example

1. Try to compile for the first time

①Menu bar ->File ->new project…

The project name and path are arbitrary, and the rest are set by default.

②Try to compile


If you encounter any problems, you can continue reading below.

2. Possible problems and solutions for Android QT compilation errors (problems I have encountered)

① There is no scene to effectively deploy the equipment.

Solution:
Create an emulator in AVD Manager.exe. You can turn to the AVD creation tutorial (if you follow this tutorial, this problem will not occur)

②The deployment device “XXXX” does not support the suite architecture
Kit supports arm64-v8a", but device uses "armeabi-v7a,armeabi".

Solution:
Find the kit, find the settings in the build steps and check armabi-v7a

③Problem 1: Missing simulator
The missing emulator tool() has been installed for the installed Android SDK

Solution: Download and install the emulator tool

④ Appears during compilation
# include type traits' file not found
[arm64-v8a mainobj] Error 1

Solution:
1. It may be an NDK problem as mentioned on the Internet. Just change the version.
2. There may be a problem with the build and you need to cancel arm64-v8a.

⑤The compilation process is very slow
Downloading https://services.gradle.org/distributions/gradle-5.6.4-bin.zip is very slow

Solution: Reference
Enter the build directory to find the “build.gradle” file and modify it to

buildscript {<!-- -->
    repositories {<!-- -->
        #google()
        #jcenter()
maven{<!-- -->url'https://maven.aliyun.com/repository/google'}
        maven{<!-- -->url'https://maven.aliyun.com/repository/public'}
    }

    dependencies {<!-- -->
        classpath 'com.android.tools.build:gradle:3.6.0'
    }
}



⑥The compilation process appears
FAILURE:Build failed with an exception.
* Where:
Build file 'D: \XXX\ build-AndroidT1-Qt_5_15_2_Clang_Multi_Abi_59c420-Debug android-build build.gradle` line: 20

Solution: Reference
It’s because the gradle version is too high. Just lower the gradle version and compile it. If you don’t know which version to change to, just create a new project, see what version it is, and just change it to the corresponding version.
Enter the build directory to find the “build.gradle” file, and modify the classpath to your correct version.