Short explanation on Gradle, minSdkVersion, maxSdkVersion, compileSdkVersion and targetSdkVersion in Android
Gradle:
The Android build system compiles app resources and source code, and packages them into APKs that you can test, deploy, sign, and distribute. Android Studio uses Gradle.
The Android plugin for Gradle works with the build toolkit to provide processes and configurable settings that are specific to building and testing Android applications.Gradle and the Android plugin run independent of Android Studio. Gradle architecture is shown below.
Example:
android {
compileSdkVersion 27
buildToolsVersion “26.0.2”
defaultConfig {
applicationId “com.example.checkyourtargetsdk"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName “1.0”
}
}
minSdkVersion:
minSdkVersion is the lower bound for your app. The minSdkVersion is one of the signals the Google Play Store uses to determine which of a user’s devices an app can be installed on.
your app’s minSdkVersion must be at least as high as your dependencies’ minSdkVersion
When deciding on a minSdkVersion, you should consider the stats on theDashboards, which give you a global look on all devices that visited the Google Play Store in the prior 7 days — that’s your potential audience when putting an app on Google Play .
compileSdkVersion:
compileSdkVersion is your way to tell Gradle what version of the Android SDK to compile your app with.
Therefore it is strongly recommended that you always compile with the latest SDK. You’ll get all the benefits of new compilation checks on existing code, avoid newly deprecated APIs, and be ready to use new APIs.
App can run on device with lower API level if code execution paths do not attempt to invoke any unavailable APIs (except constans which will be simply copied into an app). Value should be always set to the highest stable API level, even if app does not use any API from it. This is due to the fact that some API may be deprecated, stop working.
targetSdkVersion:
targetSdkVersion is the main way Android provides forward compatibility by not applying behavior changes unless the targetSdkVersion is updated. This allows you to use new APIs prior to working through the behavior changes.
targetSdkVersion
is a hint for system on which app is running, indicating which API level is app designed for.maxSdkVersion:
In docs they stated that they are not effective from 2.1 and also in warning they stated that "declaring the attribute can result in your application being removed from users' devices after a system update to a higher API Level.
An integer designating the maximum API Level on which the application is designed to run.
From Doc: In Android 1.5, 1.6, 2.0, and 2.0.1, the system checks the value of this attribute when installing an application and when re-validating the application after a system update. In either case, if the application's
maxSdkVersion attribute is lower than the API Level used by the system itself, then the system will not allow the application to be installed. In the case of re-validation after system update, this effectively removes your application from the device. |
Conditions when using the Android SDK Version in build.gradle
- There is also a restriction that
minSdkVersion
of given module cannot be lower than the value in any dependent module eg: you cannot use version 7.5.0 of Google Play Services library (which
minSdkVersion
is 9
) in an app which has that value set to 8-
targetSdkVersion
should not be set to value higher than compileSdkVersion
relationship between the three values
minSdkVersion <= targetSdkVersion <= compileSdkVersion
Also,
minSdkVersion (lowest possible) <= targetSdkVersion == compileSdkVersion (latest SDK)
This intuitively makes sense — if compileSdkVersion is your ‘maximum’ and minSdkVersion is your ‘minimum’ then your maximum must be at least as high as your minimum and the target must be somewhere in between.
You’ll hit the biggest audience with a low minSdkVersion and look and act the best by targeting and compiling with the latest SDK — a great way to better apps.
AndroidManifest.xml, you’d see a tag such as:
<uses-sdk android:targetSdkVersion=”27" android:minSdkVersion=”7" />
it’ll be ignored when you build with Gradle (although other build systems might certainly rely on it being there).
Reference:
Digi Tech Tricks
ReplyDeletehigh as your minimum and