Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I do lowering the minimum SDK version?

I'm working on an Anrdoid app. It's almost finished. I've just noticed that the minSdkVersion is set to 21. Maybe I forgot it when I created the project. I'd like to lower it, because the app's users will likely to have older devices.

I don't think it's good idea to change the minSdkVersion to ~10, sit back, and hope it will compile and run fine in the future.

My idea was that I could check all the methods used in the project, their minimum API level, so I could know what I have to replace with alternatives. However, the project is a bit large. Searching for all methods' documentation one by one would take a lot of time.

Is it possible to automatically list the Android API specific methods used in my project, and their API level? Or somehow detect the highest API level that is required by an used method? Android Studio knows these numbers, it can fetch the documentation too. Or, is it safe to change the minSdkVersion and targetSdkVersion to a lower API level to know which methods aren't supported in an older device, and after I fix all errors/warnings the IDE will show me, will my app run fine?

like image 839
klenium Avatar asked Dec 23 '22 12:12

klenium


1 Answers

Android Studio will give you warnings when you use methods that require a higher sdk version than your specified minSdkVersion. You can access the whole list of these warnings for the complete project by leveraging the Analyze -> Code Cleanup functionality. So what you can do:

  1. Lower the minSdkVersion.
  2. Click Analyze -> Code Cleanup in Android Studio. Select "Whole Project"
  3. The relevant errors are part of these sections:
    • Android Lint: Correctness -> Attribute unused on older versions
    • Android Lint: Correctness -> Calling new methods on older versions
    • Android Lint: Correctness -> using inlined constants on older versions
    • Android Lint: Internationalization -> Right-to-left text compatibility issues

By trying different version numbers you can see how many changes are necessary. To decide for the correct minSdkVersion, you might want to consider the Android API level device stats.

So a strategy for deciding for a targetSdkVersion or minSdkVersion typically looks like this: You set the targetSdkVersion to the highest version number that you have tested your app with. The minSdkVersion should be set to a lower value - low enough so enough devices are supported, but high enough so there are not to many version specific workarounds necessary. Find details about these two values in the Android documentation.

like image 140
guglhupf Avatar answered Dec 27 '22 03:12

guglhupf