Repository navigation
feat: register flutter-fire-ai and flutter-fire-dc platform versions and fix web late registration #18707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: register flutter-fire-ai and flutter-fire-dc platform versions and fix web late registration #18707
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4db57d7
feat: register flutter-fire-ai and flutter-fire-dc platform versions …
kevmoo c0076f3
fix(firebase_ai): add firebase-common dependency to android build.gradle
kevmoo a846963
chore: scope firebase_ai android repositories and shorten registerWeb…
kevmoo 55a5d0b
test(core_web): add browser test for late library version registratio…
kevmoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/firebase_ai/firebase_ai/android/src/main/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,9 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="io.flutter.plugins.firebase.ai"> | ||
| <application> | ||
| <service android:name="com.google.firebase.components.ComponentDiscoveryService"> | ||
| <meta-data android:name="com.google.firebase.components:io.flutter.plugins.firebase.ai.FlutterFirebaseAppRegistrar" | ||
| android:value="com.google.firebase.components.ComponentRegistrar" /> | ||
| </service> | ||
| </application> | ||
| </manifest> |
28 changes: 28 additions & 0 deletions
28
..._ai/android/src/main/kotlin/io/flutter/plugins/firebase/ai/FlutterFirebaseAppRegistrar.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package io.flutter.plugins.firebase.ai | ||
|
|
||
| import androidx.annotation.Keep | ||
| import com.google.firebase.components.Component | ||
| import com.google.firebase.components.ComponentRegistrar | ||
| import com.google.firebase.platforminfo.LibraryVersionComponent | ||
|
|
||
| @Keep | ||
| class FlutterFirebaseAppRegistrar : ComponentRegistrar { | ||
| override fun getComponents(): List<Component<*>> { | ||
| return listOf( | ||
| LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION)) | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
packages/firebase_ai/firebase_ai/android/user-agent.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import java.util.regex.Matcher | ||
| import java.util.regex.Pattern | ||
|
|
||
| String libraryVersionName = "UNKNOWN" | ||
| String libraryName = "flutter-fire-ai" | ||
| File pubspec = new File(project.projectDir.parentFile, 'pubspec.yaml') | ||
|
|
||
| if (pubspec.exists()) { | ||
| String yaml = pubspec.text | ||
| // Using \s*['|"]?([^\n|'|"]*)['|"]? to extract version number. | ||
| Matcher versionMatcher = Pattern.compile("^version:\\s*['|\"]?([^\\n|'|\"]*)['|\"]?\$", Pattern.MULTILINE).matcher(yaml) | ||
| if (versionMatcher.find()) libraryVersionName = versionMatcher.group(1).replaceAll("\\+", "-") | ||
| } | ||
|
|
||
| android { | ||
| defaultConfig { | ||
| // BuildConfig.VERSION_NAME | ||
| buildConfigField 'String', 'LIBRARY_VERSION', "\"${libraryVersionName}\"" | ||
| // BuildConfig.LIBRARY_NAME | ||
| buildConfigField 'String', 'LIBRARY_NAME', "\"${libraryName}\"" | ||
| } | ||
| } |
16 changes: 16 additions & 0 deletions
16
packages/firebase_ai/firebase_ai/ios/firebase_ai/Sources/firebase_ai/Constants.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| /// Auto-generated file. Do not edit. | ||
| public let versionNumber = "5.0.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/firebase_ai/firebase_ai/lib/src/platform_version_stub.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| /// Stub implementation of [registerWebLibraryVersion] on non-web platforms. | ||
| void registerWebLibraryVersion(String libraryName, String version) {} |
40 changes: 40 additions & 0 deletions
40
packages/firebase_ai/firebase_ai/lib/src/platform_version_web.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import 'dart:js_interop'; | ||
| import 'dart:js_interop_unsafe'; | ||
|
|
||
| bool _registered = false; | ||
|
|
||
| /// Registers [libraryName] and [version] with the Firebase Web JS SDK. | ||
| void registerWebLibraryVersion(String libraryName, String version) { | ||
| if (_registered) return; | ||
| try { | ||
| final core = globalContext.getProperty('firebase_core'.toJS) as JSObject?; | ||
| if (core != null && core.hasProperty('registerVersion'.toJS).toDart) { | ||
| final storage = | ||
| globalContext.getProperty('sessionStorage'.toJS) as JSObject?; | ||
| final key = 'flutterfire-$libraryName-$version'.toJS; | ||
| if (storage?.callMethod<JSAny?>('getItem'.toJS, key) == null) { | ||
| storage?.callMethod<JSAny?>('setItem'.toJS, key, version.toJS); | ||
| core.callMethod<JSAny?>( | ||
| 'registerVersion'.toJS, | ||
| libraryName.toJS, | ||
| version.toJS, | ||
| ); | ||
| } | ||
| _registered = true; | ||
| } | ||
| } catch (_) {} | ||
| } | ||
|
kevmoo marked this conversation as resolved.
Resolved
|
||
1 change: 1 addition & 0 deletions
1
packages/firebase_ai/firebase_ai/macos/firebase_ai/Sources/firebase_ai/Constants.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../../ios/firebase_ai/Sources/firebase_ai/Constants.swift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/firebase_core/firebase_core_web/test/firebase_core_web_late_registration_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Copyright 2026 The Chromium Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| @TestOn('browser') | ||
| library; | ||
|
|
||
| import 'dart:js_interop'; | ||
| import 'dart:js_interop_unsafe'; | ||
|
|
||
| import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'; | ||
| import 'package:firebase_core_web/firebase_core_web.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:web/web.dart' as web; | ||
|
|
||
| String _getPlatformInfoString() { | ||
| final core = globalContext.getProperty<JSObject>('firebase_core'.toJS); | ||
| final jsApp = core.callMethod<JSObject>('getApp'.toJS); | ||
| final container = jsApp.getProperty<JSObject>('container'.toJS); | ||
| final provider = container.callMethod<JSObject>( | ||
| 'getProvider'.toJS, | ||
| 'platform-logger'.toJS, | ||
| ); | ||
| final logger = provider.callMethod<JSObject>('getImmediate'.toJS); | ||
| return logger.callMethod<JSString>('getPlatformInfoString'.toJS).toDart; | ||
| } | ||
|
|
||
| void main() { | ||
| group('FirebaseCoreWeb late library version registration', () { | ||
| setUp(() { | ||
| FirebasePlatform.instance = FirebaseCoreWeb(); | ||
| web.window.sessionStorage.clear(); | ||
| }); | ||
|
|
||
| test( | ||
| 'registers library version with PlatformLogger when called after initializeApp', | ||
| () async { | ||
| const options = FirebaseOptions( | ||
| apiKey: 'fake-api-key', | ||
| appId: '1:1234567890:web:fake', | ||
| messagingSenderId: '1234567890', | ||
| projectId: 'fake-project', | ||
| authDomain: 'fake-project.firebaseapp.com', | ||
| ); | ||
|
|
||
| await FirebasePlatform.instance.initializeApp(options: options); | ||
|
|
||
| final initialPlatformInfo = _getPlatformInfoString(); | ||
| expect(initialPlatformInfo, contains('flutter-fire-core/')); | ||
| expect( | ||
| initialPlatformInfo, | ||
| isNot(contains('flutter-fire-late-test/1.2.3')), | ||
| ); | ||
|
|
||
| FirebaseCoreWeb.registerLibraryVersion( | ||
| 'flutter-fire-late-test', | ||
| '1.2.3', | ||
| ); | ||
|
|
||
| expect( | ||
| web.window.sessionStorage | ||
| .getItem('flutterfire-flutter-fire-late-test-1.2.3'), | ||
| '1.2.3', | ||
| ); | ||
| expect( | ||
| _getPlatformInfoString(), | ||
| contains('flutter-fire-late-test/1.2.3'), | ||
| ); | ||
|
|
||
| // Clearing sessionStorage allows re-registering a subsequent version. | ||
| web.window.sessionStorage.clear(); | ||
| FirebaseCoreWeb.registerLibraryVersion( | ||
| 'flutter-fire-late-test-2', | ||
| '2.0.0', | ||
| ); | ||
| expect( | ||
| web.window.sessionStorage | ||
| .getItem('flutterfire-flutter-fire-late-test-2-2.0.0'), | ||
| '2.0.0', | ||
| ); | ||
| expect( | ||
| _getPlatformInfoString(), | ||
| contains('flutter-fire-late-test-2/2.0.0'), | ||
| ); | ||
| }, | ||
| ); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.