I am writing an application that uses some functions and classes that are available only at the last API level - 16, but I want it to run without errors on devices with API level 15.
Let me use a few examples. New class: Android.widget.Advanceable and new / renamed method: View.setBackground() :
I can do something like this:
Advanceable myAdvanceable = ...; if (android.os.Build.VERSION.SDK_INT >= 16) { myView.setBackground(...); myAdvanceable.advance(); } else { myView.setBackgroundDrawable(...);
And if I installed minSdk from 15, but the goal of building is 16 (i.e. in Project Properties → Android), it will actually compile without errors. At least for a while. Eclipse is a bit stochastic regarding errors and sometimes says: "setBackground () is only available at API level> = 16" or similar, but if I just clear the project, then these errors will magically disappear.
So my question is: am I allowed to do this? Will the code crash if I run it on a device of level 15 API? Will it just crash if it really gets to code 16? Why doesn't Eclipse stop me from creating it?
Change 1
Thanks for the answers, I think the question really should be: why I won’t warn me about using the new APIs?
I have this in my manifest, and I use API level 16 functions, but it still doesn't warn me:
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="16"/>
Also, I'm still not sure when entire classes are new to the API level, like Advanceable . In particular, if I use them as member variables.
Edit 2
The answer was “Eclipse buggy like hell,” but Nico’s answer also helped a lot.
android api compatibility
Timmmm Jul 21 2018-12-12T00: 00Z
source share