Android: able to install app for unsupported Android version

4k Views Asked by At

We're dropping support for Android 2.3 (API level 9) devices because most of our users have a newer Android version on their phones. I've updated the minimum SDK version to api level 14.

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
    }
}

However I'm still able to install the app on Android 2.3 devices manually (not by store). Is this expected behavior or am I doing something wrong? I couldn't find the answer somewhere else.

Another strange issue is that Lint doesn't detect the correct api level.

listView.setFastScrollAlwaysVisible(true);

This results in the warning: Call requires api level 11 (current min is 9). However my current minimum is now 14. So this indicates to me that i did something wrong. I tried cleaning and rebuilding the project, restarting Android Studio. It all didn't work.

Can anyone help me out?

Edit

Based on Sufians comment I started fiddling around with my gradle files and I came to the following solution. However some questions still remain. My project structure looks like this:

  • android.gradle (top-level build file which contains SDK versions)
  • main module (contains base code for other modules)
    • build.gradle (apply from: '../android.gradle')
  • sub module A (module specific changes)
    • build.gradle (has dependency on main module)
  • sub module B (module specific changes)
    • build.gradle (has dependency on main module)

I have a top-level build file android.gradle which contains the SDK versions. My modules then include the build file by apply from: '../android.gradle'. If I put the minSdkVersion directly in de main module the warnings disappear. Is that the way it should be? or do I need to set an minSdkVersion for every submodule? Or is there another way so that the SDK versions can stay within the android.gradle file?

4

There are 4 best solutions below

1
On BEST ANSWER

Ok... I finally realized that there is nothing wrong in my project structure. The only thing I needed to do was press the little 'Sync Project with Gradle Files' button. After that all errors disappear.

Also I concluded that it's possible to install unsupported apps manually. However the Google Play Store should prevent users from installing or updating the app.

0
On

Yes, you can install the app manually on your device as long the minimum API level specified in your manifest is less than your device's API level.

When you upload your app to the store, the store will not show your app to users with devices having Android version less than the min API level specified (API level 9 in your case).

As for the Lint warnings, make sure that the minimum/maximum SDK versions in your manifest file match those specified in the build.gradle file.

and you can also make sure that new APIs are not executed on older API levels by checking the OS version in the code. http://developer.android.com/reference/android/os/Build.VERSION.html

9
On

If I put the minSdkVersion directly in de main module the warnings disappear. Is that the way it should be?

Your main module's minimum and target SDKs (i.e inside the build.gradle of the module) will be that of your application.

The project's build.gradle should not contain any of this information.

or do I need to set an minSdkVersion for every submodule? Or is there another way so that the SDK versions can stay within the android.gradle file?

Each module defines its own minimum SDK. If you're using a third party module/library, you better not change it, unless you know what you're doing.

7
On

i have personally never developed anything for android but when installing apps the device has never complained when installing an .apk that wasn't supported by the OS version.
even when the store said it wasn't supported i'm always able to install it as a .apk so i think it can't really be blocked.