Skip to content

Commit ea212a2

Browse files
authored
[pigeon] pin native interop related dev deps and update some docs (#13103)
related to dart-lang/native#3723 pins dev deps to avoid unexpected underlying changes to generated code or it's effects
1 parent 249ddc0 commit ea212a2

12 files changed

Lines changed: 66 additions & 42 deletions

File tree

‎packages/pigeon/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 29.0.6
2+
3+
* Updates native interop guides and migration skill with SwiftPM `<plugin_name>_objc_gen` target guidance.
4+
* Updates FFI and JNI dependencies and pins code generation `dev_dependencies` (`ffigen`, `jnigen`, `swift2objc`, and `swiftgen`).
5+
16
## 29.0.5
27

38
* [dart] Fixes JNI typed data arrays being backed by native memory that is freed when

‎packages/pigeon/example/native_interop_app/lib/src/native_interop_example.g.jni.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AUTO GENERATED BY JNIGEN 1.0.0. DO NOT EDIT!
1+
// AUTO GENERATED BY JNIGEN 1.0.1. DO NOT EDIT!
22

33
// Copyright 2013 The Flutter Authors
44
// Use of this source code is governed by a BSD-style license that can be
@@ -40,7 +40,7 @@ import 'dart:core' show Object, String;
4040
import 'package:jni/_internal.dart' as jni$_;
4141
import 'package:jni/jni.dart' as jni$_;
4242

43-
const _$jniVersionCheck = jni$_.JniVersionCheck(1, 0);
43+
const _$jniVersionCheck = jni$_.JniVersionCheck(1, 1);
4444

4545
/// from: `dev.flutter.pigeonnativeinteropapp.FlutterError`
4646
extension type FlutterError._(jni$_.JObject _$this) implements RuntimeException {

‎packages/pigeon/example/native_interop_app/pubspec.yaml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ dependencies:
1010
ffi: ^2.2.0
1111
flutter:
1212
sdk: flutter
13-
jni: ^1.0.3
14-
objective_c: ^9.5.0
13+
jni: ^1.1.0
14+
objective_c: ^9.6.2
1515

1616
dev_dependencies:
1717
build_runner: ^2.1.10
18-
ffigen: ^22.0.0
18+
ffigen: 22.0.0
1919
flutter_test:
2020
sdk: flutter
2121
integration_test:
2222
sdk: flutter
23-
jnigen: ^1.0.0
23+
jnigen: 1.0.1
2424
logging: ^1.3.0
2525
pigeon:
2626
path: ../../
2727
pub_semver: ^2.1.4
28-
swift2objc: ^0.3.0
29-
swiftgen: ^0.2.0
28+
swift2objc: 0.3.1
29+
swiftgen: 0.2.0
3030

3131
flutter:
3232
uses-material-design: true

‎packages/pigeon/lib/src/generator_tools.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'generator.dart';
1616
/// The current version of pigeon.
1717
///
1818
/// This must match the version in pubspec.yaml.
19-
const String pigeonVersion = '29.0.5';
19+
const String pigeonVersion = '29.0.6';
2020

2121
/// Default plugin package name.
2222
const String defaultPluginPackageName = 'dev.flutter.pigeon';

‎packages/pigeon/native_interop_guide.md‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ flutter pub add jni
7777
flutter pub add dev:jnigen dev:logging dev:path
7878
```
7979

80-
*Note: Ensure the resolved `objective_c` version in `pubspec.yaml` matches the version expected by your `ffigen` version (e.g., `ffigen: ^22.0.0` generates bindings that require `objective_c: ^9.6.0`).*
81-
8280
### Step 2: Configure Pigeon Options
8381

8482
Enable Native Interop for your target platforms by setting the configuration options in your Pigeon file:
@@ -157,11 +155,14 @@ s.source_files = 'Sources/**/*.{swift,m,h}'
157155
This allows CocoaPods to automatically compile the generated Objective-C bridging files into the framework.
158156

159157
#### Swift Package Manager (SwiftPM) Configuration
160-
Because Swift and Objective-C files cannot reside within the same SwiftPM target, you must define two separate targets in your `Package.swift` file:
158+
**Only if a `.m` file is generated** in `<swift_output_dir>_objc_gen`, you must configure a separate Objective-C target in your `Package.swift` file. Because Swift and Objective-C files cannot reside within the same SwiftPM target, define two separate targets:
161159
1. An Objective-C target for the generated bridge files (e.g., `my_plugin_objc_gen`).
162160
2. The main Swift target that depends on the Objective-C target.
163161

164-
Example configuration:
162+
> **Important:** If your Pigeon schema only uses synchronous `@HostApi()` methods (and does not generate a `.m` file in `<swift_output_dir>_objc_gen`), **do not** add the `<plugin_name>_objc_gen` target to `Package.swift`. SwiftPM requires every `.target` to contain at least one compilable source file (`.m`, `.c`, or `.swift`). Declaring a `<plugin_name>_objc_gen` target when the directory only contains a `.h` header (or temporary `.o` file) will cause Xcode builds to fail with:
163+
> `Build input file cannot be found: '.../<plugin_name>_objc_gen.o'`
164+
165+
Example configuration (when `<plugin_name>_objc_gen` contains a generated `.m` file):
165166
<?code-excerpt "platform_tests/test_plugin/darwin/test_plugin/Package.swift (swiftpm-targets)"?>
166167
```swift
167168
targets: [
@@ -204,7 +205,7 @@ When implementing Native Interop host APIs directly in an application target rat
204205

205206
## 5. Troubleshooting Automated Generation
206207

207-
If `dart run pigeon` encounters errors while running `jnigen` or `ffigen`, review the following troubleshooting steps:
208+
If `dart run pigeon` or your platform build encounters errors, review the following troubleshooting steps:
208209

209210
### 5.1 Unupdated Native Implementation or Uncompiled Code (JNI)
210211

@@ -256,6 +257,12 @@ F DartJNI : JNI is not initialized. Are you trying to invoke a Java API from Dar
256257
- **Cause**: Your plugin's `registerWith()` method (invoked by Flutter's `_PluginRegistrant.register()` before `main()`) constructed your Dart plugin class, and its constructor eagerly called `<MyApi>.createWithNativeInteropApi()` before `JniPlugin` initialized `DartJNI`.
257258
- **Solution**: Initialize `<MyApi>.createWithNativeInteropApi()` lazily using `late final` rather than eagerly in the constructor initializer list (see [Section 4 of the Migration Guide](./native_interop_migration_guide.md#4-dart-client-adaptation)).
258259

260+
### 5.6 Xcode Error: `Build input file cannot be found: '.../<plugin_name>_objc_gen.o'`
261+
262+
If an iOS or macOS SwiftPM build fails because `<plugin_name>_objc_gen.o` cannot be found:
263+
- **Cause**: `Package.swift` defines a `<plugin_name>_objc_gen` target, but `ffigen` did not generate a `.m` implementation file in `Sources/<plugin_name>_objc_gen/` (because the Pigeon schema has no async callbacks, closures, or `@FlutterApi` methods requiring Objective-C trampolines). Without a `.m` source file, SwiftPM does not produce an object file for the target. (Note: any `.o` file produced inside `Sources/<plugin_name>_objc_gen/` during `ffigen` execution is a temporary `swiftc` artifact and must not be committed or used.)
264+
- **Solution**: Remove the `<plugin_name>_objc_gen` target and its dependency entry from `Package.swift`.
265+
259266
---
260267

261268
## 6. Migration from Platform Channels

‎packages/pigeon/native_interop_migration_guide.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ flutter pub add jni
4343
flutter pub add dev:jnigen dev:logging dev:path
4444
```
4545

46-
*Note: Ensure the resolved `objective_c` version in `pubspec.yaml` matches the version expected by your `ffigen` version (e.g., `ffigen: ^22.0.0` generates bindings that require `objective_c: ^9.6.0`).*
47-
4846
### 2.2 Update Pigeon Configuration Options
4947

5048
In your Pigeon Dart definition file, update `@ConfigurePigeon` to enable `useJni: true` for Kotlin and/or `useFfi: true` for Swift:
@@ -171,10 +169,17 @@ From the Dart side, instantiate your generated Host API using `<MyApi>.createWit
171169

172170
## 5. iOS/macOS Build System Configuration (FFI)
173171

174-
For Swift FFI, the toolchain generates an Objective-C bridging target under `<swift_output_dir>_objc_gen`. Ensure your build system includes these Objective-C files:
172+
For Swift FFI, the toolchain generates an Objective-C bridging directory under `<swift_output_dir>_objc_gen`:
173+
- **`.h` (Headers)**: Always generated to declare module interfaces and types for `ffigen`.
174+
- **`.m` (Bridging Implementation)**: Only generated when the schema contains async callbacks, closures, `@FlutterApi`, or Objective-C blocks requiring trampoline implementations.
175+
- **`.o` (Temporary Object Files)**: Intermediate binary files generated during `ffigen`/`swiftgen` AST parsing. These are **not** needed after code generation and must **not** be committed to version control.
176+
177+
Ensure your build system is configured appropriately:
175178

176179
- **CocoaPods**: Ensure `s.source_files = 'Sources/**/*.{swift,m,h}'` in your `.podspec`.
177-
- **SwiftPM**: Add a separate Objective-C target for `my_plugin_objc_gen` in `Package.swift` and depend on it from your main Swift target.
180+
- **SwiftPM (`Package.swift`)**:
181+
- **Only if a `.m` file is generated** in `<swift_output_dir>_objc_gen`: Add a separate Objective-C target for `<plugin_name>_objc_gen` in `Package.swift` and depend on it from your main Swift target.
182+
- **If no `.m` file is generated** (e.g., your schema only has synchronous `@HostApi()` methods and `<swift_output_dir>_objc_gen` only contains a `.h` header): **Do not** add the `<plugin_name>_objc_gen` target to `Package.swift`. SwiftPM requires at least one compilable source file (`.m`, `.c`, or `.swift`) per target; an empty/header-only target causes Xcode builds to fail with `Build input file cannot be found: '.../<plugin_name>_objc_gen.o'`.
178183
- **Application & Example App Targets**:
179184
- **Swift Module Name**: Set `ffiModuleName` in `SwiftOptions` to match your application's Swift module name (defaults to `'Runner'`). If iOS and macOS share the same generated Dart FFI file, both platforms must compile under that same module name. Since Flutter's default macOS template sets the module name to the app name rather than `Runner`, you can unify them by setting `PRODUCT_MODULE_NAME = Runner` in `macos/Runner/Configs/AppInfo.xcconfig` (or by matching whatever module name you configure). If iOS and macOS use separate Pigeon generation outputs or you only target one platform, unifying module names across platforms is not required.
180185
- **Native Registration**: Register the native API implementation in native code (e.g., `MainFlutterWindow.swift` in `awakeFromNib()` on macOS, or `AppDelegate.swift` on iOS via `MyApiSetup.register(api: api)`). This also ensures the setup class is referenced so the Xcode linker does not strip it (`-dead_strip`).

‎packages/pigeon/platform_tests/shared_test_plugin_code/lib/src/generated/native_interop_tests.gen.jni.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// AUTO GENERATED BY JNIGEN 1.0.0. DO NOT EDIT!
1+
// AUTO GENERATED BY JNIGEN 1.0.1. DO NOT EDIT!
22

33
// Copyright 2013 The Flutter Authors
44
// Use of this source code is governed by a BSD-style license that can be
@@ -41,7 +41,7 @@ import 'dart:core' show Object, String;
4141
import 'package:jni/_internal.dart' as jni$_;
4242
import 'package:jni/jni.dart' as jni$_;
4343

44-
const _$jniVersionCheck = jni$_.JniVersionCheck(1, 0);
44+
const _$jniVersionCheck = jni$_.JniVersionCheck(1, 1);
4545

4646
/// from: `com.example.test_plugin.NativeInteropTestsError`
4747
extension type NativeInteropTestsError._(jni$_.JObject _$this) implements RuntimeException {

‎packages/pigeon/platform_tests/shared_test_plugin_code/pubspec.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ dependencies:
1919
sdk: flutter
2020
integration_test:
2121
sdk: flutter
22-
jni: ^1.0.3
22+
jni: ^1.1.0
2323
meta: ^1.17.0
2424
mockito: ^5.4.4
25-
objective_c: ^9.5.0
25+
objective_c: ^9.6.2
2626

2727
dev_dependencies:
28-
ffigen: ^22.0.0
29-
jnigen: ^1.0.0
28+
ffigen: 22.0.0
29+
jnigen: 1.0.1
3030
leak_tracker: any

‎packages/pigeon/platform_tests/test_plugin/example/pubspec.yaml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ dependencies:
99
ffi: ^2.2.0
1010
flutter:
1111
sdk: flutter
12-
jni: ^1.0.3
13-
objective_c: ^9.5.0
12+
jni: ^1.1.0
13+
objective_c: ^9.6.2
1414
pub_semver: ^2.2.0
1515
shared_test_plugin_code:
1616
path: ../../shared_test_plugin_code
1717
test_plugin:
1818
path: ../
1919

2020
dev_dependencies:
21-
ffigen: ^22.0.0
21+
ffigen: 22.0.0
2222
flutter_test:
2323
sdk: flutter
2424
integration_test:
2525
sdk: flutter
26-
jnigen: ^1.0.0
26+
jnigen: 1.0.1
2727
logging: ^1.3.0
2828
pigeon:
2929
path: ../../..
30-
swift2objc: ^0.3.0
31-
swiftgen: ^0.2.0
30+
swift2objc: 0.3.1
31+
swiftgen: 0.2.0
3232

3333
flutter:
3434
uses-material-design: true

‎packages/pigeon/platform_tests/test_plugin/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies:
2828
ffi: ^2.2.0
2929
flutter:
3030
sdk: flutter
31-
jni: ^1.0.3
31+
jni: ^1.1.0
3232

3333
dev_dependencies:
3434
flutter_test:

0 commit comments

Comments
 (0)