Skip to content

Commit e3dd7cb

Browse files
Upgrade android_splash_screen Gradle configuration (#2779)
I noticed that the `android_splash_screen` sample was outdated and was not runnable due to gradle issues. This commit fixes 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`. @ericwindmill ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I have added sample code updates to the [changelog]. - [x] I updated/added relevant documentation (doc comments with `///`). Co-authored-by: Eric Windmill <eric@ericwindmill.com>
1 parent 6957e4a commit e3dd7cb

5 files changed

Lines changed: 52 additions & 37 deletions

File tree

android_splash_screen/android/app/build.gradle

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
plugins {
2+
id "com.android.application"
3+
id "kotlin-android"
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id "dev.flutter.flutter-gradle-plugin"
6+
}
7+
18
def localProperties = new Properties()
29
def localPropertiesFile = rootProject.file('local.properties')
310
if (localPropertiesFile.exists()) {
@@ -21,12 +28,9 @@ if (flutterVersionName == null) {
2128
flutterVersionName = '1.0'
2229
}
2330

24-
apply plugin: 'com.android.application'
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
2831
android {
29-
compileSdkVersion 31
32+
namespace "com.example.splash_screen_sample"
33+
compileSdkVersion 34
3034

3135
sourceSets {
3236
main.java.srcDirs += 'src/main/kotlin'
@@ -35,12 +39,21 @@ android {
3539
defaultConfig {
3640
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3741
applicationId "com.example.splash_screen_sample"
38-
minSdkVersion 21
39-
targetSdkVersion 30
42+
minSdkVersion flutter.minSdkVersion
43+
targetSdkVersion 34
4044
versionCode flutterVersionCode.toInteger()
4145
versionName flutterVersionName
4246
}
4347

48+
compileOptions {
49+
sourceCompatibility = JavaVersion.VERSION_1_8
50+
targetCompatibility = JavaVersion.VERSION_1_8
51+
}
52+
53+
kotlinOptions {
54+
jvmTarget = JavaVersion.VERSION_1_8
55+
}
56+
4457
buildTypes {
4558
release {
4659
// TODO: Add your own signing config for the release build.
@@ -55,7 +68,6 @@ flutter {
5568
}
5669

5770
dependencies {
58-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
5971
implementation "androidx.core:core-splashscreen:1.0.0-alpha02"
6072
implementation "androidx.core:core:1.5.0-alpha05"
6173
implementation "androidx.core:core-ktx:1.6.0"

android_splash_screen/android/app/src/main/kotlin/com/example/splash_screen_sample/MainActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ class MainActivity : FlutterActivity() {
203203
}
204204

205205
private companion object {
206-
const val SPLASHSCREEN_ALPHA_ANIMATION_DURATION = 500 as Long
207-
const val SPLASHSCREEN_TY_ANIMATION_DURATION = 500 as Long
208-
const val SPLASHSCREEN_FINAL_ANIMATION_ALPHA_ANIMATION_DURATION = 250 as Long
209-
const val WAIT_FOR_AVD_TO_FINISH = false
206+
const val SPLASHSCREEN_ALPHA_ANIMATION_DURATION = 500L
207+
const val SPLASHSCREEN_TY_ANIMATION_DURATION = 500L
208+
const val SPLASHSCREEN_FINAL_ANIMATION_ALPHA_ANIMATION_DURATION = 250L
209+
const val WAIT_FOR_AVD_TO_FINISH = false
210210
}
211211
}
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
buildscript {
2-
ext.kotlin_version = '1.5.31'
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath 'com.android.tools.build:gradle:4.1.0'
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
}
12-
}
13-
141
allprojects {
152
repositories {
163
google()
174
mavenCentral()
185
}
196
}
207

21-
rootProject.buildDir = '../build'
8+
rootProject.buildDir = "../build"
229
subprojects {
2310
project.buildDir = "${rootProject.buildDir}/${project.name}"
24-
project.evaluationDependsOn(':app')
11+
}
12+
subprojects {
13+
project.evaluationDependsOn(":app")
2514
}
2615

27-
task clean(type: Delete) {
16+
tasks.register("clean", Delete) {
2817
delete rootProject.buildDir
2918
}

android_splash_screen/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
include ':app'
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4-
def properties = new Properties()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
511

6-
assert localPropertiesFile.exists()
7-
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
17+
}
818

9-
def flutterSdkPath = properties.getProperty("flutter.sdk")
10-
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11-
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
19+
plugins {
20+
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21+
id "com.android.application" version "8.6.0" apply false
22+
id "org.jetbrains.kotlin.android" version "2.1.0" apply false
23+
}
24+
25+
include ":app"

0 commit comments

Comments
 (0)