Skip to content

Commit

Permalink
[pigeon] Adds Kotlin support for Pigeon (#999)
Browse files Browse the repository at this point in the history
  • Loading branch information
ailtonvivaz authored Sep 22, 2022
1 parent 52fdcbc commit d2fd81d
Show file tree
Hide file tree
Showing 47 changed files with 3,206 additions and 21 deletions.
4 changes: 4 additions & 0 deletions packages/pigeon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.0

* Adds experimental support for Kotlin generation.

## 4.1.1

* [java] Adds missing `@NonNull` annotations to some methods.
Expand Down
37 changes: 31 additions & 6 deletions packages/pigeon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ host platform type-safe, easier and faster.

## Supported Platforms

Currently Pigeon supports generating Objective-C code for usage on iOS, Java
code for Android, and has experimental support for C++ for Windows. The
Objective-C code is
Currently Pigeon supports generating Objective-C and experimental Swift code
for usage on iOS, Java and experimental Kotlin code for Android,
and has experimental support for C++ for Windows.
The Objective-C code is
[accessible to Swift](https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_objective-c_into_swift)
and the Java code is accessible to Kotlin.

Expand All @@ -31,18 +32,24 @@ doesn't need to worry about conflicting versions of Pigeon.

### Flutter calling into iOS steps

1) Add the generated Objective-C code to your Xcode project for compilation
1) Add the generated Objective-C or Swift code to your Xcode project for compilation
(e.g. `ios/Runner.xcworkspace` or `.podspec`).
1) Implement the generated iOS protocol for handling the calls on iOS, set it up
as the handler for the messages.

**Note:** Swift code generation for iOS is experimental while we get more usage and add more
testing. Not all features may be supported.

### Flutter calling into Android Steps

1) Add the generated Java code to your `./android/app/src/main/java` directory
1) Add the generated Java or Kotlin code to your `./android/app/src/main/java` directory
for compilation.
1) Implement the generated Java interface for handling the calls on Android, set
1) Implement the generated Java or Kotlin interface for handling the calls on Android, set
it up as the handler for the messages.

**Note:** Kotlin code generation for Android is experimental while we get more usage and add more
testing and works just with Flutter 3.3.0 or later. Not all features may be supported.

### Flutter calling into Windows Steps

1) Add the generated C++ code to your `./windows` directory for compilation, and
Expand Down Expand Up @@ -112,6 +119,15 @@ Generates:
@end
```
```swift
// Swift
/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
protocol Api2Host {
func calculate(value: Value, completion: @escaping (Value) -> Void)
}
```

```java
// Java
public interface Result<T> {
Expand All @@ -124,6 +140,15 @@ public interface Api2Host {
}
```

```kotlin
// Kotlin

/** Generated interface from Pigeon that represents a handler of messages from Flutter.*/
interface Api2Host {
fun calculate(value: Value, callback: (Value) -> Unit)
}
```

```c++
// C++

Expand Down
2 changes: 1 addition & 1 deletion packages/pigeon/lib/generator_tools.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'dart:mirrors';
import 'ast.dart';

/// The current version of pigeon. This must match the version in pubspec.yaml.
const String pigeonVersion = '4.1.1';
const String pigeonVersion = '4.2.0';

/// Read all the content from [stdin] to a String.
String readStdin() {
Expand Down
Loading

0 comments on commit d2fd81d

Please sign in to comment.