The functions of compileSdkVersion, minSdkVersion, targetSdkVersion, and Support libraries and their relationships

Preface

To upgrade the SDK version of an application,
you need to clarify the functions of compileSdkVersion, minSdkVersion, targetSdkVersion, and Support libraries and their relationships
to ensure that the application is configured correctly and that the application can be used normally on different systems after the upgrade.


1. The meaning and relationship of each Version

  • compileSdkVersion: The sdk version used when compiling the application (only takes effect during compilation and has nothing to do with runtime)

The android sdk version we use when compiling and packaging apk in daily development is specified by compileSdkVersion.
The APIs available in the code also correspond to this version, and APIs higher than the declared version cannot be found and used.
By the way, the version of buildtools must be consistent with compileSdkVersion 

  •  minSdkVersion: The minimum system version that the application can run

For example, after setting minSdkVersion to 14 (corresponding to Android version 4.0), the application cannot be installed on systems below Android 4.0.

 

  • targetSdkVersion: The sdk version used when the application is running (this parameter is very important!) 

The functional features of the Android SDK specified by this parameter will take effect at runtime.
For example, take the dynamic permission check function of the android6.0 (api 23) system


1. When targetSdkVersion<23:
After the application is installed on an Android 6.0 phone,
it will not execute the dynamic permission check logic unique to the Android 6.0 system or above,
but will continue to execute the previous permission check logic.

2. When targetSdkVersion changes to 23:
The dynamic permission check feature of the android6.0 system will take effect.

3. When targetSdkVersion is 25 (representing android 7.0) > 23:
When installed on an android 6.0 device, it
can still only execute features of 6.0 and below, and cannot execute new features of 7.0.

Usually targetSdkVersion is less than or equal to compileSdkVersion. Generally, targetSdkVersion is changed to the version of compileSdkVersion only 
after the version specified by compileSdkVersion is compiled and the relevant features are tested without problems.

 

  • To sum up, the best relationship is: 

minSdkVersion <= targetSdkVersion = compileSdkVersion. 
Use a lower minSdkVersion to cover the largest population, 
and set target and compile with the latest SDK to get the best appearance and behavior. 

 

2. android support support library

What is a support library: 
a function library that integrates specific framework components and UI elements. It is usually used to provide lower versions with functions that are only available in higher versions.

There are multiple support libraries. Each library supports a specific range of android versions. It is recommended to add the v4 and v7appcompat libraries.

v4: supports at least android1.6, including ViewPager, Fragment, etc. 
v7: supports at least android2.3, v7 depends on v4, including ActionBar, receylerview and other 
design support libraries (Material Design): provides some controls that conform to the design style, such as suspension Action button

Note: The major version number of the Support library must be the same as the major version number of compileSdkVersion. 

 

3. Practical examples:

In the application's build.gradle, the configuration is as follows

android {
    buildToolsVersion 22
    compileSdkVersion 22

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:22.0.0'


4. Reference articles

1. How to select compileSdkVersion, minSdkVersion and targetSdkVersion:

      https://www.open-open.com/lib/view/open1453253049558.html

2. Android official documents: Introducing compileSdkVersion, minSdkVersion and targetSdkVersion, etc.:

     https://developer.android.google.cn/studio/publish/versioning

 

Guess you like

Origin blog.csdn.net/IT666DHW/article/details/90729830