16

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.

Gemma
  • 161
  • 1
  • 1
  • 5
  • welcome to stack overflow :) i've updated your question to remove the part where you ask for a tool to achieve this, because asking for tools or off-site resources might get your question closed as we don't allow questions for off-site resources here, but the rest of your question is fine – a_local_nobody Jul 01 '20 at 20:33
  • I'm sorry I wasnt aware of that but I think I should have asked if there is anyway in android studio to determine minimum API Level used in my project. Like for example "TO DO" tracks of all tasks etc, do we have any feature in Android studio to determine minimum API Level. Thanks a lot for updating my question. – Gemma Jul 01 '20 at 20:37
  • feel free to [edit](https://stackoverflow.com/posts/62684839/edit) your question as you would like if you would like to make it specific to android studio :) – a_local_nobody Jul 01 '20 at 20:38
  • Thank you. I've updated the question :) – Gemma Jul 01 '20 at 20:49

5 Answers5

4

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:

  1. Set minSdkVersion to 1
  2. build the project.
  3. If it builds then current minSdkVersion is the absolute minSdkVersion, else it will give an error telling some dependencies to the anotherSdkVersion, now set minSdkVersion to anotherSdkVersion --go to step 2.
3

To determine minSdk and maxSdk see build.gradle(Module: app) in Gradle Scripts. See the project structure:

  • compileSdkVersion is de maxSdk.
  • minSdkVersion is minSdk.
  • targetSdkVersion is de maxSdk tested version.
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
    }
}
1

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

Zoe
  • 27,060
  • 21
  • 118
  • 148
J.J.Enrik
  • 180
  • 1
  • 9
  • Will this automatically assess the minimum API Level used in my project and show the result? – Gemma Jul 01 '20 at 21:27
  • are you talking about the gradle file? anyway every changes in the file or the project structure will trigger the evaluation of your entire code just like android studio is already doing with the current levels – J.J.Enrik Jul 01 '20 at 21:34
  • 3
    Im not asking about a "way" to change minimum sdk or target sdk. Im asking if I keep developing developing and when I finish it how do I know what is the minimum sdk requirement for my project? How do I keep track of which code used what API Level and what was the smallest API Level any of my code used in my project? – Gemma Jul 01 '20 at 21:56
0

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?

0

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, ...

ABC ABC
  • 19
  • 2