Introduction
Spent a day upgrading the architecture of Youmengji from Flutter 2
to Flutter 3
. Here’s a summary of the pitfalls encountered.
Upgrading Flutter Version
-
Check current version:
flutter --version
-
Upgrade Flutter (requires VPN access):
flutter upgrade
-
Verify version (should start with 3.x):
flutter --version
-
If you’re lucky enough to run the app directly after this, you can stop reading here.
compileSdkVersion Error
- Modify
compileSdkVersion
to33
inandroid/app/build.gradle
- Update
distributionUrl
inandroid/gradle/wrapper/gradle-wrapper.properties
:distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
- Update Gradle plugin in
android/build.gradle
:classpath 'com.android.tools.build:gradle:7.1.2'
- Update SDK via Android Studio’s SDK Manager:
1.png 2.png
Warning: Mapping new ns xxx to old ns xxx
- Modify repository URLs in
android/build.gradle
:// From: maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } // To: maven { url 'https://maven.aliyun.com/repository/public' }
Error: No named parameter with the name ‘maxLengthEnforced’
- Common issue with deprecated parameters after Flutter upgrades.
- Solution:
- Update all dependencies to their latest versions
- Follow migration guides for breaking changes in SDKs
No signature of method: .android() in build.gradle (app)
- Remove
useProguard
configuration inandroid/app/build.gradle
:buildTypes { release { minifyEnabled true // Delete this line proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }
JAR Version Conflict Warning
- Ensure Kotlin version consistency:
ext.kotlin_version = '1.7.10' dependencies { classpath 'com.android.tools.build:gradle:7.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" }
- Pro tip: Create a new Flutter project (
flutter new app
) to compare with fresh configuration files.