|
| 1 | +# Android Api and Related versions |
| 2 | + |
| 3 | +Picking the full suite of android versions can be difficult if you are not a full time android developer. |
| 4 | +This document is for contributors to understand what versions of common android tooling should be used in the flutter/flutter codebase. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +**The most important thing is for any test, project, or app to have compatible versions. ** |
| 9 | + |
| 10 | +If versions need to be different then a comment explaining why and what is being evaluated should be included. |
| 11 | +All chosen versions should pass the minimum versions checks defined in [DependencyVersionChecker](https://github.com/flutter/flutter/blob/main/packages/flutter_tools/gradle/src/main/kotlin/DependencyVersionChecker.kt) |
| 12 | + |
| 13 | +If the versions chosen are not known by [gradle_utils.dart](https://github.com/flutter/flutter/blob/a16c447abcb695b4ca907d59e66dc87f4f7178d3/packages/flutter_tools/lib/src/android/gradle_utils.dart#L63) then update gradle_utils.dart. |
| 14 | + |
| 15 | +## Specifics |
| 16 | + |
| 17 | +### compileSdk |
| 18 | + |
| 19 | +- Must be higher then or equal to `targetSdk`. |
| 20 | +- Should be `compileSdk` instead of `compileSdkVersion`. |
| 21 | +- Should be the max stable value available in CIPD if not `flutter.compileSdkVersion`. |
| 22 | +- Must have a comment if an api level lower than max is chosen intentionally. |
| 23 | + |
| 24 | +``` |
| 25 | +// OK |
| 26 | +android { |
| 27 | + compileSdk flutter.compileSdkVersion |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +``` |
| 32 | +// OK if flutter.compileSdkVersion is not available like in an add to app example. |
| 33 | +android { |
| 34 | + compileSdk 35 |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +``` |
| 39 | +// NOT OK |
| 40 | +android { |
| 41 | + compileSdk 28 |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### targetSdk |
| 46 | + |
| 47 | +- Must be higher then or equal to `minSdk`. |
| 48 | +- Should be `targetSdk` instead of `targetSdkVersion`. |
| 49 | +- `targetSdk` takes human level effort to update. This is a design decision by the AGP team. |
| 50 | +- `targetSdk` may lag behind compile sdk because of the effort to update. |
| 51 | +- If the `targetSdk` version is intentionally different there should be a comment explaining why. |
| 52 | + |
| 53 | +``` |
| 54 | +// OK |
| 55 | +defaultConfig { |
| 56 | + targetSdk flutter.targetSdkVersion |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +``` |
| 61 | +// OK if flutter.compileSdkVersion is not available like in an add to app example. |
| 62 | +defaultConfig { |
| 63 | + targetSdk 35 |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +``` |
| 68 | +// NOT OK |
| 69 | +defaultConfig { |
| 70 | + targetSdk 28 |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +### AGP |
| 75 | +AKA `com.android.application`, `com.android.tools.build:gradle` `com.android.library` |
| 76 | + |
| 77 | +- "AGP" version should be the version set in flutter templates or newer. |
| 78 | +- If the version is intentionally different there should be a comment explaining why. |
| 79 | + |
| 80 | + |
| 81 | +``` |
| 82 | +// OK |
| 83 | +dependencies { |
| 84 | + classpath "com.android.tools.build:gradle:8.8.1" |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +``` |
| 89 | +// OK |
| 90 | +dependencies { |
| 91 | + // Testing backwards compatability of feature XYZ |
| 92 | + classpath "com.android.tools.build:gradle:7.5.2" |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### gradle |
| 97 | + |
| 98 | +Gradle versions are the least likley to break across minor version updates. |
| 99 | + |
| 100 | +- In new code the "gradle" version should be the version set in flutter templates or newer. |
| 101 | +- In older code any gradle version that works with the other version constraints is ok. |
| 102 | +- In practice our customers use a large variety of gradle versions. |
| 103 | +- If the version is intentionally different there should be a comment explaining why. |
| 104 | + |
| 105 | +``` |
| 106 | +// OK |
| 107 | +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip |
| 108 | +``` |
| 109 | + |
| 110 | +### kotlin |
| 111 | + |
| 112 | +Changing kotlin versions is most likley to have an issue with another dependency and not the code under test. |
| 113 | + |
| 114 | +- "kotlin" version should be the version set in flutter templates or newer. |
| 115 | +- If the version is intentionally different there should be a comment explaining why. |
| 116 | + |
| 117 | +``` |
| 118 | +// Ok |
| 119 | +ext.kotlin_version = "1.7.10" |
| 120 | +... |
| 121 | +classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" |
| 122 | +``` |
0 commit comments