Featured image of post Upgrading from Flutter 2 to Flutter 3

Upgrading from Flutter 2 to Flutter 3

The Journey of Upgrading Youmengji

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 to 33 in android/app/build.gradle
  • Update distributionUrl in android/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:

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:
    1. Update all dependencies to their latest versions
    2. Follow migration guides for breaking changes in SDKs

No signature of method: .android() in build.gradle (app)

  • Remove useProguard configuration in android/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.