
How to migrate old Flutter project to the latest Flutter version
Migrating an old Flutter project (using older Android Gradle and build.gradle
Groovy files) to the latest Flutter version (3.22) which now defaults to Kotlin DSL (build.gradle.kts
), involves several steps.
Objective:
Migrate your existing android/build.gradle
, android/app/build.gradle
, and related files from Groovy (.gradle
) to Kotlin DSL (.gradle.kts
) format while ensuring compatibility with Flutter 3.22 and AGP (Android Gradle Plugin) 8+.
Step-by-step Migration Guide:
1. Upgrade Flutter SDK to 3.22
Make sure you’re on Flutter 3.22:
flutter upgrade
flutter --version
2. Backup Your Project
Before any change, back up your current project (e.g. via Git or zip).
3. Update Gradle Wrapper
Edit android/gradle/wrapper/gradle-wrapper.properties
:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Gradle 8.4 is compatible with AGP 8.4+ and Kotlin DSL.
4. Convert Groovy .gradle
to Kotlin DSL .gradle.kts
Rename:
android/build.gradle
→android/build.gradle.kts
android/app/build.gradle
→android/app/build.gradle.kts
- Update
settings.gradle
→settings.gradle.kts
5. Edit build.gradle.kts
(Project-level)
Example android/build.gradle.kts
:
// File: android/build.gradle.kts
buildscript {
dependencies {
classpath("com.android.tools.build:gradle:8.4.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
6. Edit app/build.gradle.kts
(App-level)
Here’s a minimal example for android/app/build.gradle.kts
:
// File: android/app/build.gradle.kts
plugins {
id("com.android.application")
kotlin("android")
}
android {
namespace = "com.example.yourapp"
compileSdk = 34
defaultConfig {
applicationId = "com.example.yourapp"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
dependencies {
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.appcompat:appcompat:1.6.1")
}
7. Update settings.gradle.kts
Replace settings.gradle
with settings.gradle.kts
:
// File: android/settings.gradle.kts
include(":app")
8. Update Flutter Build Configuration
Make sure flutter.gradle
is still referenced. You might need to update:
// android/build.gradle.kts (under buildscript)
classpath("com.google.gms:google-services:4.4.0")
classpath("com.android.tools.build:gradle:8.4.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
In app/build.gradle.kts
, apply:
apply(from = "../flutter.gradle.kts")
9. Update Gradle Properties
Edit android/gradle.properties
:
propertiesCopyEditorg.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
kotlin.code.style=official
10. Clean and Build
flutter clean
flutter pub get
flutter build apk
Common Issues:
Issue | Fix |
---|---|
DSL errors like compileSdkVersion not found | You’re still using Groovy-style in Kotlin DSL – adjust syntax (compileSdkVersion = 34 → compileSdk = 34 ) |
Plugins not found | Ensure plugins block is used at the top of .gradle.kts |
flutter.gradle not applied | Use apply(from = "../flutter.gradle.kts") or keep the Groovy file and reference it |
Final Tip
If you want a fully working sample with Kotlin DSL, create a new Flutter project with:
flutter create --platforms android -a kotlin my_new_app
Then compare the android/
folder structure and Kotlin DSL syntax with your project.
Also Read :- How to update laravel project with latest version step by step guide