From 0f76a19104ec07f17f7e143257b58ae24e98d903 Mon Sep 17 00:00:00 2001 From: NiazSagor Date: Sun, 25 Jan 2026 17:33:52 +0600 Subject: [PATCH] Upgrade android_splash_screen Gradle configuration This commit modernizes the Gradle setup for the `android_splash_screen` sample. Key changes include: * Upgrading Gradle wrapper from version 6.7 to 8.7. * Migrating to the plugins block in `settings.gradle` and `app/build.gradle` for applying Android, Kotlin, and Flutter Gradle plugins. * Removing the outdated `buildscript` block from the root `build.gradle`. * Updating `compileSdkVersion` and `targetSdkVersion` to 34. * Setting `minSdkVersion` to `flutter.minSdkVersion`. * Adding the `namespace` property as required by newer Android Gradle Plugin versions. * Refactoring Kotlin constant declarations in `MainActivity.kt`. --- .../android/app/build.gradle | 28 ++++++++++++----- .../splash_screen_sample/MainActivity.kt | 8 ++--- android_splash_screen/android/build.gradle | 21 ++++--------- .../gradle/wrapper/gradle-wrapper.properties | 2 +- android_splash_screen/android/settings.gradle | 30 ++++++++++++++----- 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/android_splash_screen/android/app/build.gradle b/android_splash_screen/android/app/build.gradle index 8c01625b409..958b5b065a9 100644 --- a/android_splash_screen/android/app/build.gradle +++ b/android_splash_screen/android/app/build.gradle @@ -1,3 +1,10 @@ +plugins { + id "com.android.application" + id "kotlin-android" + // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins. + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -21,12 +28,9 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 31 + namespace "com.example.splash_screen_sample" + compileSdkVersion 34 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -35,12 +39,21 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.splash_screen_sample" - minSdkVersion 21 - targetSdkVersion 30 + minSdkVersion flutter.minSdkVersion + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8 + } + buildTypes { release { // TODO: Add your own signing config for the release build. @@ -55,7 +68,6 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "androidx.core:core-splashscreen:1.0.0-alpha02" implementation "androidx.core:core:1.5.0-alpha05" implementation "androidx.core:core-ktx:1.6.0" diff --git a/android_splash_screen/android/app/src/main/kotlin/com/example/splash_screen_sample/MainActivity.kt b/android_splash_screen/android/app/src/main/kotlin/com/example/splash_screen_sample/MainActivity.kt index d3efc96d743..e7d858e6943 100644 --- a/android_splash_screen/android/app/src/main/kotlin/com/example/splash_screen_sample/MainActivity.kt +++ b/android_splash_screen/android/app/src/main/kotlin/com/example/splash_screen_sample/MainActivity.kt @@ -203,9 +203,9 @@ class MainActivity : FlutterActivity() { } private companion object { - const val SPLASHSCREEN_ALPHA_ANIMATION_DURATION = 500 as Long - const val SPLASHSCREEN_TY_ANIMATION_DURATION = 500 as Long - const val SPLASHSCREEN_FINAL_ANIMATION_ALPHA_ANIMATION_DURATION = 250 as Long - const val WAIT_FOR_AVD_TO_FINISH = false + const val SPLASHSCREEN_ALPHA_ANIMATION_DURATION = 500L + const val SPLASHSCREEN_TY_ANIMATION_DURATION = 500L + const val SPLASHSCREEN_FINAL_ANIMATION_ALPHA_ANIMATION_DURATION = 250L + const val WAIT_FOR_AVD_TO_FINISH = false } } diff --git a/android_splash_screen/android/build.gradle b/android_splash_screen/android/build.gradle index c45f25cc9d6..d2ffbffa4cd 100644 --- a/android_splash_screen/android/build.gradle +++ b/android_splash_screen/android/build.gradle @@ -1,16 +1,3 @@ -buildscript { - ext.kotlin_version = '1.5.31' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() @@ -18,12 +5,14 @@ allprojects { } } -rootProject.buildDir = '../build' +rootProject.buildDir = "../build" subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" - project.evaluationDependsOn(':app') +} +subprojects { + project.evaluationDependsOn(":app") } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/android_splash_screen/android/gradle/wrapper/gradle-wrapper.properties b/android_splash_screen/android/gradle/wrapper/gradle-wrapper.properties index bc6a58afdda..7aeeb11c6ee 100644 --- a/android_splash_screen/android/gradle/wrapper/gradle-wrapper.properties +++ b/android_splash_screen/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip diff --git a/android_splash_screen/android/settings.gradle b/android_splash_screen/android/settings.gradle index 44e62bcf06a..4f520718dcc 100644 --- a/android_splash_screen/android/settings.gradle +++ b/android_splash_screen/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" + id "com.android.application" version "8.6.0" apply false + id "org.jetbrains.kotlin.android" version "2.1.0" apply false +} + +include ":app"