From cde861627b734b6bbe4d30637b79d4f011273303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Tue, 15 Oct 2024 10:49:27 +0200 Subject: [PATCH] Improve build process --- .gitlab-ci.yml | 42 ++++++--- android/.gitignore | 4 +- android/app/build.gradle | 90 ++++++++++--------- android/app/src/debug/AndroidManifest.xml | 6 +- android/app/src/main/AndroidManifest.xml | 23 ++++- .../org/benoitharrault/memory/MainActivity.kt | 5 ++ .../res/drawable-v21/launch_background.xml | 10 +++ .../app/src/main/res/values-night/styles.xml | 9 ++ android/app/src/profile/AndroidManifest.xml | 6 +- android/build.gradle | 4 +- android/gradle.properties | 4 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- android/settings.gradle | 9 +- .../metadata/android/en-US/changelogs/27.txt | 1 + .../metadata/android/fr-FR/changelogs/27.txt | 1 + pubspec.yaml | 2 +- 16 files changed, 137 insertions(+), 81 deletions(-) create mode 100644 android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt create mode 100644 android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 android/app/src/main/res/values-night/styles.xml create mode 100644 fastlane/metadata/android/en-US/changelogs/27.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/27.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 24c8063..8160b8f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,14 +23,27 @@ android:build-debug: - echo keyAlias=$ANDROID_DEBUG_KEY_ALIAS >> android/key.properties - echo keyPassword=$ANDROID_DEBUG_KEY_PASSWORD >> android/key.properties # build flutter app + - VERSION_NAME="$(grep '^version:' pubspec.yaml | cut -d' ' -f2 | cut -d'+' -f1)" + - echo "${VERSION_NAME}" + - VERSION_CODE="$(grep '^version:' pubspec.yaml | cut -d' ' -f2 | cut -d'+' -f2)" + - echo "${VERSION_CODE}" - flutter packages get - flutter clean + - flutter build apk --debug --split-per-abi - flutter build apk --debug # prepare artifact - - find . -name "*.apk" # where is my apk? + - BASE_APK_FOLDER="build/app/outputs/flutter-apk" + - APP_NAME="$(grep 'namespace' android/app/build.gradle | cut -d'"' -f2)" + - > + if [ "$(find "${BASE_APK_FOLDER}" -name "*.apk")" != "" ]; then + for APK in ${BASE_APK_FOLDER}/*.apk; do + mv -v "${APK}" "$(echo "${APK}" | sed "s|\.apk|_${VERSION_CODE}.apk|" | sed "s|/app-|/${APP_NAME}-|")" + done + fi + - find "${BASE_APK_FOLDER}" -name "*.apk" # where are my apk? artifacts: paths: - - build/app/outputs/apk/debug + - build/app/outputs/flutter-apk expire_in: 1 week interruptible: true @@ -52,9 +65,12 @@ android:build-release: - echo keyAlias=$ANDROID_KEY_ALIAS >> android/key.properties - echo keyPassword=$ANDROID_KEY_PASSWORD >> android/key.properties # build flutter app - - VERSION_FILE="$(find . -name 'gradle.properties' | head -n1)" - - VERSION_NAME="$(grep '^app.versionName=' "${VERSION_FILE}" | cut -d'=' -f2)" - - VERSION_CODE="$(grep '^app.versionCode=' "${VERSION_FILE}" | cut -d'=' -f2)" + - BASE_APK_FOLDER="build/app/outputs/flutter-apk" + - echo "${BASE_APK_FOLDER}" + - mkdir -p "${BASE_APK_FOLDER}" + - VERSION_NAME="$(grep '^version:' pubspec.yaml | cut -d' ' -f2 | cut -d'+' -f1)" + - VERSION_CODE="$(grep '^version:' pubspec.yaml | cut -d' ' -f2 | cut -d'+' -f2)" + - APP_NAME="$(grep 'namespace' android/app/build.gradle | cut -d'"' -f2)" - TAG_NAME="Release_${VERSION_NAME}_${VERSION_CODE}" - echo "${TAG_NAME}" - > @@ -63,13 +79,20 @@ android:build-release: else flutter packages get flutter clean + flutter build apk --release --split-per-abi flutter build apk --release fi # prepare artifact - - find . -name "*.apk" # where is my apk? + - > + if [ "$(find "${BASE_APK_FOLDER}" -name "*.apk")" != "" ]; then + for APK in ${BASE_APK_FOLDER}/*.apk; do + mv -v "${APK}" "$(echo "${APK}" | sed "s|\.apk|_${VERSION_CODE}.apk|" | sed "s|/app-|/${APP_NAME}-|")" + done + fi + - find "${BASE_APK_FOLDER}" -name "*.apk" # where are my apk? artifacts: paths: - - build/app/outputs/apk/release + - build/app/outputs/flutter-apk expire_in: 1 week interruptible: true @@ -89,9 +112,8 @@ application:release: - git config user.email "${GITLAB_USER_EMAIL}" - git config user.name "${GITLAB_USER_NAME}" - git remote set-url origin https://oauth2:${GITLAB_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH} - - VERSION_FILE="$(find . -name 'gradle.properties' | head -n1)" - - VERSION_NAME="$(grep '^app.versionName=' "${VERSION_FILE}" | cut -d'=' -f2)" - - VERSION_CODE="$(grep '^app.versionCode=' "${VERSION_FILE}" | cut -d'=' -f2)" + - VERSION_NAME="$(grep '^version:' pubspec.yaml | cut -d' ' -f2 | cut -d'+' -f1)" + - VERSION_CODE="$(grep '^version:' pubspec.yaml | cut -d' ' -f2 | cut -d'+' -f2)" - TAG_NAME="Release_${VERSION_NAME}_${VERSION_CODE}" - echo "${TAG_NAME}" - > diff --git a/android/.gitignore b/android/.gitignore index 0a741cb..55afd91 100644 --- a/android/.gitignore +++ b/android/.gitignore @@ -7,5 +7,7 @@ gradle-wrapper.jar GeneratedPluginRegistrant.java # Remember to never publicly share your keystore. -# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app +# See https://flutter.dev/to/reference-keystore key.properties +**/*.keystore +**/*.jks diff --git a/android/app/build.gradle b/android/app/build.gradle index 356f26f..78cd598 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -4,32 +4,6 @@ plugins { id "dev.flutter.flutter-gradle-plugin" } -def localProperties = new Properties() -def localPropertiesFile = rootProject.file('local.properties') -if (localPropertiesFile.exists()) { - localPropertiesFile.withReader('UTF-8') { reader -> - localProperties.load(reader) - } -} - -def gradleProperties = new Properties() -def gradlePropertiesFile = rootProject.file('gradle.properties') -if (gradlePropertiesFile.exists()) { - gradlePropertiesFile.withReader('UTF-8') { reader -> - gradleProperties.load(reader) - } -} - -def appVersionCode = gradleProperties.getProperty('app.versionCode') -if (appVersionCode == null) { - appVersionCode = '1' -} - -def appVersionName = gradleProperties.getProperty('app.versionName') -if (appVersionName == null) { - appVersionName = '1.0' -} - def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { @@ -37,41 +11,69 @@ if (keystorePropertiesFile.exists()) { } android { - compileSdkVersion 34 - namespace "org.benoitharrault.memory" + namespace = "org.benoitharrault.memory" + compileSdk = flutter.compileSdkVersion + ndkVersion = flutter.ndkVersion - sourceSets { - main.java.srcDirs += 'src/main/kotlin' + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } - lintOptions { - disable 'InvalidPackage' + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 } defaultConfig { - applicationId "org.benoitharrault.memory" - minSdkVersion flutter.minSdkVersion - targetSdkVersion 30 - versionCode appVersionCode.toInteger() - versionName appVersionName - archivesBaseName = "$applicationId" + "_" + "$versionCode" + applicationId = "org.benoitharrault.memory" + minSdk = flutter.minSdkVersion + targetSdk = flutter.targetSdkVersion + versionCode = flutter.versionCode + versionName = flutter.versionName } signingConfigs { release { - keyAlias keystoreProperties['keyAlias'] - keyPassword keystoreProperties['keyPassword'] - storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null - storePassword keystoreProperties['storePassword'] + keyAlias = keystoreProperties['keyAlias'] + keyPassword = keystoreProperties['keyPassword'] + storeFile = keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null + storePassword = keystoreProperties['storePassword'] } } buildTypes { release { - signingConfig signingConfigs.release + signingConfig = signingConfigs.release } } + + splits { + abi { + reset() + include 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' + } + } +} + +ext.abiCodes = [ + 'armeabi': 1, + 'armeabi-v7a': 2, + 'arm64-v8a': 3, + 'x86': 4, + 'x86_64': 5, +] + +import com.android.build.OutputFile + +android.applicationVariants.all { variant -> + variant.outputs.each { output -> + def perAbiVersionCodeIncrement = project.ext.abiCodes.get(output.getFilter(OutputFile.ABI)) + + if (perAbiVersionCodeIncrement != null) { + output.versionCodeOverride = variant.versionCode * 1000 + perAbiVersionCodeIncrement + } + } } flutter { - source '../..' + source = "../.." } diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index 6c527ab..bbd7ee7 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -1,7 +1,3 @@ -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.benoitharrault.memory"> - <!-- Flutter needs it to communicate with the running application - to allow setting breakpoints, to provide hot reload, etc. - --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.INTERNET"/> </manifest> diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 2ca7b69..fb5ec35 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,16 +1,25 @@ -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.benoitharrault.memory"> +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <application - android:name="${applicationName}" android:label="memory" + android:name="${applicationName}" android:icon="@mipmap/ic_launcher"> <activity - android:name="io.flutter.embedding.android.FlutterActivity" + android:name=".MainActivity" + android:exported="true" android:launchMode="singleTop" + android:taskAffinity="" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> + <meta-data + android:name="io.flutter.embedding.android.NormalTheme" + android:resource="@style/NormalTheme" + /> + <meta-data + android:name="io.flutter.embedding.android.SplashScreenDrawable" + android:resource="@drawable/launch_background" + /> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> @@ -20,4 +29,10 @@ android:name="flutterEmbedding" android:value="2" /> </application> + <queries> + <intent> + <action android:name="android.intent.action.PROCESS_TEXT"/> + <data android:mimeType="text/plain"/> + </intent> + </queries> </manifest> diff --git a/android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt b/android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt new file mode 100644 index 0000000..63e8e74 --- /dev/null +++ b/android/app/src/main/kotlin/org/benoitharrault/memory/MainActivity.kt @@ -0,0 +1,5 @@ +package org.benoitharrault.memory + +import io.flutter.embedding.android.FlutterActivity + +class MainActivity: FlutterActivity() diff --git a/android/app/src/main/res/drawable-v21/launch_background.xml b/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 0000000..428eb36 --- /dev/null +++ b/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:drawable="?android:colorBackground" /> + + <item> + <bitmap + android:gravity="center" + android:src="@mipmap/launch_image" /> + </item> +</layer-list> diff --git a/android/app/src/main/res/values-night/styles.xml b/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 0000000..c6e7031 --- /dev/null +++ b/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar"> + <item name="android:windowBackground">@drawable/launch_background</item> + </style> + <style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar"> + <item name="android:windowBackground">?android:colorBackground</item> + </style> +</resources> diff --git a/android/app/src/profile/AndroidManifest.xml b/android/app/src/profile/AndroidManifest.xml index 6c527ab..bbd7ee7 100644 --- a/android/app/src/profile/AndroidManifest.xml +++ b/android/app/src/profile/AndroidManifest.xml @@ -1,7 +1,3 @@ -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="org.benoitharrault.memory"> - <!-- Flutter needs it to communicate with the running application - to allow setting breakpoints, to provide hot reload, etc. - --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <uses-permission android:name="android.permission.INTERNET"/> </manifest> diff --git a/android/build.gradle b/android/build.gradle index bc157bd..d2ffbff 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,12 +5,12 @@ allprojects { } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { - project.evaluationDependsOn(':app') + project.evaluationDependsOn(":app") } tasks.register("clean", Delete) { diff --git a/android/gradle.properties b/android/gradle.properties index 2aa2a7b..2597170 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,3 @@ -org.gradle.jvmargs=-Xmx1536M +org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError android.useAndroidX=true android.enableJetifier=true -app.versionName=1.0.25 -app.versionCode=26 diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index b1159fc..7bb2df6 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/android/settings.gradle b/android/settings.gradle index 8cc46c0..b9e43bd 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -5,10 +5,9 @@ pluginManagement { def flutterSdkPath = properties.getProperty("flutter.sdk") assert flutterSdkPath != null, "flutter.sdk not set in local.properties" return flutterSdkPath - } - settings.ext.flutterSdkPath = flutterSdkPath() + }() - includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle") + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") repositories { google() @@ -19,8 +18,8 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "7.2.2" apply false - id "org.jetbrains.kotlin.android" version "1.9.22" apply false + id "com.android.application" version "8.1.0" apply false + id "org.jetbrains.kotlin.android" version "1.8.22" apply false } include ":app" diff --git a/fastlane/metadata/android/en-US/changelogs/27.txt b/fastlane/metadata/android/en-US/changelogs/27.txt new file mode 100644 index 0000000..2ac84b0 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/27.txt @@ -0,0 +1 @@ +Improve build process, split packages per ABI. diff --git a/fastlane/metadata/android/fr-FR/changelogs/27.txt b/fastlane/metadata/android/fr-FR/changelogs/27.txt new file mode 100644 index 0000000..2c13542 --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/27.txt @@ -0,0 +1 @@ +Amélioration du processus de construction. Éclatement des packages par ABI. diff --git a/pubspec.yaml b/pubspec.yaml index 48cbb36..d351fe9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A simple and classic memory game. publish_to: "none" -version: 1.0.25+26 +version: 1.1.0+27 environment: sdk: "^3.0.0" -- GitLab