javaandroidandroid-developer-api

Now library methods are deprecated based on library number instead of Android version?


I am working with the following code snippet:

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU){
            WebSettingsCompat.setForceDark(myWebView.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
        }

It underlines the setForceDark method as deprecated, I understand that it should not be underlined since it is within the condition that verifies the Android version, read here.

So reading this other part of the documentation indicates that the method has been deprecated since version 1.5.0 of the androidx.webkit:webkit library.

My question is, are deprecated methods now based on library version instead of Android version? If this answer is affirmative, since when? I have been offline for 3 months.


Solution

  • Androidx is not Android. It is not part of the Android SDK. In fact the entire reason it exists is that it isn't part of the Android SDK, so it can be iterated on and updated separately without requiring an OS update. This allows it to work around differences in SDK versions for you.

    When using anything in AndroidX, you never have to worry about the possibility of multiple versions. You specify the version in your dependencies. Then you use the version you specified there.

    In particular, this API call was turned into a noop on tagetSDKVersion > TIRAMISU because the functionality it's based on is no longer in the base SDK code- you can see that in the base non-androidx webview: https://developer.android.com/reference/android/webkit/WebSettings#setForceDark(int). Since it doesn't exist on the base WebView, it can't exist in androidx webview unless there's an easy way to port the functionality (there isn't).