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
file_picker/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
sqflite/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
camera_android_camerax/intermediates/runtime_library_classes_jar/debug/classes.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeLibDexDebug'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
camera_android_camerax/intermediates/runtime_library_classes_jar/debug/classes.jar.
> Error while dexing.
file_picker/intermediates/runtime_library_classes_jar/debug/classes.jar.
> Error while dexing.
path_provider_android/intermediates/runtime_library_classes_jar/debug/classes.jar.
> Error while dexing.
sqflite/intermediates/runtime_library_classes_jar/debug/classes.jar.
> Error while dexing.
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
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
}
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
}
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
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)