Android target SDK version and phones

616 views Asked by At

So I wrote an Android app a while ago, and I'm trying to update it. I'm wanting to build in code sections where if the phone they're on is less than 3.0, do something one way, otherwise do it another way.

My build target is set to 11 in the project.properties file, but it still seems to run on Android versions < 3.0? Is this normal? Will I see some crash at some point? Everything seems to be working... My minSDKVersion is 8, but happens when I run this app with Android 3.0 code on Android 2.3.3?

3

There are 3 answers

0
joshkendrick On BEST ANSWER

I think I was having a dumb moment. If I set my minSDK to 8, then anything newer than 8 should work fine. If I set my build target to 11, and then do checks before running any code that is newer than 8 on phones with SDKs older than 11, then that should cover all the bases.

I just got a little confused when I was messing with the targetSDK and the minSDK

Thanks for the comments.

0
Graham Borland On

It will in general run OK on platforms as far back as API level 8, since that's what you have as your minSdkVersion. It will, however, crash on earlier (pre-11) platforms if you try to call any APIs which were introduced at level 11 or later. To avoid this, you should check the OS version at runtime before calling any such methods. See Retrieving Android API version programmatically for advice on how to do this.

0
Jaypoulz On

It is usually best to work from lower APIs up when approaching this kind of development. Each time you've finished a working version for an API, make sure it compiles without error before moving up to the next level. The manifest will warn you if you're targetSdkVersion and your minSdkVersion are different; however, this is mostly just to make sure that you are careful not to call methods from higher APIs. A useful work around might be:

    private static int getApiLevel() {
            return Integer.parseInt(android.os.Build.VERSION.SDK);
    }