简体   繁体   中英

How to determine which minSDKVersion to set for my Android App

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.

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

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
    }
}

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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM