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
Xamarinからネイティブコードを活用する
Search
Nobuhiro Ito
May 28, 2014
Programming
1
970
Xamarinからネイティブコードを活用する
2014/05/28(Wed) Xamarin User Group 勉強会
Nobuhiro Ito
May 28, 2014
Tweet
Share
More Decks by Nobuhiro Ito
See All by Nobuhiro Ito
Bitriseで本をビルドする / Build a book with Bitrise
iseebi
0
130
BitriseでmacOSアプリをビルドする / Build macOS apps with Bitrise
iseebi
1
720
iOS/Androidアプリ転送ツール TransporterPadの紹介
iseebi
0
6k
Xamarinアプリとプッシュ通知
iseebi
2
1.6k
Apple Developer Enterprise Program でどこまでいけるのか
iseebi
0
730
ReactiveProperty を使ったアプリの設計に Realm Xamarin を組み合わせる
iseebi
0
610
ReactiveProperty で Xamarin アプリの作り方が変わった
iseebi
3
1.6k
600件のPull RequestからみたXamarinのはまりどころ
iseebi
3
4.1k
Yet Another Cross Platform Development
iseebi
0
4.1k
Other Decks in Programming
See All in Programming
距離関数を極める! / SESSIONS 2024
gam0022
0
290
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
890
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.7k
Quine, Polyglot, 良いコード
qnighy
4
650
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Rails Girls Zürich Keynote
gr2m
94
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Transcript
Xamarin +'/#4* ¬ĔĿ (@iseebi) XamarinķŁēŁĎĻŁĬÅL 2014/05/28(Wed)
»Ã • ¬x±À / ¬ĔĿ – @iseebi / id:iseebi • ĪćĿĺĻr!6,M½
– iOS / Android / Windows 8 ëĄĬĺ6ÚåòÜ • đIJĶģĞą – ĖıŁĠĪĉĿÅL@.R – ÜØÎHaskell¼t in • H¼ĀæòÜÊ(2¯7)
4-ëÑÚéÓÔ • iOS ëĤĆĞąīĦĆĿğąĿĎëiú$ • Android ëĤĆĞąīĦĆĿğąĿĎëiú$ • Â¥ iOS
ĄĬĺëĘŁĖÿvÏ
ĤĆĞąīĦĆĿğąĿĎ • ĤĆĞąīđŁġætÒüàĹĆīĹĺÿv<æÔû øÏêéû$5 – Xamarin.iOS æ Objective-C ætÒüà ĹĆīĹĺÿvÏ – Xamarin.Android
æ Java ö NDK ætÒüà ĹĆīĹĺÿvÏ
ĤĆĞąīĦĆĿğąĿĎÿvÎàÎoçì • jqŀ¢w¹(ë SDK – Admob – nend – Google Analytics • UIĹĆīĹĺ
– Nimbus
ĤĆĞąīĦĆĿğąĿĎÿvÎàÎoçì • ¤9Hëy< – Â¥ĄĬĺÿXamarin æĺĬļĆĖÚàÎ – æõ=,ëBsÿYãåÕû%'õéÎ â÷ãçÝäöúàÎ
iOS+'/-3(3"
iOSĤĆĞąīĦĆĿğąĿĎĬĽĕćčĠiN • Google Analytics SDK æöãåóòÜ – https://developers.google.com/analytics/ devguides/collection/ios/resources?hl=ja – ÜæêXamarin Components
ê ¨ÙüåÎûëæÉÍÕòælæÜÊ (EéE´ÓÈãååçÚåÎ)
Eéõëÿ • ĹĆīĹĺëĦĆĢĺĪăĆĻ (.a) • vÎàÎĆĿęŁĪćĆĖëĭĜĚ (.h) • Objective Sharpie
– http://docs.xamarin.com/guides/ios/ advanced_topics/binding_objective-c/ objective_sharpie/
ĬĽĕćčĠëiN • iOS Binding Project ÿiN – ĬĽĕćčĠ`êË.ÌÓäÕçĥıúòÜÊ (×ë9|iãåûçÔòàĥıãàÊĖčĔĸì.äÎåûëæI )
ĹĆīĹĺëU • ĬĽĕćčĠêĹĆīĹĺÿU
ĹĆīĹĺëU • .a ÿUÜûç .linkwith.cs ĪăĆĻÓ ?)êiùüòÜÊ
linkwith.cs ĪăĆĻ • ĤĆĞąīĹĆīĹĺëĺĿčê.ÜûeXÓtÒü åÎûÊ – #ÚåÎûCPUĄŁČĞčěĵÉ EçÜû©ĹĆīĹĺéèÿ\(ÜûÊ • ğĪĉĻĠæS2ëøÏé(Ó NÙüòÜ
[assembly: LinkWith ("libGoogleAnalyticsServices.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Simulator, ForceLoad = true)]
EéĪļŁijľŁč • iOSëĹĆīĹĺëÉ áÎàÎëìUĪļŁijľŁčÓEçé úòÜÊ • Google Analytics ë https://developers.google.com/analytics/devguides/collection/ios/v3/?hl=ja
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)]
(ëiN • ĺĿčÙüàĹĆīĹĺðë C#ëĆĿęŁĪćĆĖÿUÚòÜÊ – P/Invoke )éç×ý • Objective Sharpie êĭĜĚÿ¼òÞûçÉ?
)ê(ÿiNÚåÕüòÜÊ – NÙüàĪăĆĻë*nÿ ApiDefinition.cs çStructsAndEnums.cs ë êÒÔaóòÜÊ
None
None
None
None
?æiãåÕüûÓFsæìéÎ • 0Ùüà(ìÒéúĈĹŁáùÖ… – [¾Úåàú – [unmapped: unexposed: Elaborated] çÒ – VerifyAttribute çÒ
• ÓĀíãåéÑÜ – áïãåûëìÜ – VerifyAttributeìÉêtÒüåÎû3ÿ zfÚå¥ÚåÉJWéÖüíÜ • ¶éĹĆīĹĺñè PÓÎû – vþéÎõëì(ê"üûëÿÇôûÄP
(ĥıúİĆĿĠ • FieldAttribute ÓäÎåÎåÉ ĐĜęŁëóëĬĽħĞą • "__Internal" ÿäÖûEÓÍúòÜÊ [Field ("kGAIUseSecure",
"__Internal")] NSString GAIUseSecure { get; } [Field ("kGAIUseSecure")] NSString GAIUseSecure { get; }
ßüæõòáûĈĹŁ • ĹĆīĹĺìĩĻġÓ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)]
Android+'/-3(3"
Androidõ!ÛøÏê • Google Analytics æöãåóòÚ÷ÏÊ – https://developers.google.com/analytics/ devguides/collection/android/resources?hl=ja • Android ëì
.jar ĪăĆĻáÖæ OKÊ
ĬĽĕćčĠëiN • Android Java Bindings Library ÿiúòÜÊ
.jar ĪăĆĻëU • JarsĪĉĻĚðUÚòÜÊ • ÍçìĩĻġÚåþú – ÏòÕÕìÉDê×üáÖÊ – àáÚÉáÎàÎÏòÕÎÒéÎÊ
ĈĹŁë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)
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>
iOS01%4$
Â¥9Hë· • Â¥ë iOS ëĄĬĺÓÍãåÉ • oļĮĻæßëBsØçÓãÙúYãåÔàÎ • ßĀéçÔê×ë$5ÓvÐûçpÎòÜÊ
×ÏÎÏĄĬĺÿ·ÚòÜ .m, .xib, .png ² vÎßÏéĪăĆĻ1ú
zf<ĄĬĺĬĽĕćčĠiN • Empty Application éèæiNÚòÜÊ
zf<ĄĬĺĬĽĕćčĠÿiû • ĬĽĕćčĠÿªčĺĜčÚåÉ ĹĆīĹĺĬĽĕćčĠÿiû
ĬĽĕćčĠiN • Cocoa Touch Static Library ÿiN
ĺĘŁĖ<ëNÿU • ĹĆīĹĺëĬĽĕćčĠĬĽħĞąÿ6ÔÉęŁĐĜ ĠU
ĺĘŁĖ<ëNëU • Bundle ÿU – OS X êÚÒéÎëæÉòÝìOS X æU
ĺĘŁĖ<ëNëU • BundleëęŁĐĜĠSDKÿÚå ĬĽĕćčĠêþÞû ċŁĘĻÍþÞå deleteÿ®Ü ³¡êéãåiOSêéû
ęŁĐĜĠë¿¥.{O( • LibraryìResourcesê¿¥Üûç(ÜûÊ
ęŁĐĜĠë¿¥.{O( • cëĘŁĖÓ¿¥Üû Framework ÿ ÁÜû
ĩĻġëO( • ĬĽĕćčĠëO(æ Build Active Architecture Only ëO(ÿ No êÜû
ķģĦŁĒĻĹĆīĹĺiN • ĔIJĶļŁę<ç8B<ëĦĆĢĺÿ bÜûĄčĔĸĿÿUÜû – ĔIJĶļŁę<ç8B<ëĦĆĢĺì }êiNÙüûàô • ęŁĐĜĠêAggregateÿU [ĬĽĕćčĠ`]Universal çÎÏ
`&ÿ~Öû×çÓ]ÎæÜÊ
ķģĦŁĒĻĹĆīĹĺiN • Aggregate ê Run Script Build Phase ÿ UÚòÜ
ķģĦŁĒĻĹĆīĹĺiN • ĖčĺĬĠÿtÔòÜÊ Bundle ë¿¥õ(ÚåÑÔòÜÊ
# 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}/"
ĘŁĖÿĬĽĕćčĠêU • ĬĽĕćčĠêĘŁĖŀĺĘŁĖÿU – ĘŁĖì Library ðÉĺĘŁĖì Bundle ðęŁĐĜĠ ÿėĜĠÜû
None
đŁġë> • ĺĘŁĖÿ¼ó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; }
?đŁġÿtÕ • Objective Sharpie æ;ÙÞûđŁġÿ CêÜûç'ÓÒÒùéÎÊ – CëĊīĕćčĠÓåÕûđŁġÿtÕççåõ¦Ê #import "Editor.h" #import
<UIKit/UIKit.h> @implementation Editor + (UIViewController *) editorViewController; @end
××òæĹĆīĹĺëO( ××ÒùĒĿĬĻĄĬĺëO(
ĹĆīĹĺÿÁêU • ĄĬĺë Link Binary With Libraries êU Copy Bundle
Resources êì + æ å×éÎ×çÓÍûëæ ßëìĪăĆĻĝĺŁÒù ġĽĜĬÜû
ĭĜĚëÁħĖÿO( • ĄĬĺë User Header Search Path ê $SRCROOT ÿėĜĠ
ÍçìèÏÜû • ęŁĐĜĠuú°ÐåiÿÜû ĒĿĬĻĄĬĺæ?izf …Universal æĦĆĢĺiN (iOS Device êÍþÞû×ç )
ÍçìèÏÜû • Universal ëñÏÿ8ÜûçÉ NbwëĪĉĻĚÓ6Õ – ĬĽĕćčĠêUÜû .a ç Objective Sharpie
êÒÖû .h Ó 0ÙüåÎû – ×üÿvãåĦĆĿğąĿĎÿiN
òçô • ĤĆĞąīĦĆĿğąĿĎì P – ĈĹŁÿ PøÕÚåÎÕi – vþéÎĴĘĜġéèÿ«û²É ]ìÇôû (¢o) – ê
Android ë Transform ìÉþÒúöÜÎĺĪăļ ĿĖÿòáæÔåÎéÎ… (ÆÒmÐåÕáÙÎw) • æöûçÔìĆĿęŁĪćĆĖÿ GÜüí¦ – ĬĽĕćčĠëO(Óâ÷ãçáÖ'
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-ëĒĿĬĻ