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

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

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

619fccc61ef955ccf39bfa41df527042?s=128

Nobuhiro Ito

May 28, 2014
Tweet

Transcript

  1. 2.

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

    – iOS / Android / Windows 8 ëĄĬĺ6ÚåòÜ •  đIJĶģĞą – ĖıŁĠĪĉĿÅL@.R – ÜØÎHaskell¼t in ” •  H¼ĀæòÜÊ(2¯7)
  2. 9.

    ‡Eéõëÿ„‹ •  ĹĆīĹĺëĦĆĢĺĪăĆĻ (.a) •  vÎàÎĆĿęŁĪćĆĖëĭĜĚ (.h) •  Objective Sharpie

    – http://docs.xamarin.com/guides/ios/ advanced_topics/binding_objective-c/ objective_sharpie/
  3. 13.

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

    [assembly: LinkWith ("libGoogleAnalyticsServices.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Simulator, ForceLoad = true)]
  4. 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)] 
  5. 16.

    (•ëiN •  ĺĿčÙüàĹĆīĹĺðë C#ëĆĿęŁĪćĆĖÿœUÚòÜÊ – P/Invoke )éç×ý •  Objective Sharpie êĭĜĚÿ¼òÞûçÉ?

    )ê(•ÿiNÚåÕüòÜÊ –  NÙüàĪăĆĻë*nÿ ApiDefinition.cs çStructsAndEnums.cs ë êÒÔaóòÜÊ
  6. 17.
  7. 18.
  8. 19.
  9. 20.
  10. 21.

    ?æiãåÕüûÓFsæìéÎ •  0Ùüà(•ìÒéúĈĹŁáùÖ… – [¾Úåàú – [unmapped: unexposed: Elaborated] çÒ – VerifyAttribute çÒ

    •  ÓĀíãåéÑÜ – áïãåûëìÜ – VerifyAttributeìÉêtÒüåÎû™3ÿ zfÚ奈ÚåÉJWéÖüíÜ •  ¶éĹĆīĹĺñè PÓÎû – vþéÎõëì(•ê"üûëÿÇôûÄP
  11. 22.

    (•ĥıúİĆĿĠ •  FieldAttribute ÓäÎåÎåÉ ĐĜęŁëóëĬĽħĞą •  "__Internal" ÿäÖû‡EÓÍúòÜÊ [Field ("kGAIUseSecure",

    "__Internal")] NSString GAIUseSecure { get; }  [Field ("kGAIUseSecure")] NSString GAIUseSecure { get; } 
  12. 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)] 
  13. 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) 
  14. 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> 
  15. 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}/"
  16. 47.
  17. 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; }
  18. 51.

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

    Resources êì + æ å×éÎ×çÓÍûëæ ßëìĪăĆĻĝĺŁÒù ġĽĜĬÜû
  19. 55.

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

    Android ë Transform ìÉþÒúöÜÎĺĪăļ ĿĖÿòáæÔåÎéÎ… (ÆÒmÐåÕáÙÎw) •  æöûçÔìĆĿęŁĪćĆĖÿ G’Üüí¦ –  ĬĽĕćčĠëO(Óâ÷ãçáÖ'
  20. 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-ëĒĿĬĻ