This answer is intended to expand Vinícius Bruno`s answer.
Other than updating the Flutter SDK itself, please make sure that you're working with an updated environment setup.
Q: Do I have to upgrade to compileSdkVersion 35 to use these media3 dependencies?
The short answer is yes, you should. However, normally you can leave this as is:
android {
compileSdk = flutter.compileSdkVersion
}
In addition, you should be able to check what configurations you're using. Please see this thread for reference:
Technically speaking, using the updated Flutter usually has the latest available compileSDKVersion, and I hope you're reading their release notes as well:
The compatibility of your environment setup is a must to avoid further build issues.
Please read this article for reference:
Note: Use the updated AGP for your project to avoid conflicts during app building.
Ensure that you're using a stable gradle for your project. As a reminder, you should use a compatible environment for your project and tools (e.g., plugin/package dependencies, Android Studio, SDKs, etc.).
Q: Is there a workaround (e.g. using older versions of media3, excluding specific modules, or changing dependency resolution strategy)?
Personally, I don't recommend the older version over the new ones, unless it is strongly suggested for your app. However, to help you decide, kindly read their release notes:
Older versions, or their outdated ones, usually consist of bug issues. But it depends on how you utilize some plugins/packages (e.g., how and what you implement classes and methods in your project. Simply, it's how you handle the source code of plugins/packages).
Q: What is the best practice for this kind of dependency/SDK mismatch in a Flutter app?
As I've previously mentioned, build issues usually happen because of incompatibility in your environment and misconfiguration in your configuration files (e.g., build.gradle, settings.gradle, etc.). I strongly advise to read plugin/package/SDK release notes, and try to bump your specific version if you find you're in an outdated environment or configurations. As per Vinícius Bruno's advice,
When updating Flutter, some features of your project will break, so be careful when updating Flutter
And I agree with it. Fun fact, it also applies to Gradle versions or other related tools (e.g., Kotlin version, etc.). But by understanding how they complement each other (i.e., their compatibilities), you can someday fix your build issues all by yourself.
I hope this helps!
flutter doctoroutput?