Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Xamarin.Android で始めるクロスプラットフォームモバイルアプリ開発 #d...

amay077
March 09, 2017

Xamarin.Android で始めるクロスプラットフォームモバイルアプリ開発 #droidkaigi #droidkaigi1

DroidKaigi2017 - https://droidkaigi.github.io/2017/ day2 AM10:40-11:30 Room1 の発表資料です。

amay077

March 09, 2017
Tweet

More Decks by amay077

Other Decks in Programming

Transcript

  1. About me • Ԟࢁ ༟ਈ - @amay077ʢ͋Ί͍ʣ • ۀ຿ܥϓϩάϥϚ+α •

    Ѫ஌ݝࡏॅͷϑϧϦϞʔτϫʔΧʔ • ஍ཧ৘ใγεςϜɺҐஔ৘ใϓϩάϥϛϯά • Android, iOS, Xamarin, Java, C#, Salesforce 
  2. Work for  • B2B޲͚PaaSɺ૔ݿ؅ཧɾӡૹۀ޲͚SaaS • AWS, Elasticsearch, Cassandra, Lambda,

    etc • શһ͕ϑϧϦϞʔτϫʔΧʔ ͓࢓ࣄ಺༰΍ϦϞʔτͰͷಇ͖ํͳͲڵຯ͋Δํɺؾܰʹฉ͍͍ͯͩ͘͞
  3. Xamarin.Androidͱ͸ʁ • C#͔ΒAndroid API, Java API͕ݺͼग़ͤΔ ʮബ͍ϥούʔʯ • Activity, Intent,

    ϦιʔεXML౳Λී௨ʹ࢖͑Δ • தؒίʔυ(MSIL)ͱMono VMΛΞϓϦ(apk) ʹ ಉࠝɺJava VMͱฏߦՔಇ 
  4. Xamarin.AndroidͷHello World  [Activity(Label = "AppTitle", MainLauncher = true, Icon

    = "@mipmap/icon")] public class MainActivity : Activity { protected override void OnCreate(Bundle state) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); var btn = FindViewById<Button>(Resource.Id.btn); btn.Click += (s, e) => btn.Text = "Hello World!"; } }
  5. Xamarin.Androidͷ࣮ߦϞσϧ  "OESPJE04 +BWB7. .POP7. 9BNBSJO"OESPJE.POP ΞϓϦ $  "OESPJE04

    +BWB7. "OESPJE4%, ΞϓϦ +BWB  +BWB4%, AndroidωΠςΟϒ Xamarin.Android
  6. Xamarin.iOSͷ࣮ߦϞσϧ  "3. "3.Ϛγϯޠ $PDPB5PVDI 9BNBSJOJ04.POP ΞϓϦέʔγϣϯ $  .POP"05ίϯύΠϥ

    ࣮ػ Xamarin.iOS "3. "3.Ϛγϯޠ $PDPB5PVDI ΞϓϦέʔγϣϯ 4XJGU  --7.ίϯύΠϥ ࣮ػ iOSωΠςΟϒ
  7. Xamarin.Formsͱ͸ʁ • Android, iOS, Win, ͦͷଞͰUIͷ࣮૷Λڞ௨Խ ͢ΔϑϨʔϜϫʔΫ • ωΠςΟϒͷUI͕࢖༻͞ΕΔ •

    .NETͷσεΫτοϓΞϓϦ։ൃख๏ʹ͍ۙ (XAML<βϜϧ>Ͱը໘Λهड़ͳͲ) • ϚΠΫϩιϑτ͸͜Εਪ͠ 
  8. 

  9. ౷߹։ൃ؀ڥ • Visual Studio 2017ʗfor Mac Λ࢖͏ • AndroidΞϓϦ։ൃʹಛԽͨ͠Android Studio

    ΑΓ͸एׯޮ཰͕མͪΔ(ओ؍) • UIσβΠφ • XMLϦιʔεͷΠϯϥΠϯදࣔɺ౳ • JetBrains Riderͱ͍͏৽IDE΋ʂ 
  10. ඇಉظॲཧͷ࿈࠯(Java)  void sendZip(String src, String dest) // 1. σʔλΛμ΢ϯϩʔυͯ͠

    downloadAsync(src, data -> // 2. ZIPѹॖͯ͠ zipAsync(data, zipped -> // 3. ผͳͱ͜Ζʹૹ৴ sendAsync(zipped, dest, () -> activity.runOnUiThread(() -> // ૹ৴׬ྃ(UIεϨου) )))); } ωετͭΒ͍ɾɾɾ
  11. ඇಉظॲཧͷ࿈࠯(C#)  async void SendZip(string src, string dest) { //

    1. σʔλΛμ΢ϯϩʔυͯ͠ var data = await DownloadAsync(src); // 2. ZIPѹॖͯ͠ var zipped = await ZipAsync(data); // 3. ผͳͱ͜Ζʹૹ৴ await SendAsync(zipped, dest); // ૹ৴׬ྃ(UIεϨου) } ϑϥοτʂ
  12. ϥϜμࣜɺLINQ to Objects  var list=new[]{0,1,2,3,4,5,6,7,8,9}// 0ʙ9Λ .Where(x => x

    % 2 == 0) // ۮ਺ͷΈ .OrderByDescending(x => x) // ߱ॱ .Select(x => x * 10); // 10ഒ // ݁Ռ: 80 60 40 20 0 // ↑ͷ݁Ռͱ [40, 20, 10] ͱͷੵू߹Λऔಘ͢Δ var ret = list.Intersect(new[]{40,20,10}); // ݁Ռ: 40 20 ֎෦ϥΠϒϥϦʹཔΒͣͰ͖Δͷ͕ڧ͍ʂ
  13. ͪΐͬͱnull҆શʁ  // hoge ͕ null ͳΒ࣮ߦ͠ͳ͍ hoge?.DoSomething(); // hoge,

    fuga ͕ null ͳΒ “none” Λฦ͢ var text = hoge?.fuga?.ToString() ?? “none"; int count = null; // ίϯύΠϧΤϥʔ int? count = null; // null ୅ೖՄೳ ൥ࡶͳnullνΣοΫΛ؆ུԽͰ͖Δ
  14. vs Kotlin • ηϛίϩϯϨεͳͲͷ؆ܿͳߏจ • ڧྗͳnull҆શ • ܕਪ࿦ɺϥϜμࣜ • ύλʔϯϚον

    • ίϧʔνϯ(async/await)  C#͸.NETϑϨʔϜϫʔΫͱڞʹਐԽͰ͖ΔڧΈ ݴޠͷϞμϯͩ͞ͱKotlinͷউͪ
  15. .NET੡ϥΠϒϥϦΛ࢖͓͏ • ετϨʔδ - PCLStorage, Stream • σʔλϕʔε - SQLite-net,

    Realm Xamarin • ௨৴ - HttpClient • JSON - Json.NET • mBaaS - Azure, AWS, Firebase 
  16. RxͱReactive Programing • Rx = Reactive Extensions • LINQͷඇಉظόʔδϣϯ •

    RxJava, RxSwiftͳͲ΁Ҡ২͞Εͨ • RxJavaͷਐԽ͸RxΑΓૣ͍ • ํݴ͸͋ΕͲɺجຊ͸ಉ͡ • Reactive Programing͸ࠓ΍ඞਢεΩϧ 
  17. Android-JavaͰͷ࣮૷ύλʔϯ  .BJO"DUJWJUZ .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ 5FYU7JFX

    දࣔܗࣜ 4XJUDI TUBSU 3Y+BWB MPDBUJPO 0CTFSWBCMF MPDBUJPO ։࢝ #VUUPO PO$IFDLFE PO$MJDL "OESPJEσʔλόΠϯσΟϯά -PDBUJPO"QJ -PDBUJPO.BOBHFS 'VTFE-PDBUJPO"QJ
  18. iOS-SwiftͰͷ࣮૷ύλʔϯ  .BJO7JFX$POUSPMMFS .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ 6*5FYU'JFME

    දࣔܗࣜ 6*4XJUDI TUBSU 3Y4XJGU MPDBUJPO 0CTFSWBCMF MPDBUJPO ։࢝ 6*#VUUPO PO4XJUDI TUBSU 4XJGU#POE -PDBUJPO"QJ $--PDBUJPO.BOBHFS
  19. Xamarin.FormsͰͷ࣮૷ύλʔϯ  .BJO1BHF .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ -BCFM

    දࣔܗࣜ 4XJUDI 4UBSU 3FBDUJWF&YUFOTJPOT -PDBUJPO 0CTFSWBCMF -PDBUJPO ։࢝ #VUUPO *T%NT'PSNBU 4UBSU 9BNBSJO'PSNTσʔλόΠϯσΟϯά -PDBUJPO"QJ -PDBUJPO.BOBHFS <Inject> -PDBUJPO"QJ $--PDBUJPO.BOBHFS
  20.  .BJO1BHF .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ -BCFM දࣔܗࣜ

    4XJUDI 4UBSU 3FBDUJWF&YUFOTJPOT -PDBUJPO 0CTFSWBCMF -PDBUJPO ։࢝ #VUUPO *T%NT'PSNBU 4UBSU 9BNBSJO'PSNTσʔλόΠϯσΟϯά -PDBUJPO"QJ -PDBUJPO.BOBHFS <Inject> -PDBUJPO"QJ $--PDBUJPO.BOBHFS AndroidσʔλόΠϯσΟϯά SwiftBond ↓ Xamarin.Forms σʔλόΠϯσΟϯά Xamarin.FormsͰͷ࣮૷ύλʔϯ
  21.  .BJO1BHF .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ -BCFM දࣔܗࣜ

    4XJUDI 4UBSU 3FBDUJWF&YUFOTJPOT -PDBUJPO 0CTFSWBCMF -PDBUJPO ։࢝ #VUUPO *T%NT'PSNBU 4UBSU 9BNBSJO'PSNTσʔλόΠϯσΟϯά -PDBUJPO"QJ -PDBUJPO.BOBHFS <Inject> -PDBUJPO"QJ $--PDBUJPO.BOBHFS RxJava RxSwift ↓ Reactive Extensions Xamarin.FormsͰͷ࣮૷ύλʔϯ
  22.  .BJO1BHF .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ -BCFM දࣔܗࣜ

    4XJUDI 4UBSU 3FBDUJWF&YUFOTJPOT -PDBUJPO 0CTFSWBCMF -PDBUJPO ։࢝ #VUUPO *T%NT'PSNBU 4UBSU 9BNBSJO'PSNTσʔλόΠϯσΟϯά -PDBUJPO"QJ -PDBUJPO.BOBHFS <Inject> -PDBUJPO"QJ $--PDBUJPO.BOBHFS andoid:LocationaManager ios:CLLocationManager ↓ ϓϥοτϑΥʔϜݻ༗APIΛ ࢖࣮ͬͨ૷ΛDI (Dependency Injection) Xamarin.FormsͰͷ࣮૷ύλʔϯ
  23.  .BJO1BHF .BJO7JFX.PEFM ViewModel View Model -PDBUJPO6TFDBTF Ң౓ܦ౓ -BCFM දࣔܗࣜ

    4XJUDI 4UBSU 3FBDUJWF&YUFOTJPOT -PDBUJPO 0CTFSWBCMF -PDBUJPO ։࢝ #VUUPO *T%NT'PSNBU 4UBSU 9BNBSJO'PSNTσʔλόΠϯσΟϯά -PDBUJPO"QJ -PDBUJPO.BOBHFS <Inject> -PDBUJPO"QJ $--PDBUJPO.BOBHFS ڞ௨ԽͰ͖ͳ͍ͷ͸͚ͩ͜͜ Xamarin.FormsͰͷ࣮૷ύλʔϯ
  24. ڞ௨Խࣄྫ1: B2B޲͚ ं᫑ӡߦ؅ཧΞϓϦ  • ໿20ը໘ • ڞ௨Ͱͳ͍ॲཧ: GPS, Push௨஌,

    Ի੠࠶ੜ, Toast౳ • ૯ίʔυߦ਺: 22,816 Android:9% 2,134ߦ iOS:6% 1,407ߦ ڞ௨:85%
 19,275ߦ
  25. ڞ௨Խࣄྫ2: ΤΠνɾΤεূ݊ εϚג  • ໿70ը໘ • View͸C#ɺViewModelͱModel͸ F# Λ࢖༻

    • ૯ίʔυߦ਺: 72,445 Android:3% 2,130ߦ iOS:4% 2,897ߦ ڞ௨:93% 67,418ߦ JXUG#17ʮূ݊औҾΞϓϦͱNote app࡞ͬͯΈͨʯΑΓ
  26. Open Xamarin, ɹɹOpen Microsoft • Xamarin.Android .iOS .Forms ͸શͯOSS •

    .NET Core • .NETϑϨʔϜϫʔΫ(ͷҰ෦)ΛOSS&X-PlatԽ • AWS Lambda΍GCP͕.NET/C#ʹରԠ  ϚΠΫϩιϑτ = ϓϩϓϥΠΤλϦ .NET = Windows ͸΋͸΍ඇৗࣝʂ
  27. XamarinΛ࢖͏΂͖έʔε • B2BͳϞόΠϧɾλϒϨοτΞϓϦ • Win, Android, iOSͰڞ௨ϩδοΫΛ࠷େԽ • ӡ༻อकίετ㽊ɺཁһ֬อ •

    ελʔτΞοϓاۀ • ϏδωεϞσϧݕূ༻ʹαΫοͱ։ൃ • AndroidͱiOSࢢ৔ʹಉ࣌౤ೖ • ϑΟʔυόοΫɾϧʔϓΛૉૣ͘ճͤΔ