Repository navigation
feat(android): migrate plugins to built-in Kotlin on Flutter 3.44 - #18922
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the SDK and Flutter constraints across multiple packages, disables the prefer_initializing_formals linter rule, and applies extensive code formatting and style cleanups. The review feedback highlights several violations of the repository's style guide regarding null safety, specifically pointing out the prohibited use of the non-null assertion operator (!) in test files and method channels, and recommends replacing them with proper null checks and flow analysis.
| PersistentCacheIndexManager? indexManager = firestore | ||
| .persistentCacheIndexManager(); | ||
| await indexManager!.enableIndexAutoCreation(); | ||
| await indexManager.disableIndexAutoCreation(); | ||
| await indexManager.deleteAllIndexes(); |
There was a problem hiding this comment.
According to the repository style guide (rule 23), the ! operator should not be used. Instead, use flow analysis with a null check to ensure type safety and avoid potential runtime errors.
PersistentCacheIndexManager? indexManager = firestore
.persistentCacheIndexManager();
if (indexManager != null) {
await indexManager.enableIndexAutoCreation();
await indexManager.disableIndexAutoCreation();
await indexManager.deleteAllIndexes();
}References
- Null Safety: NO
!operator. Use?and flow analysis (e.g.if (x != null)). (link)
| PersistentCacheIndexManager? indexManager = firestore | ||
| .persistentCacheIndexManager(); | ||
|
|
||
| expect(indexManager, isNull); | ||
| } else { | ||
| final firestore = FirebaseFirestore.instanceFor( | ||
| app: Firebase.app(), | ||
| databaseId: 'other-platform-disabled', | ||
| ); | ||
| // macOS, android, iOS have persistence enabled by default so we disable it | ||
| firestore.settings = const Settings(persistenceEnabled: false); | ||
| PersistentCacheIndexManager? indexManager = firestore | ||
| .persistentCacheIndexManager(); | ||
| expect(indexManager, isNull); | ||
| } | ||
| }, | ||
| skip: defaultTargetPlatform == TargetPlatform.windows, | ||
| ); | ||
| await indexManager!.enableIndexAutoCreation(); | ||
| await indexManager.disableIndexAutoCreation(); | ||
| await indexManager.deleteAllIndexes(); |
There was a problem hiding this comment.
Avoid using the ! operator on indexManager as per the repository style guide (rule 23). Use flow analysis instead.
| PersistentCacheIndexManager? indexManager = firestore | |
| .persistentCacheIndexManager(); | |
| expect(indexManager, isNull); | |
| } else { | |
| final firestore = FirebaseFirestore.instanceFor( | |
| app: Firebase.app(), | |
| databaseId: 'other-platform-disabled', | |
| ); | |
| // macOS, android, iOS have persistence enabled by default so we disable it | |
| firestore.settings = const Settings(persistenceEnabled: false); | |
| PersistentCacheIndexManager? indexManager = firestore | |
| .persistentCacheIndexManager(); | |
| expect(indexManager, isNull); | |
| } | |
| }, | |
| skip: defaultTargetPlatform == TargetPlatform.windows, | |
| ); | |
| await indexManager!.enableIndexAutoCreation(); | |
| await indexManager.disableIndexAutoCreation(); | |
| await indexManager.deleteAllIndexes(); | |
| PersistentCacheIndexManager? indexManager = firestore | |
| .persistentCacheIndexManager(); | |
| if (indexManager != null) { | |
| await indexManager.enableIndexAutoCreation(); | |
| await indexManager.disableIndexAutoCreation(); | |
| await indexManager.deleteAllIndexes(); | |
| } |
References
- Null Safety: NO
!operator. Use?and flow analysis (e.g.if (x != null)). (link)
| PersistentCacheIndexManager? indexManager2 = firestore2 | ||
| .persistentCacheIndexManager(); | ||
|
|
||
| await indexManager2!.enableIndexAutoCreation(); | ||
| await indexManager2.disableIndexAutoCreation(); | ||
| await indexManager2.deleteAllIndexes(); |
There was a problem hiding this comment.
Avoid using the ! operator on indexManager2 as per the repository style guide (rule 23). Use flow analysis instead.
| PersistentCacheIndexManager? indexManager2 = firestore2 | |
| .persistentCacheIndexManager(); | |
| await indexManager2!.enableIndexAutoCreation(); | |
| await indexManager2.disableIndexAutoCreation(); | |
| await indexManager2.deleteAllIndexes(); | |
| PersistentCacheIndexManager? indexManager2 = firestore2 | |
| .persistentCacheIndexManager(); | |
| if (indexManager2 != null) { | |
| await indexManager2.enableIndexAutoCreation(); | |
| await indexManager2.disableIndexAutoCreation(); | |
| await indexManager2.deleteAllIndexes(); | |
| } |
References
- Null Safety: NO
!operator. Use?and flow analysis (e.g.if (x != null)). (link)
| PersistentCacheIndexManager? indexManager = firestore | ||
| .persistentCacheIndexManager(); | ||
| await indexManager!.enableIndexAutoCreation(); | ||
| await indexManager.disableIndexAutoCreation(); | ||
| await indexManager.deleteAllIndexes(); |
There was a problem hiding this comment.
Avoid using the ! operator on indexManager as per the repository style guide (rule 23). Use flow analysis instead.
PersistentCacheIndexManager? indexManager = firestore
.persistentCacheIndexManager();
if (indexManager != null) {
await indexManager.enableIndexAutoCreation();
await indexManager.disableIndexAutoCreation();
await indexManager.deleteAllIndexes();
}References
- Null Safety: NO
!operator. Use?and flow analysis (e.g.if (x != null)). (link)
| final observerId = await task; | ||
|
|
||
| final nativePlatformStream = | ||
| MethodChannelFirebaseFirestore.loadBundleChannel( | ||
| observerId!, | ||
| ).receiveBroadcastStream(); | ||
| MethodChannelFirebaseFirestore.loadBundleChannel(observerId!) | ||
| .receiveBroadcastStream(); |
There was a problem hiding this comment.
Avoid using the ! operator on observerId as per the repository style guide (rule 23). Use flow analysis instead.
final observerId = await task;
if (observerId == null) {
throw StateError('Observer ID cannot be null');
}
final nativePlatformStream =
MethodChannelFirebaseStorage.loadBundleChannel(observerId)
.receiveBroadcastStream();References
- Null Safety: NO
!operator. Use?and flow analysis (e.g.if (x != null)). (link)
| if (credential is PhoneAuthCredential) { | ||
| return auth_interop.PhoneAuthProvider.credential( | ||
| credential.verificationId!, | ||
| credential.smsCode!, | ||
| ) | ||
| as auth_interop.OAuthCredential; | ||
| credential.verificationId!, | ||
| credential.smsCode!, | ||
| ) as auth_interop.OAuthCredential; | ||
| } |
There was a problem hiding this comment.
Avoid using the ! operator on credential.verificationId and credential.smsCode as per the repository style guide (rule 23). Use flow analysis instead.
if (credential is PhoneAuthCredential) {
final verificationId = credential.verificationId;
final smsCode = credential.smsCode;
if (verificationId == null || smsCode == null) {
throw ArgumentError('verificationId and smsCode must not be null');
}
return auth_interop.PhoneAuthProvider.credential(
verificationId,
smsCode,
) as auth_interop.OAuthCredential;
}References
- Null Safety: NO
!operator. Use?and flow analysis (e.g.if (x != null)). (link)
Flutter 3.44 is the minimum that builds a plugin which no longer applies the Kotlin Gradle Plugin while android.builtInKotlin is off. Dart 3.12 ships with that release. The Dart 3.13 reformat belonged to the higher floor.
Stop applying the Kotlin Gradle Plugin, including the AGP version guard. Flutter 3.50 lowers the pub.dev score for that apply line, and AGP 10 rejects it. When built-in Kotlin is on, AGP already provides the kotlin extension. When it is off, Flutter applies the plugin after this script and the JVM target is set then. Updates the minimum supported SDK version to Flutter 3.44/Dart 3.12. Migrates to built-in Kotlin.
319056f to
7189271
Compare
Dart 3.12 keeps the public name of a private named parameter, so this._apiKey is still called as apiKey:. The analyzer flags the old assignments when infos are fatal.
These two constructors still failed prefer_initializing_formals after the first pass. The public argument names stay onError and data.
Flutter's KGP check (FlutterPluginUtils.detectApplyingKotlinGradlePlugin) matches `apply plugin: 'kotlin-android'` in the build script text, so the AGP 9 guard still gets core, auth, storage, crashlytics, app_check and cloud_functions named in its "plugins that apply KGP" warning. Flutter >= 3.44 applies KGP to plugins itself when android.builtInKotlin=false, so the guard is not needed (upstream firebase#18922, not yet released). Based on the 2026-10-23 release, BoM 5.1.0 (firebase_core 5.1.0, firebase_auth 7.0.1, firebase_storage 14.0.1, firebase_crashlytics 6.0.1, firebase_app_check 0.5.1, cloud_functions 7.0.1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Description
Migrates the Android plugins that apply the Kotlin Gradle Plugin onto AGP built-in Kotlin, and sets the minimum SDK constraint to Dart
^3.12.0/ Flutter>=3.44.0.Flutter 3.50 lowers the pub.dev score of a plugin that still applies the Kotlin Gradle Plugin, even behind an AGP version guard, and that apply fails under AGP 10. The plugin-author guide sets the minimum at Flutter 3.44 / Dart 3.12. That floor is what lets an app build the migrated plugin on AGP 9 with
android.builtInKotlin=false. Turning built-in Kotlin on in an example app needs Flutter 3.47, so the examples stay on the off setting.The thirteen plugins that applied
kotlin-androidno longer do. When AGP is 9 or newer and built-in Kotlin is on, the plugin sets the JVM target on the extension AGP already registered. Otherwise it waits until Flutter appliesorg.jetbrains.kotlin.androidand sets the target then.plugins.withIdis not an apply, so Flutter's detector does not flag it. Cloud Firestore and Firebase Messaging never applied the plugin, so their Gradle files stay as they are.Apps below Flutter 3.44 keep resolving the current published releases. This follows the same non-breaking treatment as #18634.
Flutter 3.50 stable also refuses the Android toolchain the examples were using. Example apps, the Firestore pipeline example, and
tests/androidnow use the Flutter 3.50 template versions: Gradle 9.5.0, Android Gradle Plugin 9.3.1, and Kotlin Gradle Plugin 2.4.20, withandroid.builtInKotlin=falseandandroid.newDsl=false. Google Services is 4.5.0, the Crashlytics Gradle plugin is 3.0.8, and the Performance Gradle plugin is 2.0.2. The published plugin constraint stays Flutter 3.44.Related Issues
Fixes #18956
Fixes the Kotlin Gradle Plugin warning for the migrated plugins once this release is published.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
Apps below Flutter 3.44 stay on the current releases. An app that already meets the new floor does not have to change its Gradle files to keep building with built-in Kotlin off.
Test plan
sdk: ^3.12.0, and every Flutter package pubspec is onflutter: >=3.44.0.android/build.gradlestill containsapply plugin: 'kotlin-android'.dart formatreports no further changes at the Dart 3.12 language version.tests/androidGradle configuration succeeds on Flutter 3.50 with Gradle 9.5.0, AGP 9.3.1, and KGP 2.4.20.Melos writes the release notes from the commits. The floor change is
feat: update the minimum supported SDK version to Flutter 3.44/Dart 3.12, and the Gradle migration isfeat(android): migrate plugins to built-in Kotlin.