Skip to content

Commit 1a59438

Browse files
Add rebuild script for deeplink_cookbook (#2290)
If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. [Effective Dart: Style]: https://dart.dev/guides/language/effective-dart/style
1 parent 6cd4e4f commit 1a59438

File tree

12 files changed

+254
-31
lines changed

12 files changed

+254
-31
lines changed

deeplink_cookbook/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

deeplink_cookbook/android/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ gradle-wrapper.jar
55
/gradlew.bat
66
/local.properties
77
GeneratedPluginRegistrant.java
8+
.cxx/
89

910
# Remember to never publicly share your keystore.
1011
# See https://flutter.dev/to/reference-keystore

deeplink_cookbook/android/app/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ android {
1111
ndkVersion = flutter.ndkVersion
1212

1313
compileOptions {
14-
sourceCompatibility = JavaVersion.VERSION_1_8
15-
targetCompatibility = JavaVersion.VERSION_1_8
14+
sourceCompatibility = JavaVersion.VERSION_11
15+
targetCompatibility = JavaVersion.VERSION_11
1616
}
1717

1818
kotlinOptions {
19-
jvmTarget = JavaVersion.VERSION_1_8.toString()
19+
jvmTarget = JavaVersion.VERSION_11.toString()
2020
}
2121

2222
defaultConfig {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: deeplink_cookbook rebuild script
2+
steps:
3+
- name: Remove runners
4+
rmdirs:
5+
- android
6+
- ios
7+
- linux
8+
- macos
9+
- web
10+
- windows
11+
- name: Flutter recreate
12+
flutter: create .
13+
- name: Remove README.md
14+
rm: README.md
15+
- name: Patch android/app/src/main/AndroidManifest.xml
16+
path: android/app/src/main/AndroidManifest.xml
17+
patch-u: |
18+
--- b/deeplink_cookbook/android/app/src/main/AndroidManifest.xml
19+
+++ a/deeplink_cookbook/android/app/src/main/AndroidManifest.xml
20+
@@ -24,6 +24,14 @@
21+
<action android:name="android.intent.action.MAIN"/>
22+
<category android:name="android.intent.category.LAUNCHER"/>
23+
</intent-filter>
24+
+ <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
25+
+ <intent-filter android:autoVerify="true">
26+
+ <action android:name="android.intent.action.VIEW" />
27+
+ <category android:name="android.intent.category.DEFAULT" />
28+
+ <category android:name="android.intent.category.BROWSABLE" />
29+
+ <data android:scheme="http" android:host="example.com" />
30+
+ <data android:scheme="https" />
31+
+ </intent-filter>
32+
</activity>
33+
<!-- Don't delete the meta-data below.
34+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
35+
- name: Patch ios/Runner/info.plist
36+
path: ios/Runner/Info.plist
37+
patch-u: |
38+
--- b/deeplink_cookbook/ios/Runner/Info.plist
39+
+++ a/deeplink_cookbook/ios/Runner/Info.plist
40+
@@ -16,6 +16,8 @@
41+
<string>deeplink_cookbook</string>
42+
<key>CFBundlePackageType</key>
43+
<string>APPL</string>
44+
+ <key>FlutterDeepLinkingEnabled</key>
45+
+ <true/>
46+
<key>CFBundleShortVersionString</key>
47+
<string>$(FLUTTER_BUILD_NAME)</string>
48+
<key>CFBundleSignature</key>
49+
- name: Add Runner.entitlements
50+
path: ios/Runner/Runner.entitlements
51+
replace-contents: |
52+
<?xml version="1.0" encoding="UTF-8"?>
53+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
54+
<plist version="1.0">
55+
<dict>
56+
<key>com.apple.developer.associated-domains</key>
57+
<array>
58+
<string>applinks:example.com</string>
59+
</array>
60+
</dict>
61+
</plist>
62+
63+
- name: Build ios
64+
flutter: build ios --simulator

deeplink_cookbook/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@
362362
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
363363
CLANG_ENABLE_MODULES = YES;
364364
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
365-
DEVELOPMENT_TEAM = TC87DMJLQP;
366365
ENABLE_BITCODE = NO;
367366
INFOPLIST_FILE = Runner/Info.plist;
368367
LD_RUNPATH_SEARCH_PATHS = (
@@ -542,7 +541,6 @@
542541
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
543542
CLANG_ENABLE_MODULES = YES;
544543
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
545-
DEVELOPMENT_TEAM = TC87DMJLQP;
546544
ENABLE_BITCODE = NO;
547545
INFOPLIST_FILE = Runner/Info.plist;
548546
LD_RUNPATH_SEARCH_PATHS = (
@@ -565,7 +563,6 @@
565563
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
566564
CLANG_ENABLE_MODULES = YES;
567565
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
568-
DEVELOPMENT_TEAM = TC87DMJLQP;
569566
ENABLE_BITCODE = NO;
570567
INFOPLIST_FILE = Runner/Info.plist;
571568
LD_RUNPATH_SEARCH_PATHS = (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(runner LANGUAGES CXX)
3+
4+
# Define the application target. To change its name, change BINARY_NAME in the
5+
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6+
# work.
7+
#
8+
# Any new source files that you add to the application should be added here.
9+
add_executable(${BINARY_NAME}
10+
"main.cc"
11+
"my_application.cc"
12+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
13+
)
14+
15+
# Apply the standard set of build settings. This can be removed for applications
16+
# that need different build settings.
17+
apply_standard_settings(${BINARY_NAME})
18+
19+
# Add preprocessor definitions for the application ID.
20+
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
21+
22+
# Add dependency libraries. Add any application-specific dependencies here.
23+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
24+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
25+
26+
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "my_application.h"
2+
3+
int main(int argc, char** argv) {
4+
g_autoptr(MyApplication) app = my_application_new();
5+
return g_application_run(G_APPLICATION(app), argc, argv);
6+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include "my_application.h"
2+
3+
#include <flutter_linux/flutter_linux.h>
4+
#ifdef GDK_WINDOWING_X11
5+
#include <gdk/gdkx.h>
6+
#endif
7+
8+
#include "flutter/generated_plugin_registrant.h"
9+
10+
struct _MyApplication {
11+
GtkApplication parent_instance;
12+
char** dart_entrypoint_arguments;
13+
};
14+
15+
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16+
17+
// Implements GApplication::activate.
18+
static void my_application_activate(GApplication* application) {
19+
MyApplication* self = MY_APPLICATION(application);
20+
GtkWindow* window =
21+
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22+
23+
// Use a header bar when running in GNOME as this is the common style used
24+
// by applications and is the setup most users will be using (e.g. Ubuntu
25+
// desktop).
26+
// If running on X and not using GNOME then just use a traditional title bar
27+
// in case the window manager does more exotic layout, e.g. tiling.
28+
// If running on Wayland assume the header bar will work (may need changing
29+
// if future cases occur).
30+
gboolean use_header_bar = TRUE;
31+
#ifdef GDK_WINDOWING_X11
32+
GdkScreen* screen = gtk_window_get_screen(window);
33+
if (GDK_IS_X11_SCREEN(screen)) {
34+
const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35+
if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36+
use_header_bar = FALSE;
37+
}
38+
}
39+
#endif
40+
if (use_header_bar) {
41+
GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42+
gtk_widget_show(GTK_WIDGET(header_bar));
43+
gtk_header_bar_set_title(header_bar, "deeplink_cookbook");
44+
gtk_header_bar_set_show_close_button(header_bar, TRUE);
45+
gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46+
} else {
47+
gtk_window_set_title(window, "deeplink_cookbook");
48+
}
49+
50+
gtk_window_set_default_size(window, 1280, 720);
51+
gtk_widget_show(GTK_WIDGET(window));
52+
53+
g_autoptr(FlDartProject) project = fl_dart_project_new();
54+
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
55+
56+
FlView* view = fl_view_new(project);
57+
gtk_widget_show(GTK_WIDGET(view));
58+
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
59+
60+
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
61+
62+
gtk_widget_grab_focus(GTK_WIDGET(view));
63+
}
64+
65+
// Implements GApplication::local_command_line.
66+
static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
67+
MyApplication* self = MY_APPLICATION(application);
68+
// Strip out the first argument as it is the binary name.
69+
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
70+
71+
g_autoptr(GError) error = nullptr;
72+
if (!g_application_register(application, nullptr, &error)) {
73+
g_warning("Failed to register: %s", error->message);
74+
*exit_status = 1;
75+
return TRUE;
76+
}
77+
78+
g_application_activate(application);
79+
*exit_status = 0;
80+
81+
return TRUE;
82+
}
83+
84+
// Implements GApplication::startup.
85+
static void my_application_startup(GApplication* application) {
86+
//MyApplication* self = MY_APPLICATION(object);
87+
88+
// Perform any actions required at application startup.
89+
90+
G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
91+
}
92+
93+
// Implements GApplication::shutdown.
94+
static void my_application_shutdown(GApplication* application) {
95+
//MyApplication* self = MY_APPLICATION(object);
96+
97+
// Perform any actions required at application shutdown.
98+
99+
G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
100+
}
101+
102+
// Implements GObject::dispose.
103+
static void my_application_dispose(GObject* object) {
104+
MyApplication* self = MY_APPLICATION(object);
105+
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
106+
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
107+
}
108+
109+
static void my_application_class_init(MyApplicationClass* klass) {
110+
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
111+
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
112+
G_APPLICATION_CLASS(klass)->startup = my_application_startup;
113+
G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
114+
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
115+
}
116+
117+
static void my_application_init(MyApplication* self) {}
118+
119+
MyApplication* my_application_new() {
120+
// Set the program name to the application ID, which helps various systems
121+
// like GTK and desktop environments map this running application to its
122+
// corresponding .desktop file. This ensures better integration by allowing
123+
// the application to be recognized beyond its binary name.
124+
g_set_prgname(APPLICATION_ID);
125+
126+
return MY_APPLICATION(g_object_new(my_application_get_type(),
127+
"application-id", APPLICATION_ID,
128+
"flags", G_APPLICATION_NON_UNIQUE,
129+
nullptr));
130+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef FLUTTER_MY_APPLICATION_H_
2+
#define FLUTTER_MY_APPLICATION_H_
3+
4+
#include <gtk/gtk.h>
5+
6+
G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7+
GtkApplication)
8+
9+
/**
10+
* my_application_new:
11+
*
12+
* Creates a new Flutter-based application.
13+
*
14+
* Returns: a new #MyApplication.
15+
*/
16+
MyApplication* my_application_new();
17+
18+
#endif // FLUTTER_MY_APPLICATION_H_

deeplink_cookbook/macos/Runner/Configs/AppInfo.xcconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ PRODUCT_NAME = deeplink_cookbook
1111
PRODUCT_BUNDLE_IDENTIFIER = com.example.deeplinkCookbook
1212

1313
// The copyright displayed in application information
14-
PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved.
14+
PRODUCT_COPYRIGHT = Copyright © 2025 com.example. All rights reserved.

0 commit comments

Comments
 (0)