I have an Android project that is targeted to Android 15, but has a minimum version of Android 8. This defined in the manifest file:
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="15"/>
This means I can only use functionality up to Android 8.
When I use methods like the String class’ isEmpty() method (that was added in API 9), IntelliJ and Eclipse both happily compile it, but when I run it on older devices, I get crashes because API 8 does not have isEmpty() implemented.
Does anyone know why neither IDE can catch stuff like this?
My Java compiler is version 1.6.0_33 – would forcing the IDE to use an older version help here?
Thanks! If there is any info I missed, feel free to leave a comment and I’ll dig the info up!
It is supposed to compile. This allows you to use newer methods in more recent SDKs via wrapper classes. If your target SDK was 8, then the IDE would catch you and complain.
More info here:
http://developer.android.com/guide/practices/compatibility.html
The wrapper class technique is very useful. There is a guide in this blog post about it:
http://android-developers.blogspot.com/2009/04/backward-compatibility-for-android.html
Edit:
It should be noted the latest ADT (r20, perhaps earlier) for Eclipse with Lint in it’s default settings will look for usage of API methods above the minSDK. However it will only check files after they have been modified, or if you run Lint.
More on Lint: http://tools.android.com/tips/lint