DEV Community

Cover image for Upgrading to Ladybug 🐞, led to loads of bugs 🐛! (flutter)
Saad Alkentar
Saad Alkentar

Posted on

Upgrading to Ladybug 🐞, led to loads of bugs 🐛! (flutter)

Upgrading my Android Studio version has always been a hurdle! I've always avoided it when possible, but it's a must after a while.

Errors 😓

To list a few errors that faced me when upgrading a rather small project

path_provider_android/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Enter fullscreen mode Exit fullscreen mode
file_picker/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Enter fullscreen mode Exit fullscreen mode
sqflite/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Enter fullscreen mode Exit fullscreen mode
camera_android_camerax/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Enter fullscreen mode Exit fullscreen mode
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Enter fullscreen mode Exit fullscreen mode
camera_android_camerax/intermediates/runtime_library_classes_jar/debug/classes.jar.
         > Error while dexing.
Enter fullscreen mode Exit fullscreen mode
file_picker/intermediates/runtime_library_classes_jar/debug/classes.jar.
         > Error while dexing.
Enter fullscreen mode Exit fullscreen mode
path_provider_android/intermediates/runtime_library_classes_jar/debug/classes.jar.
         > Error while dexing.
Enter fullscreen mode Exit fullscreen mode
sqflite/intermediates/runtime_library_classes_jar/debug/classes.jar.
         > Error while dexing.
Enter fullscreen mode Exit fullscreen mode

and so on! As you can see, these errors are library-related, but those are very common libraries and it is kinda tricky! it seems like a multi-dexing issue at first, those error messages don't give a good idea about the problem. finally, to the solution...

Upgrading the project! 🤩

We start by updating the gradle version in the Android folder, making sure it is 8.x. ie gradle-8.9-all.zip

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
Enter fullscreen mode Exit fullscreen mode

android/gradle/wrapper/gradle-wrapper.properties

Then, updating Gradle plugin in gradle setting file

plugins {
    id "dev.flutter.flutter-plugin-loader" version "1.0.0"
    id "com.android.application" version "8.3.2" apply false
    id "org.jetbrains.kotlin.android" version "2.0.20" apply false
}
Enter fullscreen mode Exit fullscreen mode

android/settings.gradle

Finally updating Java version in Android app gradle file

android {
    namespace = "com..."
    compileSdk = flutter.compileSdkVersion
    ndkVersion = "25.1.8937393"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = 17
    }
Enter fullscreen mode Exit fullscreen mode

android/app/build.gradle

make sure to set version to Java 17. I also recommend updating pub libraries if possible using

flutter pub upgrade
flutter clean
flutter run
Enter fullscreen mode Exit fullscreen mode

That is it! I believe this covers all the steps to upgrade your flutter project. tell me if you find any unexpected issues

Stay tuned for other tips 😎

Top comments (0)