Skip to content

Commit 746750e

Browse files
[pigeon] Add an initial example app (#3761)
This creates an initial example app covering Android (Kotlin), iOS and macOS (Swift), and Windows, showing integration of Pigeon into an app directly, without using a plugin. This serves as both a simple runnable example for clients, and as a future source for snippet extraction for documentation. It includes a simple integration test so that CI will ensure that it's actually working. Since we can't demonstrate Java and Objective-C in the same application, we could consider adding a second example app covering those in the future. Currently it shows only host API, and only a single trivial method, but we can expand over time as is useful for documentation. Part of flutter/flutter#66511
1 parent fa736c2 commit 746750e

File tree

117 files changed

+4360
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+4360
-0
lines changed

.github/dependabot.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,25 @@ updates:
477477
- dependency-name: "*"
478478
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
479479

480+
- package-ecosystem: "gradle"
481+
directory: "/packages/pigeon/example/app/android/app"
482+
commit-message:
483+
prefix: "[pigeon]"
484+
schedule:
485+
interval: "weekly"
486+
open-pull-requests-limit: 10
487+
ignore:
488+
- dependency-name: "com.android.tools.build:gradle"
489+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
490+
- dependency-name: "junit:junit"
491+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
492+
- dependency-name: "org.mockito:*"
493+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
494+
- dependency-name: "androidx.test:*"
495+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
496+
- dependency-name: "org.robolectric:*"
497+
update-types: ["version-update:semver-minor", "version-update:semver-patch"]
498+
480499
- package-ecosystem: "gradle"
481500
directory: "/packages/pigeon/platform_tests/test_plugin/android"
482501
commit-message:

packages/pigeon/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Adds an example application that uses Pigeon directly, rather than in a plugin.
4+
15
## 9.2.4
26

37
* [objc] Fixes a warning due to a C++-style function signature in the codec
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
**/ios/Flutter/.last_build_id
27+
.dart_tool/
28+
.flutter-plugins
29+
.flutter-plugins-dependencies
30+
.packages
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
35+
# Symbolication related
36+
app.*.symbols
37+
38+
# Obfuscation related
39+
app.*.map.json
40+
41+
# Android Studio will place build artifacts here
42+
/android/app/debug
43+
/android/app/profile
44+
/android/app/release

packages/pigeon/example/app/.metadata

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
8+
channel: main
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
17+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
18+
- platform: android
19+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
20+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
21+
- platform: ios
22+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
23+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
24+
- platform: linux
25+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
26+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
27+
- platform: macos
28+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
29+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
30+
- platform: web
31+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
32+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
33+
- platform: windows
34+
create_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
35+
base_revision: a8354ff165eda6174ae423dca3b65c10fa952f4c
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'

packages/pigeon/example/app/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pigeon_example_app
2+
3+
This demonstrates using Pigeon for platform communication directly in an
4+
application, rather than in a plugin.
5+
6+
To update the generated code, run:
7+
```sh
8+
dart run pigeon --input pigeons/messages.dart
9+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
gradle-wrapper.jar
2+
/.gradle
3+
/captures/
4+
/gradlew
5+
/gradlew.bat
6+
/local.properties
7+
GeneratedPluginRegistrant.java
8+
9+
# Remember to never publicly share your keystore.
10+
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
key.properties
12+
**/*.keystore
13+
**/*.jks
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
def localProperties = new Properties()
2+
def localPropertiesFile = rootProject.file('local.properties')
3+
if (localPropertiesFile.exists()) {
4+
localPropertiesFile.withReader('UTF-8') { reader ->
5+
localProperties.load(reader)
6+
}
7+
}
8+
9+
def flutterRoot = localProperties.getProperty('flutter.sdk')
10+
if (flutterRoot == null) {
11+
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12+
}
13+
14+
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15+
if (flutterVersionCode == null) {
16+
flutterVersionCode = '1'
17+
}
18+
19+
def flutterVersionName = localProperties.getProperty('flutter.versionName')
20+
if (flutterVersionName == null) {
21+
flutterVersionName = '1.0'
22+
}
23+
24+
apply plugin: 'com.android.application'
25+
apply plugin: 'kotlin-android'
26+
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27+
28+
android {
29+
namespace "dev.flutter.pigeon_example_app"
30+
compileSdkVersion flutter.compileSdkVersion
31+
ndkVersion flutter.ndkVersion
32+
33+
compileOptions {
34+
sourceCompatibility JavaVersion.VERSION_1_8
35+
targetCompatibility JavaVersion.VERSION_1_8
36+
}
37+
38+
kotlinOptions {
39+
jvmTarget = '1.8'
40+
}
41+
42+
sourceSets {
43+
main.java.srcDirs += 'src/main/kotlin'
44+
}
45+
46+
defaultConfig {
47+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
48+
applicationId "dev.flutter.pigeon_example_app"
49+
// You can update the following values to match your application needs.
50+
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
51+
minSdkVersion flutter.minSdkVersion
52+
targetSdkVersion flutter.targetSdkVersion
53+
versionCode flutterVersionCode.toInteger()
54+
versionName flutterVersionName
55+
}
56+
57+
buildTypes {
58+
release {
59+
// TODO: Add your own signing config for the release build.
60+
// Signing with the debug keys for now, so `flutter run --release` works.
61+
signingConfig signingConfigs.debug
62+
}
63+
}
64+
}
65+
66+
flutter {
67+
source '../..'
68+
}
69+
70+
dependencies {
71+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
72+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<!-- The INTERNET permission is required for development. Specifically,
3+
the Flutter tool needs it to communicate with the running application
4+
to allow setting breakpoints, to provide hot reload, etc.
5+
-->
6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
</manifest>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<application
3+
android:label="pigeon_example_app"
4+
android:name="${applicationName}"
5+
android:icon="@mipmap/ic_launcher">
6+
<activity
7+
android:name=".MainActivity"
8+
android:exported="true"
9+
android:launchMode="singleTop"
10+
android:theme="@style/LaunchTheme"
11+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
12+
android:hardwareAccelerated="true"
13+
android:windowSoftInputMode="adjustResize">
14+
<!-- Specifies an Android theme to apply to this Activity as soon as
15+
the Android process has started. This theme is visible to the user
16+
while the Flutter UI initializes. After that, this theme continues
17+
to determine the Window background behind the Flutter UI. -->
18+
<meta-data
19+
android:name="io.flutter.embedding.android.NormalTheme"
20+
android:resource="@style/NormalTheme"
21+
/>
22+
<intent-filter>
23+
<action android:name="android.intent.action.MAIN"/>
24+
<category android:name="android.intent.category.LAUNCHER"/>
25+
</intent-filter>
26+
</activity>
27+
<!-- Don't delete the meta-data below.
28+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
29+
<meta-data
30+
android:name="flutterEmbedding"
31+
android:value="2" />
32+
</application>
33+
</manifest>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package dev.flutter.pigeon_example_app
6+
7+
import ExampleHostApi
8+
import androidx.annotation.NonNull
9+
import io.flutter.embedding.android.FlutterActivity
10+
import io.flutter.embedding.engine.FlutterEngine
11+
12+
private class PigeonApiImplementation: ExampleHostApi {
13+
override fun getHostLanguage(): String {
14+
return "Kotlin"
15+
}
16+
}
17+
18+
class MainActivity: FlutterActivity() {
19+
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
20+
super.configureFlutterEngine(flutterEngine)
21+
22+
val api = PigeonApiImplementation()
23+
ExampleHostApi.setUp(flutterEngine.dartExecutor.binaryMessenger, api);
24+
}
25+
}

0 commit comments

Comments
 (0)