What is the difference between compileSdkVersion and targetSdkVersion?

前端 未结 11 2110
生来不讨喜
生来不讨喜 2020-11-22 10:44

I have looked at the documentation for building with Gradle, but I\'m still not sure what the difference between compileSdkVersion and targetSdkVersion

11条回答
  •  孤独总比滥情好
    2020-11-22 11:31

    Late to the game.. and there are several great answers above-- essentially, that the compileSdkVersion is the version of the API the app is compiled against, while the targetSdkVersion indicates the version that the app was tested against.

    I'd like to supplement those answers with the following notes:

    1. That targetSdkVersion impacts the way in which permissions are requested:

      • If the device is running Android 6.0 (API level 23) or higher, and the app's targetSdkVersion is 23 or higher, the app requests permissions from the user at run-time.
      • If the device is running Android 5.1 (API level 22) or lower, or the app's targetSdkVersion is 22 or lower, the system asks the user to grant the permissions when the user installs the app.
    2. If the compileSdkVersion is higher than the version declared by your app's targetSdkVersion, the system may enable compatibility behaviors to ensure that your app continues to work the way you expect. (ref)

    3. With each new Android release...

      • targetSdkVersion should be incremented to match the latest API level, then thoroughly test your application on the corresponding platform version
      • compileSdkVersion, on the other hand, does not need to be changed unless you're adding features exclusive to the new platform version
      • As a result, while targetSdkVersion is often (initially) less than than the compileSdkVersion, it's not uncommon to see a well-maintained/established app with targetSdkVersion > compileSdkVersion

提交回复
热议问题