Skip to content

Commit 75e5919

Browse files
[pigeon] Reland: Add an initial example app (flutter#3832)
Relands flutter/packages#3761, with the native runners re-created from `stable`. The important change was the principle class in the macOS Info.plist being NSApplication instead of `FlutterApplication`, since the latter doesn't exist on stable. (The pigeon versions also changed because when I re-created the app I re-ran pigeon, and had a slightly newer version.)
1 parent 66703bc commit 75e5919

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.5
26

37
* Reports an error when trying to use an enum directly in a `List` or `Map`
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: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
8+
channel: stable
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
17+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
18+
- platform: android
19+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
20+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
21+
- platform: ios
22+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
23+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
24+
- platform: linux
25+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
26+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
27+
- platform: macos
28+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
29+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
30+
- platform: web
31+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
32+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
33+
- platform: windows
34+
create_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
35+
base_revision: 4d9e56e694b656610ab87fcf2efbcd226e0ed8cf
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+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
// Autogenerated from Pigeon (v9.2.5), do not edit directly.
5+
// See also: https://pub.dev/packages/pigeon
6+
7+
8+
import android.util.Log
9+
import io.flutter.plugin.common.BasicMessageChannel
10+
import io.flutter.plugin.common.BinaryMessenger
11+
import io.flutter.plugin.common.MessageCodec
12+
import io.flutter.plugin.common.StandardMessageCodec
13+
import java.io.ByteArrayOutputStream
14+
import java.nio.ByteBuffer
15+
16+
private fun wrapResult(result: Any?): List<Any?> {
17+
return listOf(result)
18+
}
19+
20+
private fun wrapError(exception: Throwable): List<Any?> {
21+
if (exception is FlutterError) {
22+
return listOf(
23+
exception.code,
24+
exception.message,
25+
exception.details
26+
)
27+
} else {
28+
return listOf(
29+
exception.javaClass.simpleName,
30+
exception.toString(),
31+
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
32+
)
33+
}
34+
}
35+
36+
/**
37+
* Error class for passing custom error details to Flutter via a thrown PlatformException.
38+
* @property code The error code.
39+
* @property message The error message.
40+
* @property details The error details. Must be a datatype supported by the api codec.
41+
*/
42+
class FlutterError (
43+
val code: String,
44+
override val message: String? = null,
45+
val details: Any? = null
46+
) : Throwable()
47+
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
48+
interface ExampleHostApi {
49+
fun getHostLanguage(): String
50+
51+
companion object {
52+
/** The codec used by ExampleHostApi. */
53+
val codec: MessageCodec<Any?> by lazy {
54+
StandardMessageCodec()
55+
}
56+
/** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */
57+
@Suppress("UNCHECKED_CAST")
58+
fun setUp(binaryMessenger: BinaryMessenger, api: ExampleHostApi?) {
59+
run {
60+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.ExampleHostApi.getHostLanguage", codec)
61+
if (api != null) {
62+
channel.setMessageHandler { _, reply ->
63+
var wrapped: List<Any?>
64+
try {
65+
wrapped = listOf<Any?>(api.getHostLanguage())
66+
} catch (exception: Throwable) {
67+
wrapped = wrapError(exception)
68+
}
69+
reply.reply(wrapped)
70+
}
71+
} else {
72+
channel.setMessageHandler(null)
73+
}
74+
}
75+
}
76+
}
77+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="?android:colorBackground" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Modify this file to customize your launch splash screen -->
3+
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
4+
<item android:drawable="@android:color/white" />
5+
6+
<!-- You can insert your own image assets here -->
7+
<!-- <item>
8+
<bitmap
9+
android:gravity="center"
10+
android:src="@mipmap/launch_image" />
11+
</item> -->
12+
</layer-list>
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)