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
3
4k
Flutterでstaging/production環境を切替える
Flutter Meetup Tokyo #1 のLT資料です
FURUKI Eiji
April 18, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
命名をリントする
chiroruxx
1
570
QA環境で誰でも自由自在に現在時刻を操って検証できるようにした話
kalibora
1
120
なまけものオバケたち -PHP 8.4 に入った新機能の紹介-
tanakahisateru
1
140
テストコード書いてみませんか?
onopon
2
290
range over funcの使い道と非同期N+1リゾルバーの夢 / about a range over func
mackee
0
200
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
290
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
220
MCP with Cloudflare Workers
yusukebe
2
270
Androidアプリの One Experience リリース
nein37
0
730
CloudflareStack でRAGに入門
asahiiwm
0
140
今年のアップデートで振り返るCDKセキュリティのシフトレフト/2024-cdk-security-shift-left
tomoki10
0
330
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.3k
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
298
20k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Agile that works and the tools we love
rasmusluckow
328
21k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Code Reviewing Like a Champion
maltzj
521
39k
Building an army of robots
kneath
302
44k
Building Adaptive Systems
keathley
38
2.3k
Documentation Writing (for coders)
carmenintech
67
4.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
850
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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ͰڥΛΓସ͑ͯϏϧυ͢Δ