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
Flutterでstaging/production環境を切替える
Search
FURUKI Eiji
April 18, 2018
Programming
4
4k
Flutterでstaging/production環境を切替える
Flutter Meetup Tokyo #1 のLT資料です
FURUKI Eiji
April 18, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
役立つログに取り組もう
irof
28
9.6k
イベント駆動で成長して委員会
happymana
1
330
RubyLSPのマルチバイト文字対応
notfounds
0
120
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
970
cmp.Or に感動した
otakakot
3
200
CSC509 Lecture 11
javiergs
PRO
0
180
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
890
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
140
Featured
See All Featured
Scaling GitHub
holman
458
140k
4 Signs Your Business is Dying
shpigford
180
21k
Speed Design
sergeychernyshev
25
620
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
130
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
What's in a price? How to price your products and services
michaelherold
243
12k
A better future with KSS
kneath
238
17k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Transcript
Flavor Of Flutter Flutter Meetup Tokyo #1 FlutterͰstaging/productionڥͷସ
ࣗݾհ • @fullfool / FURUKI Eiji • iOS / Android
ΤϯδχΞ • ϞΠגࣜձࣾ • Flutterྺɹࡢ8݄த०͔Β • ࠷ۙFlutter৮ͬͯͳ͍
agenda
agenda • Flavorͱ • DartͰFlavorΛऔಘ͢Δ • AndroidStudio, XcodeͰFlavorΛࢦఆ͢Δ • PlatformຖͷFlavorͷఆٛ
• Firebase, FastlaneͱFlavor
agenda • Flavorͱ • DartͰFlavorΛऔಘ͢Δ • AndroidStudio, XcodeͰFlavorΛࢦఆ͢Δ • PlatformຖͷFlavorͷఆٛ
• Firebase, FastlaneͱFlavor
Flavorͱʁ
Flavorͱʁ • ҰͭͷϓϩδΣΫτͰdemo൛ʗfull൛ɺࣾ ςετ༻ʗετΞ༻ͳͲͷෳͷڥΛఆٛ ͢ΔΈ • AndroidͰ ProductFlavor • iOSͰ
Scheme
FlavorΛࢦఆͯ͠ΞϓϦΛ࣮ߦ $ flutter run --flavor staging $ flutter run --flavor
production `--flavor` ΦϓγϣϯͰFlavorΛࢦఆ͢Δ flavorʹࢦఆ͢ΔPlatformଆ(Android/iOS)ͰઃఆࡁΈͷ͕ࢦఆͰ ͖·͢ ͦΕͧΕͷPlatformͰͷFlavorͷఆٛεϥΠυඌʹ
DartͰFlavorΛऔಘ͢Δํ๏
DartͰFlavorΛऔಘ void main() { const String flavor = const String.fromEnvironment('flavor');
configure(flavor); runApp(new MyApp()); } const bool isReleaseMode = const bool.fromEnvironment('dart.vm.product'); ىಈ࣌ʹFlavorΛऔಘ͍ͨ͠ releaseϞʔυΛऔಘ͢Δ࣌
DartͰFlavorΛऔಘ void main() { const String flavor = const String.fromEnvironment('flavor');
configure(flavor); runApp(new MyApp()); } const bool isReleaseMode = const bool.fromEnvironment('dart.vm.product'); ىಈ࣌ʹFlavorΛऔಘ͍ͨ͠ releaseϞʔυΛऔಘ͢Δ࣌
DartͰFlavorຖͷॲཧΛߦ͏ ̎ͭͷํ๏ • Flavor औಘ༻ͷ MethodChannel Λ࡞Δ • Flavor ຖʹ
Dart Entry-Point Λมߋ͢Δ
MethodChannelͱ • Platform(Obj-C/Java)Ͱఆٛͨؔ͠Λඇಉظ ݺͼग़͢͠ΔͨΊͷΫϥε • ىಈ࣌ʹPlatformଆͰMethodChannelΛొ • DartଆͰMethodChannelΛ༻͢Δ͜ͱͰɺ PlatformͰͷॲཧ݁ՌΛऔಘͰ͖Δ
MethodChannelͷొ(Android) new MethodChannel(getFlutterView(), "flavor") .setMethodCallHandler(new MethodChannel.MethodCallHandler() { @Override public void
onMethodCall(MethodCall methodCall, MethodChannel.Result result) { result.success(BuildConfig.FLAVOR); } }); ΞϓϦىಈ࣌ʹMethodChannelΛొ͢Δ ʢ͜ͷchannelFlavorऔಘઐ༻ͷͨΊMethodCallࢀর͠ͳ͍ʣ
MethodChannelͷొ(Android) new MethodChannel(getFlutterView(), "flavor") .setMethodCallHandler(new MethodChannel.MethodCallHandler() { @Override public void
onMethodCall(MethodCall methodCall, MethodChannel.Result result) { result.success(BuildConfig.FLAVOR); } }); ProductFlavor(BuildConfig.FLAVOR)Λฦ͢
MethodChannelͷొ(iOS) FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController; FlutterMethodChannel* flavorChannel = [FlutterMethodChannel methodChannelWithName:@"flavor"
binaryMessenger:controller]; [flavorChannel setMethodCallHandler:^(FlutterMethodCall *call, FlutterResult result) { NSString* flavor = (NSString*)[[NSBundle mainBundle] .infoDictionary valueForKey:@"Flavor"]; result(flavor); }]; Bundleʹఆٛ͢ΔSchemeʹؔ࿈͚ͨFlavorΛฦ͢
MethodChannelͰFlavorऔಘ void main() { _run(); } Future _run() async {
var flavor = await MethodChannel('flavor').invokeMethod('getFlavor'); configure(flavor); runApp(new MyApp()); } main.dartͰFlavorΛऔಘͯ͠ɺઃఆΛॳظԽ
Dart Entry-Pointͱ • ҙͷdartϑΝΠϧΛࢦఆ͢Δ • ࢦఆͨ͠dartϑΝΠϧͷmain()͔ؔΒ࢝·Δ $ flutter run --flavor
staging -t lib/main_staging.dart
FlavorຖͷEntry-Point • main.dart "production"ͰઃఆॳظԽ void main() { configure("staging"); runApp(new MyApp());
} void main() { configure("production"); runApp(new MyApp()); } • main_staging.dart "staging"ͰઃఆॳظԽ
FlavorΛѻ͏߹ MethodCallͱEntry-Point Ͳͬͪ͑ʁ
MethodCallͱEntry-Point • MethodChannel • Obj-C, Java(Swift, Kotlin)༻ҙ͢Δ • Pluginͱಉ͡ͳͷͰɺ׳Ε͓ͯ͘ͱPlugin࡞Γ͍͢ •
Entry-Point • Dart͚ͩͰ݁͢ΔͷͰ͓खܰ • XcodeͰͷڥସϛε͋Γͦ͏
࣮ߦ࣌ͷFlavorࢦఆ
࣮ߦ࣌ͷFlavorࢦఆ(CLI) • CLIͰ࣮ߦ͢Δ߹ɺ͜ͷίϚϯυ • AndroidStudio, XcodeͰ࣮ߦ͢Δ࣌ʹFlavor(Entry-Point)Λࢦఆ͢ Δʹʁ $ flutter run
--flavor staging -t lib/main_staging.dart
࣮ߦ࣌ͷFlavorࢦఆ (AndroidStudio Flutter Plugin) Menu > Run > Edit Configurations...
ʹͯ "Build flavor"ͱ "Dart entrypoint" Λࢦఆ͢Δ
࣮ߦ࣌ͷFlavorࢦఆ(Xcode) • Xcode͔ΒFlutterΞϓϦΛ࣮ߦ͢Δ߹ʹ `build` ίϚϯυͰม ߋͰ͖Δ • ίϚϯυ࣮ߦޙɺXcodeͰSchemeΛมߋ͢Δ $ flutter
build ios --flavor staging -t lib/main_staging.dart
·ͱΊ
·ͱΊ • DartͰFlavorΛѻ͏ʹɺ̎ͭͷํ๏͕͋Δ • XcodeͰ࣮ߦ͢Δ࣌ɺFastlaneCIͰ `flutter build` ͰڥΛସ͑Δ͜ͱʹཹҙ͢ ΔɻͦΕҎ֎ࠓ·ͰͦΕͧΕͷPlatformͰ ͍ͬͯͨํ๏Ͱɻ
PlatformͰͷFlavorఆٛ
PlatformͰͷFlavorఆٛ(Android) android { ... defaultConfig {...} buildTypes {...} flavorDimensions "api"
productFlavors { staging { dimension "api" applicationIdSuffix ".staging" manifestPlaceholders = [appName: "Casmo dev"] } production { dimension "api" manifestPlaceholders = [appName: "Casmo"] } } } ௨ৗͷAndroidΞϓϦͷProductFlavorsͱಉ༷
PlatformͰͷFlavorఆٛ(iOS) • SchemeΛઃఆ • ConfigurationΛઃఆ • Build SettingsͷPRODUCT_BUNDLE_IDENTIFIERΛมߋ • Build
SettingsͷUser-Defined ValueΛՃ • info.plistʹFlavorͷkey-valueΛՃ
PlatformͰͷFlavorఆٛ(iOS) • SchemeΛઃఆ
PlatformͰͷFlavorఆٛ(iOS) • ConfigurationΛઃఆ
PlatformͰͷFlavorఆٛ(iOS) • Build SettingsͷPRODUCT_BUNDLE_IDENTIFIERΛมߋ
PlatformͰͷFlavorఆٛ(iOS) • Build SettingsͷUser-Defined ValueΛՃ ($PRODUCT_FLAVOR)
PlatformͰͷFlavorఆٛ(iOS) • info.plistʹFlavorͷkey-value ($Flavor ) ΛՃ
Firebaseͷସ
Firebaseͷସ(Android) src/$flavor ຖʹ google-services.json Λஔ
Firebaseͷସ(iOS) GoogleService-Info-$flavor.plist Λىಈ࣌ʹಡ Έସ͑Δ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSString *flavor = (NSString*)[[NSBundle mainBundle] .infoDictionary valueForKey:@"Flavor"]; NSString *firebaseInfo = [NSString stringWithFormat: @"GoogleService-Info-%@", flavor]; NSString *path = [[NSBundle mainBundle] pathForResource:firebaseInfo ofType:@"plist"]; FIROptions* firOptions = [[FIROptions alloc] initWithContentsOfFile:path]; if (firOptions == nil) { assert("Couldn't load config file"); } [FIRApp configureWithOptions:firOptions];
Fastlane+Beta
Fastlane+Beta(Android) lane :beta do |options| flavor = (options[:prod] ? "production"
: "staging") entry_dart = (options[:prod] ? "lib/main.dart" : "lib/main_staging.dart") sh("cd ../.. && flutter build apk --flavor #{flavor} -t #{entry_dart} --release && cd -") changelog_from_git_commits # upload to Beta crashlytics( ... ) slack( ... ) end flutter buildͰڥΛΓସ͑ͯϏϧυ͢Δ
Fastlane+Beta(iOS) lane :beta do |options| scheme = (options[:prod] ? "Production"
: "Staging") flavor = (options[:prod] ? "production" : "staging") entry_dart = (options[:prod] ? "lib/main.dart" : "lib/main_staging.dart") sh("cd ../.. && flutter build ios --flavor #{flavor} -t #{entry_dart} --release && cd -") gym( scheme: scheme, configuration: "Release #{scheme}", export_method: "ad-hoc" ) changelog_from_git_commits # upload to Beta crashlytics( ... ) slack( ... ) end flutter buildͰڥΛΓସ͑ͯϏϧυ͢Δ