Android:Coin: do gradle build in provisioning to cache downloadables

If Gradle is not present in the system, it's downloaded from the URL
from the Gradle wrapper. Also, the same for AGP when an Android
project build is done. Currently, that's done on every integration,
and that can be unreliable due to networking flakiness. With this
patch, a Gradle build is done once during provisioning where the
downloads of Gradle and AGP dependencies are downloaded.

Fixes: QTQAINFRA-6166
Fixes: QTQAINFRA-4726
Fixes: QTBUG-117203
Fixes: QTBUG-114699
Change-Id: Ic9fd8aeea3379ca1d45ffeb4523a52e2846fcabb
Reviewed-by: Dimitrios Apostolou <jimis@qt.io>
Reviewed-by: Toni Saario <toni.saario@qt.io>
(cherry picked from commit 39517ef0d0)
This commit is contained in:
Assam Boudjelthia
2024-03-01 16:34:26 +02:00
parent 2366d4f29e
commit 82382f5c69
11 changed files with 171 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties

View File

@@ -0,0 +1,20 @@
# 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

@@ -0,0 +1 @@
/build

View File

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

View File

@@ -0,0 +1,20 @@
<?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="34">
<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

@@ -0,0 +1,16 @@
// 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

@@ -0,0 +1,18 @@
<?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

@@ -0,0 +1,4 @@
// 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

@@ -0,0 +1,16 @@
[versions]
agp = "7.4.1"
appcompat = "1.6.1"
material = "1.11.0"
constraintlayout = "2.1.4"
[libraries]
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

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

View File

@@ -184,6 +184,23 @@ echo "no" | ./avdmanager create avd -n automotive_emulator_x86_64_api_29 -c 2048
# To be used by the VMs to start the emulator for tests
emulator_script_filename="android_emulator_launcher.sh"
cp "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/${emulator_script_filename}" "${HOME}"
scripts_dir_name="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
cp "${scripts_dir_name}/${emulator_script_filename}" "${HOME}"
ANDROID_EMULATOR_RUNNER="${HOME}/${emulator_script_filename}"
SetEnvVar "ANDROID_EMULATOR_RUNNER" "$ANDROID_EMULATOR_RUNNER"
# 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="29a7560041734279bd1e55a79dd973af07a011fa"
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