targetSdkVersion
The most interesting of the three version numbers is targetSdkVersion. targetSdkVersion is the main basis for Android to provide forward compatibility. The system will not apply the latest behavior changes until the targetSdkVersion of the application is updated. This allows you to use the new API before adapting to new behavior changes (because you've updated compileSdkVersion, haven't you?).
The value specified by targetSdkVersion indicates that you have fully tested the target version, and the system will enable some of the latest features and features for your application. For example, Android 6.0 system references the function of runtime permission. If you specify targetSdkVersion as 23 or higher, the system will start runtime permission for your program. If you specify the targetSdkVersion as 22, then your program can only be fully tested on Android 5.1 at most, and the new features introduced in Android 6.0 will not start.
compileSdkVersion:SDK compiled version
//noinspection GradleCompatible apply plugin: 'com.android.application' android { compileSdkVersion 26 //compileSdkVersion is the same as compile 'com.android.support:appcompat-v7:26.1.0' buildToolsVersion "26.0.1" //compileSdkVersion>targetSdkVersion defaultConfig { applicationId "com.rengwuxian.rxjavasamples" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "2.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:26.1.0' compile 'com.android.support:support-v4:26.1.0' compile 'com.android.support:support-v13:26.1.0' compile 'com.android.support:design:26.1.0' compile 'com.android.support:cardview-v7:26.1.0' compile 'com.squareup.okhttp3:okhttp:3.8.0' compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' compile 'com.github.bumptech.glide:glide:4.1.1' annotationProcessor 'com.github.bumptech.glide:compiler:4.1.1' compile 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' compile 'io.reactivex.rxjava2:rxjava:2.0.7' compile 'io.reactivex.rxjava2:rxandroid:2.0.1' compile 'com.jakewharton.rxbinding2:rxbinding:2.0.0' }
compileSdkVersion tells Gradle which Android SDK version to use to compile your app. Using any newly added API requires using the Android SDK for the corresponding Level.
It should be emphasized that modifying compileSdkVersion does not change the runtime behavior. When you modify compileSdkVersion, new compilation warnings and errors may appear, but the new compileSdkVersion will not be included in APK: it is only used during compilation. (you really should fix these warnings. There must be a reason for their appearance.)
Therefore, we strongly recommend that you always compile with the latest SDK. There are many benefits to using new compilation checks on existing code, avoiding new deprecated APIs, and preparing for new APIs.
Note that if you use the Support Library, you need to compile with the latest SDK to use the latest release of the Support Library. For example, to use the 23.1.1 version of the Support Library, compileSdkVersion must be at least 23 (the large version number must be consistent!). Generally, the new version of the Support Library is released with the new system version, which provides compatibility support for the newly added API and new features of the system.
Of course, it should be noted that the levels in some support libraries are different. Although the calling methods are the same, the source code may change.