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
980
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
730
iOS/Androidアプリ転送ツール TransporterPadの紹介
iseebi
0
6k
Xamarinアプリとプッシュ通知
iseebi
2
1.6k
Apple Developer Enterprise Program でどこまでいけるのか
iseebi
0
740
ReactiveProperty を使ったアプリの設計に Realm Xamarin を組み合わせる
iseebi
0
610
ReactiveProperty で Xamarin アプリの作り方が変わった
iseebi
3
1.6k
600件のPull RequestからみたXamarinのはまりどころ
iseebi
3
4.2k
Yet Another Cross Platform Development
iseebi
0
4.2k
Other Decks in Programming
See All in Programming
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
210
ChatGPT とつくる PHP で OS 実装
memory1994
PRO
2
100
たのしいparse.y
ydah
3
120
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
500
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
150
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
140
useSyncExternalStoreを使いまくる
ssssota
6
1.1k
Jakarta EE meets AI
ivargrimstad
0
250
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
140
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
Featured
See All Featured
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Fireside Chat
paigeccino
34
3.1k
Agile that works and the tools we love
rasmusluckow
328
21k
Being A Developer After 40
akosma
87
590k
4 Signs Your Business is Dying
shpigford
181
21k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Designing for Performance
lara
604
68k
A better future with KSS
kneath
238
17k
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-ëĒĿĬĻ