Reputation: 379
I would like to create a dll that would contain definition for some functions. I would be able to use the functions in both Objective-c and java environnement.
Is it even possible to do this?
Thanks!
Upvotes: 0
Views: 745
Reputation: 61331
Write in C or C++. You'll be able to link that to Objective C/Cocoa via the magic of Objective C++, and to Java on Android via NDK and JNI. That's what I do in my project. The compiler is GCC in both cases, the RTL is not identical but similar enough.
Avoid hairy data structures in the interface, stick to primitives and primitive arrays. And, naturally, you'll probably need to abstract away some of the platform.
You might want to compile your code with -fshort-wchar. It happens so that short
is the native character format in both Cocoa and JNI. You'll lose widestring functions of the RTL though, but they're no use with Cocoa strings and Java strings anyway. Or you can use UTF-8 on the library/platform boundary. Conversion overhead on every call, yadda yadda.
Note: if you just want to reuse some minor helper functions, it's just easier to write them twice, or copy/paste then adjust the syntax. Debugging NDK code is notoriously tricky. Only go this way if the shared bits constitute 25-30% of the project or more. In my case, it's more like 60% shared.
EDIT: if you go this way, some further porting to other mobile platforms will be a snap and some - not so much. Specifically:
Upvotes: 1
Reputation: 33428
If you want to create an application for iOS and Android and you want to reuse the business logic of your application (not the UI), take a look to Xamarin.
You can develop with C# and create Android and/or iOS apps.
From Xamarin web site:
Save time by sharing data structures and non-UI code between iOS and Android.
Hope it helps.
Upvotes: 1