Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
What's Add2App project?(Flutter)
Search
kosuke matsumura
March 26, 2019
Technology
2
1.3k
What's Add2App project?(Flutter)
About Flutter Add2App project.
How to use Flutter from existing Android/iOS project.
kosuke matsumura
March 26, 2019
Tweet
Share
More Decks by kosuke matsumura
See All by kosuke matsumura
Add Material touch ripples / FlutterKaigi 2023
kosukematsumura
0
430
TabBarの色を変えたかっただけなのに
kosukematsumura
3
1.5k
Flutter Plugin Score
kosukematsumura
4
1.5k
Navigationのバックキーハンドリング.pdf
kosukematsumura
1
860
Navigation
kosukematsumura
0
240
Other Decks in Technology
See All in Technology
ウェブアクセシビリティとは
lycorptech_jp
PRO
0
330
バクラクでのSystem Risk Records導入による変化と改善の取り組み/Changes and Improvement Initiatives Resulting from the Implementation of System Risk Records
taddy_919
0
230
コンソールで学ぶ!AWS CodePipelineの機能とオプション
umekou
2
120
Vision Language Modelを活用した メルカリの類似画像レコメンドの性能改善
yadayuki
9
1.3k
Cline、めっちゃ便利、お金が飛ぶ💸
iwamot
20
19k
[CATS]Amazon Bedrock GenUハンズオン座学資料 #2 GenU環境でRAGを体験してみよう
tsukuboshi
0
150
アプリケーション固有の「ロジックの脆弱性」を防ぐ開発者のためのセキュリティ観点
flatt_security
34
13k
DevinはクラウドエンジニアAIになれるのか!? 実践的なガードレール設計/devin-can-become-a-cloud-engineer-ai-practical-guardrail-design
tomoki10
3
1.4k
ペアーズにおけるData Catalog導入の取り組み
hisamouna
0
220
職種に名前が付く、ということ/The fact that a job title has a name
bitkey
1
250
Compose MultiplatformにおけるiOSネイティブ実装のベストプラクティス
enomotok
1
220
17年のQA経験が導いたスクラムマスターへの道 / 17 Years in QA to Scrum Master
toma_sm
0
450
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
KATA
mclloyd
29
14k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
8
700
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
30
1.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Navigating Team Friction
lara
184
15k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
Unsuck your backbone
ammeep
670
57k
Building an army of robots
kneath
304
45k
Bash Introduction
62gerente
611
210k
Scaling GitHub
holman
459
140k
Transcript
What’s Add2App project Flutter Meetup Tokyo #8 2019/3/26 Kosuke Matsumura
About Me • দଜߤ༟(Kosuke Matsumura) • NAVITIME JAPAN Co., Ltd.
Android/iOS Developer • Kawasaki Frontale Supporter • Twitter m.kosuke @kosuke_mtm
Add2App project
Add2App project • Make it easy to add Flutter on
existing application • In preview(as of 2019.3.17) • Available in master channel
OUTLINE
OUTLINE Standard Flutter Project Add2App Project Existing Android/iOS project should
import Flutter project as a module. Flutter project includes Android/iOS project from the beginning. Import with CocoaPods Import with cradle
OUTLINE $ flutter --version Flutter 1.3.11-pre.34 • channel master Framework
• 2019-03-15 22:03:13 -0700 Tools • Dart 2.2.1 (build 2.2.1-dev.1.0 None) Execution environment Warning: https://github.com/flutter/flutter/wiki/Bad-Builds
OUTLINE $ flutter --version Flutter 1.3.11-pre.34 • channel master Framework
• 2019-03-15 22:03:13 -0700 Tools • Dart 2.2.1 (build 2.2.1-dev.1.0 None) Execution environment Warning: https://github.com/flutter/flutter/wiki/Bad-Builds
SETUP
SETUP Create “Flutter module” $ flutter channel master $ flutter
create -t module my_flutter `-t` option is `template`. This command create the Flutter module project template. Existing Android/iOS project will import this module. set branch to `master`
SETUP Create “Flutter module” $ flutter create -t module my_flutter
In the Flutter module project, there are hidden subfolder: `.android/` and `.ios/`
SETUP -Android-
SETUP -Android- Add compile option: using java1.8 build.gradle android {
compileOptions { sourceCompatibility 1.8 targetCompatibility 1.8 } …
SETUP -Android- Add path to the Flutter module project setting.gradle
include ':app' // add below setBinding(new Binding([gradle: this])) evaluate(new File( settingsDir.parentFile, 'my_flutter/.android/include_flutter.groovy' ))
SETUP -Android- Introduce an implementation dependency on the Flutter module
from app app/build.gradle dependencies { implementation project(‘:flutter') … }
SETUP -Android- [optional] Apply AndroidX to the Flutter module project
ɾExecute on Android Project(not Flutter module project) ɾYou should correct import manually
SETUP -iOS-
SETUP -iOS- Setup Podfile ※If you don’t have Podfile, execute
`pod init` Podfile flutter_application_path = ‘../my_flutter/‘ eval(File.read( File.join(flutter_application_path, ‘.ios’, ‘Flutter’, ‘podhelper.rb’)), binding) And execute `pod install`
SETUP -iOS- Disable bitcode As Flutter does not support bitcode
now.
SETUP -iOS- Add a build phase for building Dart code
SETUP -iOS- Add a build phase for building Dart code
Run Script “$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh” build “$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" embed
SETUP -iOS- Add a build phase for building Dart code
Drag after `Target Dependencies`
USING in Native Code
USING -Android-
USING -Android- As a View MainActivity.kt val flutterView = Flutter.createView(
this, // Activity lifecycle, // Lifecycle "route1" ) Talk about this later
USING -Android- As a Fragment MainActivity.kt val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.container, Flutter.createFragment(“route2”)) transaction.commit() What is “route”?
What is “route”? Dart code is able to receive String
main.dar void main() => runApp(_widgetForRoute(window.defaultRouteName)); Widget _widgetForRoute(String route) { switch (route) { case 'route1': return SomeWidget(…); case 'route2': return SomeWidget(…); default: return Center(child: Text('Unknown route: $route')); } }
USING -iOS-
USING -iOS- AppDelegate.swift import Flutter Replace super class with `FlutterAppDelegate`
} FlutterAppDelegate.swift @interface FlutterAppDelegate: UIResponder <UIApplicationDelegate, …> @UIApplicationMain class AppDelegate: FlutterAppDelegate {
USING -iOS- AppDelegate.swift import Flutter Case of using Flutter plugin
} @UIApplicationMain class AppDelegate: FlutterAppDelegate {
USING -iOS- AppDelegate.swift import Flutter Case of using Flutter plugin
@UIApplicationMain class AppDelegate: FlutterAppDelegate { import FlutterPluginRegistrant var flutterEngine: FlutterEngine? override func application(_ application: UIApplication,didFinishLaunching… { self.flutterEngine = FlutterEngine(name: "io.flutter", project: nil) self.flutterEngine?.run(withEntrypoint: nil) GeneratedPluginRegistrant.register(with: self.flutterEngine) return super.application(application, didFinishLaunchingWithOptions:… }
USING -iOS- ViewController.swift let flutterViewController = FlutterViewController() flutterViewController.setInitialRoute(“route3") present(flutterViewController, animated:
false, completion: nil) Call Flutter from ViewController
Back to NativeCode
Back to NativeCode main.dart SystemNavigator.pop(); Call Flutter from ViewController
Hot Reload
Hot Reload $ cd xxxxx/my_flutter $ flutter attach IDE Support
Hot Reload for Add2App is in progress. But Flutter command line tools are already present.
Hot Reload IDE Support Hot Reload for Add2App is in
progress. But Flutter command line tools are already present. Dart Observatory web user interface URL
Hot Reload IDE Support Hot Reload for Add2App is in
progress. But Flutter command line tools are already present. Dart Observatory web user interface URL
Method Channel
Method Channel • Official https://flutter.dev/docs/development/platform-integration/ platform-channels • Qiita https://qiita.com/mkosuke/items/ b384035e507ad0208c10
Thank you for your attention.
References • Add2App project https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps • github https://github.com/flutter/flutter/projects/28 • Google
Developer blog https://developers.googleblog.com/2018/12/flutter-10-googles-portable-ui- toolkit.html • gitHub https://github.com/shcahill/Add2AppSample