Xamarinからネイティブコードを活用する

 Xamarinからネイティブコードを活用する

2014/05/28(Wed) Xamarin User Group 勉強会

619fccc61ef955ccf39bfa41df527042?s=128

Nobuhiro Ito

May 28, 2014
Tweet

Transcript

  1. Xamarin  +'/#4*  ¬€ĔĿ (@iseebi) XamarinķŁēŁĎĻŁĬÅL 2014/05/28(Wed)

  2. »Ãž •  ¬x±À / ¬€ĔĿ – @iseebi / id:iseebi •  ĪćĿĺĻrƒ‚!6,M½

    – iOS / Android / Windows 8 ëĄĬĺ6ÚåòÜ •  đIJĶģĞą – ĖıŁĠĪĉĿÅL@.R – ÜØÎHaskell¼t in ” •  H¼ĀæòÜÊ(2¯7)
  3. 4-ëÑÚéÓÔ •  iOS ëĤĆĞąīĦĆĿğąĿĎëiú$ •  Android ëĤĆĞąīĦĆĿğąĿĎëiú$ •  Â¥ iOS

    ĄĬĺëĘŁĖÿvÏ
  4. ĤĆĞąīĦĆĿğąĿĎ •  ĤĆĞąīđŁġætÒüàĹĆīĹĺÿv<æÔû øÏêéû$5 – Xamarin.iOS æ Objective-C ætÒüà ĹĆīĹĺÿvÏ – Xamarin.Android

    æ Java ö NDK ætÒüà ĹĆīĹĺÿvÏ
  5. ĤĆĞąīĦĆĿğąĿĎÿvÎàÎoçì •  jqŀ¢w¹(ë SDK – Admob – nend – Google Analytics •  UIĹĆīĹĺ

    – Nimbus
  6. ĤĆĞąīĦĆĿğąĿĎÿvÎàÎoçì •  …¤9Hëy< – Â¥ĄĬĺÿXamarin æĺĬļĆĖÚàÎ – æõ=,ëBsÿYãåÕû%'õéÎ â÷ãçÝäöúàÎ 

  7. iOS+'/-3(3"

  8. iOSĤĆĞąīĦĆĿğąĿĎĬĽĕćčĠiN •  Google Analytics SDK æöãåóòÜ – https://developers.google.com/analytics/ devguides/collection/ios/resources?hl=ja – ÜæêXamarin Components

    ê ¨ŸÙüåÎûëæÉÍÕòæŠlæÜÊ (‡EéE´ÓÈãååçÚå‘Î)
  9. ‡Eéõëÿ„‹ •  ĹĆīĹĺëĦĆĢĺĪăĆĻ (.a) •  vÎàÎĆĿęŁĪćĆĖëĭĜĚ (.h) •  Objective Sharpie

    – http://docs.xamarin.com/guides/ios/ advanced_topics/binding_objective-c/ objective_sharpie/
  10. ĬĽĕćčĠëiN •  iOS Binding Project ÿiN – ĬĽĕćčĠ`êË.ÌÓäÕçĥıúòÜÊ (×ë9|iãåûçÔòàĥıãàÊĖčĔĸì.äÎåûëæšI ) 

  11. ĹĆīĹĺëœU •  ĬĽĕćčĠêĹĆīĹĺÿœU

  12. ĹĆīĹĺëœU •  .a ÿœUÜûç .linkwith.cs ĪăĆĻÓ ?)êiùüòÜÊ

  13. linkwith.cs ĪăĆĻ •  ĤĆĞąīĹĆīĹĺëĺĿčê.ÜûeXÓtÒü åÎûÊ – #ŒÚåÎûCPUĄŁČĞčěĵÉ ‡EçÜû©„ĹĆīĹĺéèÿ\(ÜûÊ •  ğĪĉĻĠæS2ëøÏé(•Ó NÙüòÜ

    [assembly: LinkWith ("libGoogleAnalyticsServices.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Simulator, ForceLoad = true)]
  14. ‡EéĪļŁijľŁč •  iOSëĹĆīĹĺëÉ áÎàÎëìœUĪļŁijľŁčӇEçé úòÜÊ •  Google Analytics ë https://developers.google.com/analytics/devguides/collection/ios/v3/?hl=ja

  15. œUĪļŁijľŁčë\( •  LinkWithAttribute ê Frameworks ÿœU •  .framework æéÎõëìÉ LinkerFlags

    æœUÚòÜÊ [assembly: LinkWith ("libGoogleAnalyticsServices.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Simulator, ForceLoad = true, Frameworks = "CoreData SystemConfiguration AdSupport", LinkerFlags = "-lz", IsCxx = true)] 
  16. (•ëiN •  ĺĿčÙüàĹĆīĹĺðë C#ëĆĿęŁĪćĆĖÿœUÚòÜÊ – P/Invoke )éç×ý •  Objective Sharpie êĭĜĚÿ¼òÞûçÉ?

    )ê(•ÿiNÚåÕüòÜÊ –  NÙüàĪăĆĻë*nÿ ApiDefinition.cs çStructsAndEnums.cs ë êÒÔaóòÜÊ
  17. None
  18. None
  19. None
  20. None
  21. ?æiãåÕüûÓFsæìéÎ •  0Ùüà(•ìÒéúĈĹŁáùÖ… – [¾Úåàú – [unmapped: unexposed: Elaborated] çÒ – VerifyAttribute çÒ

    •  ÓĀíãåéÑÜ – áïãåûëìÜ – VerifyAttributeìÉêtÒüåÎû™3ÿ zfÚ奈ÚåÉJWéÖüíÜ •  ¶éĹĆīĹĺñè PÓÎû – vþéÎõëì(•ê"üûëÿÇôûÄP
  22. (•ĥıúİĆĿĠ •  FieldAttribute ÓäÎåÎåÉ ĐĜęŁëóëĬĽħĞą •  "__Internal" ÿäÖû‡EÓÍúòÜÊ [Field ("kGAIUseSecure",

    "__Internal")] NSString GAIUseSecure { get; }  [Field ("kGAIUseSecure")] NSString GAIUseSecure { get; } 
  23. ßüæõòáûĈĹŁ •  ĹĆīĹĺìĩĻġÓ1ãåõÉ C)êĄĬĺÿĩĻġÜûçÔê úéÎçZþüûĹĆīĹĺÓÍû – 8_êĄĬĺêĺĿčÜûçÔê^3ÜûÊ – gùÝgùÝëÏâêvãåûöäçÒÊ •  LinkWith êĹĆīĹĺÿÚòÚ÷ÏÊ

    [assembly: LinkWith ("libGoogleAnalyticsServices.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Simulator, ForceLoad = true, Frameworks = "CoreData SystemConfiguration AdSupport", LinkerFlags = "-lz -lsqlite3", IsCxx = true)] 
  24. Android+'/-3(3"

  25. Androidõ!ÛøÏê •  Google Analytics æöãåóòÚ÷ÏÊ – https://developers.google.com/analytics/ devguides/collection/android/resources?hl=ja •  Android ëì

    .jar ĪăĆĻáÖæ OKÊ
  26. ĬĽĕćčĠëiN •  Android Java Bindings Library ÿiúòÜÊ

  27. .jar ĪăĆĻëœU •  JarsĪĉĻĚðœUÚòÜÊ •  ÍçìĩĻġÚåþú – ÏòÕÕìÉDê×üáÖÊ – àáÚÉáÎàÎÏòÕÎÒéÎÊ

  28. ĈĹŁëd/ •  h[(•Ó ÚàúÚòÜŀŀŀ •  Transforms ëë XML æ>—ÚòÜÊ – ìòáÍòú;dæÔåÑùÝ…

    – https://bugzilla.xamarin.com/show_bug.cgi? id=15005 Error CS0102: The type `Com.Google.Analytics.Containertag.Proto.DebugEventInfo' already contains a definition for `EventType' (CS0102) 
  29. Transforms/Metadata.xml •  4-ìC˜×üáÖÍüí1û£+Ê – 17ì@6ÙüåéÎ,ÿòçôå§K – 27쵺cëčĹĖÿLG)êtÔ •  ­@6ëčĹĖÒùµºÙüåÎû@6čĹĖáãààôÉ ùÚÎÊ <metadata> <remove-node

    path="/api/package[@name!='com.google.analytics.tracking.android']" /> <attr path="/api/package[@name='com.google.analytics.tracking.android']/ class[@name='GoogleAnalytics']" name="extends">java.lang.Object</attr> </metadata> 
  30. iOS01%4$

  31. Â¥9H뛷 •  Â¥ë iOS ëĄĬĺÓÍãåÉ •  oļĮĻæßëBsØçÓãÙúYãåÔàÎ •  ßĀéçÔê×ë$5ÓvÐûçpÎòÜÊ

  32. ×ÏÎÏĄĬĺÿ›·ÚòÜ .m, .xib, .png ² vÎßÏéĪăĆĻ1ú

  33. zf<ĄĬĺĬĽĕćčĠiN •  Empty Application éèæiNÚòÜÊ

  34. zf<ĄĬĺĬĽĕćčĠÿiû •  ĬĽĕćčĠÿªčĺĜčÚåÉ ĹĆīĹĺĬĽĕćčĠÿiû

  35. ĬĽĕćčĠiN •  Cocoa Touch Static Library ÿiN

  36. ĺĘŁĖ<ë–NÿœU •  ĹĆīĹĺëĬĽĕćčĠĬĽħĞąÿ6ÔÉęŁĐĜ ĠœU

  37. ĺĘŁĖ<ë–NëœU •  Bundle ÿœU – OS X êÚÒéÎëæÉòÝìOS X æœU

  38. ĺĘŁĖ<ë–NëœU •  BundleëęŁĐĜĠSDKÿÚå ĬĽĕćčĠêþÞû ċŁĘĻÍþÞå deleteÿ®Ü ³¡êéãåiOSêéû

  39. ęŁĐĜĠë¿¥.{O( •  LibraryìResourcesê¿¥Üûç(•ÜûÊ

  40. ęŁĐĜĠë¿¥.{O( •  cëĘŁĖÓ¿¥Üû Framework ÿ ŠÁÜû

  41. ĩĻġëO( •  ĬĽĕćčĠëO(æ Build Active Architecture Only ëO(ÿ No êÜû

  42. ķģĦŁĒĻĹĆīĹĺiN •  ĔIJĶļŁę<ç8B<ëĦĆĢĺÿ bÜûĄčĔĸĿÿœUÜû – ĔIJĶļŁę<ç8B<ëĦĆĢĺì }êiNÙüûàô •  ęŁĐĜĠêAggregateÿœU [ĬĽĕćčĠ`]Universal çÎÏ

    `&ÿ~Öû×çÓ]ÎæÜÊ
  43. ķģĦŁĒĻĹĆīĹĺiN •  Aggregate ê Run Script Build Phase ÿ œUÚòÜ

  44. ķģĦŁĒĻĹĆīĹĺiN •  ĖčĺĬĠÿtÔòÜÊ Bundle ë¿¥õ(•ÚåÑÔòÜÊ

  45. # define output folder environment variable LIBRARY_TARGET_NAME=${PROJECT_NAME} UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal # Step

    1. Build Device and Simulator versions xcodebuild -target "${LIBRARY_TARGET_NAME}" ONLY_ACTIVE_ARCH=NO -configuration $ {CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" xcodebuild -target "${LIBRARY_TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" # make sure the output directory exists mkdir -p "${UNIVERSAL_OUTPUTFOLDER}" # Step 2. Create universal binary file using lipo lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a" "${BUILD_DIR}/$ {CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a" "${BUILD_DIR}/${CONFIGURATION}- iphonesimulator/lib${PROJECT_NAME}.a" # Last touch. copy the header files. Just for convenience cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/include" "${UNIVERSAL_OUTPUTFOLDER}/" cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${LIBRARY_TARGET_NAME}Resources.bundle" "${UNIVERSAL_OUTPUTFOLDER}/” open "${UNIVERSAL_OUTPUTFOLDER}/"
  46. ĘŁĖÿĬĽĕćčĠêœU •  ĬĽĕćčĠêĘŁĖŀĺĘŁĖÿœU – ĘŁĖì Library ðÉĺĘŁĖì Bundle ðęŁĐĜĠ ÿėĜĠÜû

  47. None
  48. đŁġë>— •  ĺĘŁĖÿ¼óaĀæÎûç×ýìE>— •  [NSBundle mainBundle] æìéÕÉ ĹĆīĹĺë bundle ÿ3k\(Üû

    – xib*ëĺĘŁĖìďĄAE •  ×ÏÎÏĴĘĜġÓÍûç¸VÊ static NSBundle *editor_SharedBundle = nil; + (NSBundle *)bundle { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ editor_SharedBundle = [NSBundle bundleWithURL: [[NSBundle mainBundle] URLForResource:@"EditorResources” withExtension:@"bundle"]]; }); return editor_SharedBundle; }
  49. “?đŁġÿtÕ •  Objective Sharpie æŽ;ÙÞûđŁġÿ C˜’êÜûç'ÓÒÒùéÎÊ – C˜’ëĊīĕćčĠÓåÕûđŁġÿtÕççåõ¦Ê #import "Editor.h" #import

    <UIKit/UIKit.h> @implementation Editor + (UIViewController *) editorViewController; @end
  50. ××òæĹĆīĹĺëO( ××ÒùĒĿĬĻĄĬĺëO(

  51. ĹĆīĹĺÿŠÁêœU •  ĄĬĺë Link Binary With Libraries êœU Copy Bundle

    Resources êì + æ å×éÎ×çÓÍûëæ ßëìĪăĆĻĝĺŁÒù ġĽĜĬÜû
  52. ĭĜĚëŠÁħĖÿO( •  ĄĬĺë User Header Search Path ê $SRCROOT ÿėĜĠ

  53. ÍçìèÏÜû •  ęŁĐĜĠuú°ÐåiÿÜû ĒĿĬĻĄĬĺæ?izf …Universal æĦĆĢĺiN (iOS Device êÍþÞû×ç )

  54. ÍçìèÏÜû •  Universal ëñÏÿ8ÜûçÉ NbwëĪĉĻĚÓ6Õ – ĬĽĕćčĠêœUÜû .a ç Objective Sharpie

    êÒÖû .h Ó 0ÙüåÎû – ×üÿvãåĦĆĿğąĿĎÿiN
  55. òçô •  ĤĆĞąīĦĆĿğąĿĎì P – ĈĹŁÿ PøՐÚåÎÕi – vþéÎĴĘĜġéèÿ«û²É ]‰ìÇôû (¢o) – †ê

    Android ë Transform ìÉþÒúöÜÎĺĪăļ ĿĖÿòáæÔåÎéÎ… (ÆÒmÐåÕáÙÎw) •  æöûçÔìĆĿęŁĪćĆĖÿ G’Üüí¦ –  ĬĽĕćčĠëO(Óâ÷ãçáÖ'
  56. Šl9| •  Binding Objective-C | Xamarin –  http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c/ •  Automated

    Binding Definitions using Objective Sharpie | Xamarin –  http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c/ objective_sharpie/ •  Binding a Java Library | Xamarin –  http://docs.xamarin.com/guides/android/advanced_topics/java_integration_overview/ binding_a_java_library_%28.jar%29/ •  API Metadata Reference | Xamarin –  http://docs.xamarin.com/guides/android/advanced_topics/java_integration_overview/ binding_a_java_library_%28.jar%29/api_metadata_reference/ •  Creating a Static Library in iOS Tutorial | Ray Wenderlich –  http://www.raywenderlich.com/41377/creating-a-static-library-in-ios-tutorial •  Sandbox/XamarinUGWorkshop_20140528 at master · iseebi/Sandbox –  https://github.com/iseebi/Sandbox/tree/master/XamarinUGWorkshop_20140528 –  4-ëĒĿĬĻ