Question

When building android apps for different behavior on different targets we can do:

if (Build.VERSION.SDK_INT < 10) {
    Toast.makeText(this.context, "Not Supported", Toast.LENGTH_LONG ).show();
} else {
    this.doComplicatedOperation();
}

But in the method doComplicatedOperation() it would be logical to use higher api classes than the current build target (eg. api 5), but lint keeps complaining that ClassIntroducedInApiLevel11 can not be resolved as a type

How could I change the code of doComplicatedOperation() that my project compiles?

@TargetApi(11)
private void doComplicatedOperation() {
    ClassIntroducedInApiLevel11 = new ClassIntroducedInApiLevel11();
}
Was it helpful?

Solution

The purpose of minSdkVersion is to exclude platforms where you do not provide backward compatibility support.

In order to provide the proper libraries for your build you need to set a higher targetSdkVersion so the IDE or whatever knows what libraries to include when creating your APK.

It sounds like you don't want to target a higher SDK because some methods or objects may be deprecated or even unsupported. That's when you use support libraries, if necessary, for backward compatibility.

OTHER TIPS

You need to change your SDK target to at least the SDK that the method is in so in. You should always be targeting the highest API there is available (currently 19) so your manifest should look like this

<uses-sdk
    android:minSdkVersion="5"
    android:targetSdkVersion="19" />

if you are still targeting SDK 5 you are in the dark ages

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top