Qt5.15.2 Android Android project development environment configuration

1、Qt Creator 4.11.2

Official download: https://download.qt.io/archive/qtcreator/4.11/4.11.2/

Mirror download: https://mirrors.cloud.tencent.com/qt/archive/qtcreator/4.11/4.11.2/

2、Qt 5.15.2 Android

Official updater internal download

Reference: https://blog.csdn.net/weixin_41013202/article/details/129957693

3、JDK 8

https://adoptium.net/zh-CN/temurin/releases/

4. The following are downloaded inside Android Studio:

(1) Android SDK Platform latest version (now 33)

(2) Android SDK Build-Tools latest version (now 33.0.2), 30.0.3

(3) GDR 21.4

(4)Android SDK Command-line Tools (latest)

(5)Android SDK Platform-Tools

(6) Google USB Driver (for real machine debugging, download this, and for virtual machine debugging, download Emulator)

5. .pro file

(1) Use the latest C++ standard supported by the compiler (201707)

CONFIG += c++latest

(2) Set up SDK

ANDROID_MIN_SDK_VERSION = 24 # Android 7.0

ANDROID_TARGET_SDK_VERSION = 33 # Android 13

Reference for other SDK version numbers: https://developer.android.google.cn/studio/releases/platforms?hl=zh-cn

6. AndroidManifest.xml file

(1) Version name: "1.0" version number format

(2) Version code: Write whatever you want

(3) Application name and Activity name: Application name

7. Gradle settings

(1) C:/Users/your username/.gradle/gradle.properties:

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Fri May 26 17:03:24 CST 2023
systemProp.http.proxyHost=
systemProp.http.proxyPort=80
systemProp.https.proxyHost=
systemProp.https.proxyPort=80

(2) C:/Users/your username/.gradle/init.gradle:

allprojects {
    buildscript {
        repositories {
            mavenLocal()
            maven { url 'https://mirrors.cloud.tencent.com/maven/' }
            maven { url 'https://maven.aliyun.com/repository/central/' }
            maven { url 'https://maven.aliyun.com/repository/public/' }
            maven { url 'https://maven.aliyun.com/repository/google/' }
            maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
            maven { url 'https://maven.aliyun.com/repository/spring/' }
            maven { url 'https://maven.aliyun.com/repository/spring-plugin/' }
            maven { url 'https://maven.aliyun.com/repository/grails-core/' }
            maven { url 'https://maven.aliyun.com/repository/apache-snapshots/' }
            mavenCentral()
        }
    }

    repositories {
        mavenLocal()
        maven { url 'https://mirrors.cloud.tencent.com/maven/' }
        maven { url 'https://maven.aliyun.com/repository/central/' }
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
        maven { url 'https://maven.aliyun.com/repository/spring/' }
        maven { url 'https://maven.aliyun.com/repository/spring-plugin/' }
        maven { url 'https://maven.aliyun.com/repository/grails-core/' }
        maven { url 'https://maven.aliyun.com/repository/apache-snapshots/' }
        mavenCentral()
    }
}

(3) Project directory/android/build.gradle:

buildscript {
    repositories {
        mavenLocal()
        maven { url 'https://mirrors.cloud.tencent.com/maven/' }
        maven { url 'https://maven.aliyun.com/repository/central/' }
        maven { url 'https://maven.aliyun.com/repository/public/' }
        maven { url 'https://maven.aliyun.com/repository/google/' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
        maven { url 'https://maven.aliyun.com/repository/spring/' }
        maven { url 'https://maven.aliyun.com/repository/spring-plugin/' }
        maven { url 'https://maven.aliyun.com/repository/grails-core/' }
        maven { url 'https://maven.aliyun.com/repository/apache-snapshots/' }
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
    }
}

repositories {
    mavenLocal()
    maven { url 'https://mirrors.cloud.tencent.com/maven/' }
    maven { url 'https://maven.aliyun.com/repository/central/' }
    maven { url 'https://maven.aliyun.com/repository/public/' }
    maven { url 'https://maven.aliyun.com/repository/google/' }
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin/' }
    maven { url 'https://maven.aliyun.com/repository/spring/' }
    maven { url 'https://maven.aliyun.com/repository/spring-plugin/' }
    maven { url 'https://maven.aliyun.com/repository/grails-core/' }
    maven { url 'https://maven.aliyun.com/repository/apache-snapshots/' }
    mavenCentral()
}

apply plugin: 'com.android.application'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}

android {
    /*******************************************************
     * The following variables:
     * - androidBuildToolsVersion,
     * - androidCompileSdkVersion
     * - qt5AndroidDir - holds the path to qt android files
     *                   needed to build any Qt application
     *                   on Android.
     *
     * are defined in gradle.properties file. This file is
     * updated by QtCreator and androiddeployqt tools.
     * Changing them manually might break the compilation!
     *******************************************************/

    compileSdkVersion androidCompileSdkVersion.toInteger()

    buildToolsVersion '30.0.3'

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
            aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
            res.srcDirs = [qt5AndroidDir + '/res', 'res']
            resources.srcDirs = ['resources']
            renderscript.srcDirs = ['src']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
       }
    }

    tasks.withType(JavaCompile) {
        options.incremental = true
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        abortOnError false
    }

    // Do not compress Qt binary resources file
    aaptOptions {
        noCompress 'rcc'
    }

    defaultConfig {
        resConfig "en"
        minSdkVersion = qtMinSdkVersion
        targetSdkVersion = qtTargetSdkVersion
    }
}

(4) Project directory/android/gradle/wrapper/gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

8. Build directory

(1) It is recommended to change the name of the build directory to a shorter one, because if the folder name is too long, it will not compile.

9. Code testing

(1) Output the C++ standard used by the compiler (201707)

qDebug() << __cplusplus;

10. Error reporting and resolution

(1) If an error "android:exported..." is reported during the compilation process, add android:exported="true" to the <activity> of the AndroidManifest.xml file:

<activity android:exported="true" ............

Guess you like

Origin blog.csdn.net/weixin_41013202/article/details/131011297