Search code examples
androidandroid-api-levels

How to identify potential incompatibilies when increasing Android target SDK


I want to attempt to add a feature (notification channels) which requires target SDK level 26 to an open-source Android project that currently targets SDK level 22.

Looking at the documentation for notification channels, I saw something disturbing: apparently increasing the target level can cause previously valid uses of the API to function differently — in this case, notifications that don’t specify a channel will no longer be displayed. That tells me there could be other things that would break as well just from changing the target level.

How can I find every API call in the project that I need to examine for possible incompatibility when changing from level 22 to level 26? Alternatively, is there a way to isolate sections of code so that the code I’m not changing still uses level 22, and only the new code uses 26?


Solution

  • I want to attempt to add a feature (notification channels) which requires target SDK level 26

    If you have targetSdkVersion set to 26 or higher, then notification channels are required. If your targetSdkVersion is set below 26, notification channels are not required, but AFAIK you can still set them up, if you are running on an API Level 26+ device. Personally, I have never tried this; keeping your targetSdkVersion up to date is fairly important in modern Android app development.

    How can I find every API call in the project that I need to examine for possible incompatibility when changing from level 22 to level 26?

    In general, you can't. You are welcome to read the release notes for Android; in the past couple of releases, Google has been better about specifically calling out the changes that are triggered by targetSdkVersion. You can also read the JavaDocs for the associated Build.VERSION_CODES value (e.g., the JavaDoc for M), as they list changes triggered by targetSdkVersion. The IDE might give you some warnings. Beyond that, it's a matter of testing.

    Alternatively, is there a way to isolate sections of code so that the code I’m not changing still uses level 22, and only the new code uses 26?

    Put them in completely independent apps. Otherwise, no. The targetSdkVersion is a per-app setting, not a per-file or per-class setting.