Reputation: 191
How can I determine the minimum API Level or Maximum API Level used in my project? And is there any way to determine which part of code in my project uses which API Level?
Is there anyway in android studio to determine minimum API Level & maximum API Level used in my project? Like for example "TODO" tracks of all tasks etc, do we have any feature in Android studio to determine minimum API Level & maximum API Level used in my project?
I'm newbie so please bear with me.
Upvotes: 19
Views: 30900
Reputation: 1
You have to determine minSDKVersion based on from which version your app need to support by refering the link https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels
Upvotes: 0
Reputation: 1692
This question somewhat creates the wrong mindset behind the min SDK version. The real use of this parameter is to specify the minimum Android platform that the application is coded to run on. The lower the level, the greater the range of platforms that the application runs on. This means that the application is applicable to a larger market share of devices. If you need to set the minSDK to a lower API level so that your application meets you market share coverage plans, than set it to that level. The compiler will let you know if you made any obvious coding error, and you have to correct them. That said, at times, you may be willing to accept the deployment of the application on a smaller set of devices, because a later version of the SDK provides you with a capability that you don't want to provide your own alternate coding for.
Muhammed's solution kind of gives you the answer that Gemma is asking, but if you look more carefully at that algorithm, it only gives you the answer to the question: How can I determine the lowest level I can set minSDK so that the application compiles without error? That's maybe what Gemma's question is all about, but my point is that's not the right approach. Be aware that just because you can compile your code without errors, it doesn't necessarily mean that you application will run on the range of SDK you've specified. Remember, there's also the targetSDK. The targetSDK is the latest version of the API that you have tested and verified that you application works correctly on. The targetSDK can be greater than the compileSDK. If that's the case, you'll get a compiler error if you try and use any new functionality greater than your compileSdk because the compiler will consider that new functionality as undefined. The issue is that you won't get any errors if you use a deprecated or removed capability introduce since the compileSDK. The build process doesn't know about what happens to an SDK beyond the SDK that you compiled against. That's why targetSdk is defined to be the latest version that you've tested against. If you've thoroughly tested your application on a the targetSdk platform, then you've also have verified that you aren't using deprecated or removed functionality introduced in an SDK version greater than you compiled against.
If you're interested, you can look at your compiled SDK location and find the platform directory that you are compiling against and you'll find a file named "api-versions.xml". Each SDK version has that file. If you examine it, you'll see the complete history of all additions, deprecation, and removal of SDK functionality since version 1. That's obviously what the build tool is using to report potential SDK error and warnings to you.
And lastly, there's a QA issue. Let's say you specify a minSDK as 14, compileSdk as 33 and targetSDK to 34, what versions of platforms should you test your code under? Clearly we know that you have to test it under a 34 api platform, because that's what targetSds means. Not to test under the targetSdk would be an invalid product claim. Well, what about platforms with API 14, 15, 16, .. , 33? Should you test on all of them or just some of them. The greatest level of quality assurance would be that you've tested the application in each of those platforms or how else can you make the claim it works as designed on all those platforms. Perhaps that's overzealous, but that still remains a valid question or concern for QA. That question gets back to my statement about the min SDK version. When you develop an application, you should carefully decide what platforms you want the application to run on. You certainly increase QA testing time specifying a range greater than what your intended market is.
Upvotes: 2
Reputation: 29
I often use 14 or 16, but if your app has library's that the min SDK version not support then set it higher or find out in Google docs or other .. , flutter, ...
Upvotes: 0
Reputation: 1
I was wondering as well if there was a less tedious way to do this.
Apparently, using a minSdkVersion set to "1" in build.gradle and running the gradle lint
task on the app will do this semi-automatically by stopping on the first incompatible library and indicating the needed version.
Also described here: Easy way to detect android:minSdkVersion automatically?
Upvotes: 0
Reputation: 188
I can't understand if it's what you are asking for but this is how I do this. I often forget where to find this info too.
Go to: File
> Project Structure
, then under modules
choose your module (that probably will be app
, then under the tab flavors
you can see minimum sdk and target sdk. There is no maximum because many things changes during times.
Or you can go to the gradle file, find the one under the app
scope and there are the info you are asking for.
source:
https://abhiandroid.com/androidstudio/change-api-sdk-level-android-studio.html
Upvotes: 1
Reputation: 72
For the absolute minSdkVersion that you can actually set for the current status/version of app (as you said in comments) you can identify it using brute force:
Upvotes: 5
Reputation: 73
To determine minSdk and maxSdk see build.gradle(Module: app) in Gradle Scripts. See the project structure:
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "app.id"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
Upvotes: 4