KeyQ Blog

Demystifying the SDK Version Error in Flutter App Development

Written by Kenneth Hough | Oct 24, 2023 2:33:20 PM

Hey there Flutter enthusiasts! 🚀

Ever been all set to launch your brand-new Flutter app on your Android device, only to be greeted by a frustrating SDK version error? 🤦‍♂️ It's like trying to plug in your headphones and realizing they don't fit - a real buzzkill! But don't worry, you're not alone. Many of us have faced this head-scratching situation, scratching our heads and wondering what in the world just went wrong. Fear not, as I'm here to shed some light on this pesky '[INSTALL_FAILED_OLDER_SDK: Requires newer sdk version #33 (current version is #31)]' error and guide you through the labyrinth of SDK versions. Let's dive in and decode this puzzle together, shall we? 💡

Firstly, this error can pop up if the compiled app was built against an older SDK version, and the Android device you are trying to run it on is equipped with a more recent SDK version. It's like trying to fit a square peg into a round hole - the mismatch just doesn't bode well for a smooth run. Secondly, you might encounter the same error if your Android device is lagging behind in terms of the SDK version, while your compiled app is all set for the latest SDK version. Think of it as trying to play a cutting-edge video game on an ancient console - the tech just isn't compatible! Understanding these two potential triggers is crucial in navigating your way through this perplexing roadblock.

How to Fix

Update Android SDK and Re-Build App

The most likely reason your app won't run on your device is because the SDK the app was built on is older than the SDK your device is running. This usually occurs when a new Android SDK is released and your device updates before you realize you need to obtain a copy of the new SDK.

In this scenario, the fix is very easy. Open up, Android Studio and navigate to settings. Here's a screenshot on a mac:

Once the settings window opens, you will see a list options on your left. Look for Appearance & Behavior, and then click on System Settings to expand the list, and finally click on Android SDK. Under the SDK Platforms tab, make sure the target version you need is clicked. Sometimes the check might be a horizontal line (or minus bar), which indicates that there are updates available for the SDK. If you see a horiztonal line instead of a check mark, click on it to turn it into a check mark. This will mark the SDK for updating. When the required SDKs have been checked, click apply and your SDKs will start downloading.

Once you have the SDKs downloaded, we need to update the gradle configuration in your flutter project. Navigate to android > app > build.gradle and open the gradle file.

In the build.gradle file, look for the line that has compileSdkVersion. You may see that compileSdkVersion is set to flutter.compileSdkVersion. Change this to the SDK target version number you wish to build for. There are other version settings you can update, such as minSdkVersion and targetSdkVersion

Additionally, instead of replacing the SDK version with a hard-coded number, you can alternatively update your flutter SDK package to use the new SDK versions. You can learn more about this in the following Stack Overflow post: Flutter : How to change Android minSdkVersion in Flutter Project?.

Downgrade Android SDK to Match your Android Device

If upgrading your SDK and building against the new version doesn't resolve this issue, it's possible that your Android device is running on an older version of the SDK. You can check this by going to your device's settings and check the build number. If your device SDK is older than the SDK your app is being built for, then you can either upgrade your device to the newest version (if that is feasible...some older devices may not support the newer Android SDK), or alternatively you can downgrade the SDK you are using to build your app. To do this, follow the same steps in the previous section but instead of click on a newer SDK, look for the SDK that matches your device and download that through Android Studio. Once the download has completed, don't forget to update your build.gradle file.

That's a Wrap, Folks! 🎬

Phew! Dealing with these SDK version mishaps might have felt like navigating a maze, but now you're armed with the know-how to troubleshoot them like a pro! Remember, ensuring that your app's SDK version aligns with your device's SDK version is the key to a seamless and hassle-free deployment. So, whether it's an outdated SDK causing trouble or a mismatch between your app and your device, you've got the tools to tackle it head-on. Now, go forth and let your Flutter app shine on every compatible Android device out there! Happy coding! 🌟