Android: provision Gradle dependencies for all hosts

Add scripts to download and cache Gradle distribution
and its dependencies during provisioning for all hosts
so that Qt builds don't have to fetch them on every Qt
module and test build.

Add those scripts to various RHEL, Ubuntu, macos and
windows configurations after Android has been run
since the Gradle build for Android requires Android
SDK.

Prior to this, to avoid having a full Gradle project added
to the coin tree, some Gradle files were being fetched from
qtbase using a commit sha, that was aiming to reduce the
amount of changes each time, but that's a bit awkward since
the files here and this commit sha needs to be updated
anyways. So just have a full Gradle project here and update
its values whenever we bump Gradle or Android supported
versions.

Task-number: QTBUG-132915
Change-Id: Id4876ad90a09cdaada5b96c457820c691e2be426
Reviewed-by: Simo Fält <simo.falt@qt.io>
Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
This commit is contained in:
Assam Boudjelthia
2026-04-09 14:48:14 +03:00
parent 7b4a4cf35b
commit 23b2017121
57 changed files with 743 additions and 141 deletions

View File

@@ -1,20 +0,0 @@
# Android Gradle Project for COIN
This project is used to at provisioning time to do an Android Gradle build that
will download Gradle binaries and AGP dependencies, then they will be cached
allowing consecutive builds, i.e. at test runs to not redownload the Gradle
binaries which tend to run into network issues and thus improving the
reliability of the Android integrations on COIN.
The project is a basic empty views Android project that can be created by
Android Studio, it's Java based. Below is some extra details on relevant files
that might need updates in the future:
- settings.gradle: mainly sets the the project name
- under app/src/main/ res/layout/activity_main.xml and src/*/*.java: sets the
layout and logic of the app, this shouldn't need to be touched.
- AndroidManifest.xml / app/build.gradle: Sets project settings like target version.
- gradle/libs.versions.toml: This sets the version numbers of various dependencies.
Other files required for the project build are gradle wrapper and scripts which
are fetched by android_linux.sh from qtbase.

View File

@@ -1,27 +0,0 @@
plugins {
alias(libs.plugins.androidApplication)
}
android {
namespace 'com.example.gradle_project'
compileSdk 36
defaultConfig {
applicationId "com.example.gradle_project"
minSdk 28
targetSdk 36
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}
dependencies {
implementation libs.core
implementation libs.appcompat
implementation libs.material
}

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:label="gradle_project"
android:supportsRtl="true"
tools:targetApi="36">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -1,16 +0,0 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
package com.example.gradle_project;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

View File

@@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,4 +0,0 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.androidApplication) apply false
}

View File

@@ -1,17 +0,0 @@
[versions]
agp = "9.0.0"
core = "1.17.0"
appcompat = "1.7.1"
material = "1.13.0"
constraintlayout = "2.2.1"
[libraries]
core = { group = 'androidx.core', name = "core", version.ref = "core" }
appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
[bundles]

View File

@@ -1,17 +0,0 @@
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "gradle_project"
include ':app'

View File

@@ -255,19 +255,3 @@ SetEnvVar "ANDROID_EMULATOR_RUNNER" "$ANDROID_EMULATOR_RUNNER"
SetEnvVar "PATH" "\$PATH:$sdkTargetFolder/emulator"
SetEnvVar "PATH" "\$PATH:$sdkTargetFolder/platform-tools"
SetEnvVar "PATH" "\$PATH:$sdkTargetFolder/cmdline-tools/latest/bin"
# Gradle Caching
cp -r "${scripts_dir_name}/android/gradle_project" /tmp/gradle_project
cd /tmp/gradle_project
# Get Gradle files from qtbase
qtbaseGradleUrl="https://code.qt.io/cgit/qt/qtbase.git/plain/src/3rdparty/gradle"
commit_sha="b775c756f019d067c491bad7816f3a0cc8ea8b31"
curl "$qtbaseGradleUrl/gradle.properties?h=$commit_sha" > gradle.properties
curl "$qtbaseGradleUrl/gradlew?h=$commit_sha" > gradlew
curl "$qtbaseGradleUrl/gradlew.bat?h=$commit_sha" > gradlew.bat
mkdir -p gradle/wrapper
curl "$qtbaseGradleUrl/gradle/wrapper/gradle-wrapper.jar?h=$commit_sha" > gradle/wrapper/gradle-wrapper.jar
curl "$qtbaseGradleUrl/gradle/wrapper/gradle-wrapper.properties?h=$commit_sha" > gradle/wrapper/gradle-wrapper.properties
# Run Gradle
chmod +x gradlew
ANDROID_SDK_ROOT="$sdkTargetFolder" sh gradlew build

View File

@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Copyright (C) 2026 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
set -ex
# shellcheck source=../unix/DownloadURL.sh
source "${BASH_SOURCE%/*}/../unix/DownloadURL.sh"
# shellcheck source=../unix/SourceEnvVars.sh
source "${BASH_SOURCE%/*}/../unix/SourceEnvVars.sh"
echo "Caching Gradle distribution and dependencies"
gradleCacheFileName="gradle_9.3.1_linux_cache.tar.gz"
gradleCacheUrl="http://ci-files01-hki.ci.qt.io/input/gradle/$gradleCacheFileName"
gradleCacheSha1="b054e7366552e81023c9c240d3134967233defac"
gradleCacheFile="/tmp/$gradleCacheFileName"
DownloadURL "$gradleCacheUrl" "$gradleCacheUrl" "$gradleCacheSha1" "$gradleCacheFile"
mkdir -p "$HOME/.gradle"
tar -xzf "$gradleCacheFile" -C "$HOME/.gradle" --strip-components=1
rm "$gradleCacheFile"
gradle_project_source="${BASH_SOURCE%/*}/../shared/gradle/project"
cp -r "$gradle_project_source" /tmp/gradle_project
cd /tmp/gradle_project
chmod +x gradlew
sh gradlew build