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
3.9k
Flutterでstaging/production環境を切替える
Flutter Meetup Tokyo #1 のLT資料です
FURUKI Eiji
April 18, 2018
Tweet
Share
Other Decks in Programming
See All in Programming
cXML という電子商取引の トランザクションを支える プロトコルと向きあっている話
phigasui
3
2.3k
CSC509 Lecture 09
javiergs
PRO
0
130
カラム追加で増えるActiveRecordのメモリサイズ イメージできますか?
asayamakk
4
1.9k
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
250
RailsのPull requestsのレビューの時に私が考えていること
yahonda
5
2.6k
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
250
Kaigi on Rails 2024 - Rails APIモードのためのシンプルで効果的なCSRF対策 / kaigionrails-2024-csrf
corocn
5
3.7k
Tauriでネイティブアプリを作りたい
tsucchinoko
0
340
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
53
33k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
160
Hotwire or React? ~アフタートーク・本編に含めなかった話~ / Hotwire or React? after talk
harunatsujita
1
110
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
180
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Embracing the Ebb and Flow
colly
84
4.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
How STYLIGHT went responsive
nonsquared
95
5.2k
Statistics for Hackers
jakevdp
796
220k
Writing Fast Ruby
sferik
627
61k
How to Ace a Technical Interview
jacobian
276
23k
Music & Morning Musume
bryan
46
6.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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ͰڥΛΓସ͑ͯϏϧυ͢Δ