3

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?

Wirling
  • 4,810
  • 3
  • 48
  • 78

4 Answers4

2

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.

Wirling
  • 4,810
  • 3
  • 48
  • 78
  • Android Studio shows that option at the top of opened files, whenever a change is made in or around `build.gradle`. Strange that you didn't notice early enough. – Sufian Jun 25 '16 at 07:29
1

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.

  • that way the app can crash. – JMR Feb 25 '16 at 11:32
  • Well, I know that the Google Play Store prevents users from installing incompatible apps. Most of the time is doesn't even show you the application at all. But it probably only works if i set the minimum version correctly which i'm not sure of right now. – Wirling Feb 25 '16 at 11:35
  • If APK's minimum API level is not meant, it can't get installed. – Sufian Feb 25 '16 at 11:35
  • @JMR yeah it can crash but most of the time it works fine. and when a user installs the .apk manually most of the time they are more "advanced" users. –  Feb 25 '16 at 11:36
  • 1
    @ketkev you might be using one of those xposed modules or some other hacks. Such cases are exceptions and OP is not talking about them. – Sufian Feb 25 '16 at 11:37
  • So if I understand correctly nothing prevents you from installing the app manually, but the Google Play Store prevents user from installing / updating the app. That's fine by me. – Wirling Feb 25 '16 at 11:44
  • @wirling jup, but when manually installing the app might be less stable/crash –  Feb 25 '16 at 11:47
0

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

Mina Wissa
  • 10,923
  • 13
  • 90
  • 158
0

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.

Sufian
  • 6,405
  • 16
  • 66
  • 120
  • The SDK versions are located in android.gradle and are included in the seperate modules. My project's build.gradle file doesn't contain these SDK versions. I just needed to sync my project with the Gradle files, and now it works fine. Apparently it isn't triggered by cleaning or rebuilding your project. Check out my answer. – Wirling Feb 25 '16 at 14:22
  • @Wirling didn't your Studio show message to sync gradle when you made the changes? – Sufian Feb 25 '16 at 14:27
  • No it didn't show a message, which is very strange. My other colleagues can confirm this. – Wirling Feb 25 '16 at 14:31
  • @Wirling I still don't get what is the `android.gradle` file. Are you talking about `build.gradle`? And where are you defining the `minSdkVersion`? Inside the `build.gradle` of the project (location `~/build.gradle`) or the app module (location `~/app/build.gradle`)? – Sufian Feb 25 '16 at 15:00
  • `android.gradle` is my projects top-level build-file which contains the minSdkVersion. It is imported in all other submodules `build.gradle`. We don't have a `build.gradle` file at the project location (or maybe `android.gradle` isn't named correctly?). But our project has a lot of modules and gradle files which makes it really complex. – Wirling Feb 26 '16 at 07:40
  • @Wirling to me it seems like it's a mistake. AS always creates `build.gradle` and not `android.gradle`. I've imported projects from Eclipse and also created new projects in AS and never seen `android.gradle`. And each module should have it's own `minSdkVersion` (inside its own `build.gradle`). Writing it in the project's root might create confusion in the future (in case someone tries to get adventurous with SDK versions). – Sufian Feb 26 '16 at 10:35
  • I have to come back on my previous comment. I overlooked the fact that we have a `build.gradle` file for our project. I think that we manually created an `android.gradle` file (containing SDK versions) so we can import that in other modules, cause the modules share a lot of similarities (they're used for branding). So I think it's fine the way it is now, cause every module uses the minSdkVersion from `android.gradle`. – Wirling Feb 26 '16 at 10:48
  • 1
    @Wirling you're doing it wrong. Using same minSdkVersion for all versions is wrong and might confuse someone in the future. If it started as a shortcut for updating the `compileSdk` and `targetSdk`, look at [How to define common android properties for all modules using gradle](http://stackoverflow.com/a/20436423/1276636) – Sufian Feb 26 '16 at 11:01
  • Thanks for the link. I think that I need to change some things around. I didn't know the right way to define common properties. – Wirling Feb 26 '16 at 11:15