androidandroid-studiogradle

How to set Android Studio targetSdk with no errors or warnings


I have programmed extensively using Android Studio in the past, but I have encountered an issue when trying to create a simple "Empty Views Activity" using Android Studio Ladybug 2024.2.1 Patch 2 (the latest version available at the time of this writing). In file build.gradle.kts, I see a warning that I am not targeting the latest version of Android. partial screen image showing warning

However, if I change the value of targetSdk to 35 to match the value of compileSdk, it shows that I have an error. partial screen image showing error

But ... The app appears to build and to run correctly with either value for targetSdk. Any suggestions as to how to get rid of this warning/error?


Solution

  • I see a warning that I am not targeting the latest version of Android

    To distribute on the Play Store, you will need to target API Level 35 by sometime in the fall of 2025. Hence, the warning.

    However, if I change the value of targetSdk to 35 to match the value of compileSdk, it shows that I have an error.

    The error is that Google thinks that you don't know what you're doing. 🙃 If you hover your mouse over the error, the popup should read:

    It looks like you just edited the targetSdkVersion from 34 to 35 in the editor. Be sure to consult the documentation on the behaviors that change as result of this. The Android SDK Upgrade Assistant can help with safely migrating...

    error popover

    Choose "Override warning: I know what I'm doing" to suppress the "error". You can get the same option via a quick-fix context action (e.g., Option-Enter with your text cursor in the error).