diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2024-03-01 16:34:26 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2024-04-14 13:28:59 +0000 |
commit | 39517ef0d0860827b2b96568dd31771d0f4afa2e (patch) | |
tree | 2300fcc843f8c5da3f4da347f35a0dd6087ffa10 /coin/provisioning/common | |
parent | 6941e50a6d684fa4be4bcacc3e5bfba18fe4d7a2 (diff) |
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>
Diffstat (limited to 'coin/provisioning/common')
11 files changed, 171 insertions, 1 deletions
diff --git a/coin/provisioning/common/linux/android/gradle_project/.gitignore b/coin/provisioning/common/linux/android/gradle_project/.gitignore new file mode 100644 index 00000000..aa724b77 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/.gitignore @@ -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 diff --git a/coin/provisioning/common/linux/android/gradle_project/README.md b/coin/provisioning/common/linux/android/gradle_project/README.md new file mode 100644 index 00000000..439cd362 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/README.md @@ -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. diff --git a/coin/provisioning/common/linux/android/gradle_project/app/.gitignore b/coin/provisioning/common/linux/android/gradle_project/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/coin/provisioning/common/linux/android/gradle_project/app/build.gradle b/coin/provisioning/common/linux/android/gradle_project/app/build.gradle new file mode 100644 index 00000000..745c08f8 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/app/build.gradle @@ -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 +} diff --git a/coin/provisioning/common/linux/android/gradle_project/app/src/main/AndroidManifest.xml b/coin/provisioning/common/linux/android/gradle_project/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..492c2115 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/app/src/main/AndroidManifest.xml @@ -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> diff --git a/coin/provisioning/common/linux/android/gradle_project/app/src/main/java/com/example/gradle_project/MainActivity.java b/coin/provisioning/common/linux/android/gradle_project/app/src/main/java/com/example/gradle_project/MainActivity.java new file mode 100644 index 00000000..d3575ef9 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/app/src/main/java/com/example/gradle_project/MainActivity.java @@ -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); + } +} diff --git a/coin/provisioning/common/linux/android/gradle_project/app/src/main/res/layout/activity_main.xml b/coin/provisioning/common/linux/android/gradle_project/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..c75d0576 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/app/src/main/res/layout/activity_main.xml @@ -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> diff --git a/coin/provisioning/common/linux/android/gradle_project/build.gradle b/coin/provisioning/common/linux/android/gradle_project/build.gradle new file mode 100644 index 00000000..602be027 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/build.gradle @@ -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 +} diff --git a/coin/provisioning/common/linux/android/gradle_project/gradle/libs.versions.toml b/coin/provisioning/common/linux/android/gradle_project/gradle/libs.versions.toml new file mode 100644 index 00000000..65bc49af --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/gradle/libs.versions.toml @@ -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] + diff --git a/coin/provisioning/common/linux/android/gradle_project/settings.gradle b/coin/provisioning/common/linux/android/gradle_project/settings.gradle new file mode 100644 index 00000000..ca34c7e7 --- /dev/null +++ b/coin/provisioning/common/linux/android/gradle_project/settings.gradle @@ -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' diff --git a/coin/provisioning/common/linux/android_linux.sh b/coin/provisioning/common/linux/android_linux.sh index 4702e628..fc1a10a4 100755 --- a/coin/provisioning/common/linux/android_linux.sh +++ b/coin/provisioning/common/linux/android_linux.sh @@ -188,6 +188,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="0d91cc866f2799d56911bcdadabebb137eafcea8" +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 |