Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
145 views
in Technique[技术] by (71.8m points)

java - Crossplatform iPhone / Android code sharing

Simply put: What is the most effective way to share / reuse code between iPhone and Android builds?

The two most common scenarios I think would be:

  1. Blank slate new project, knowing ahead of time there is a large chunk of reusable logic that needs to run on each device.
  2. Existing iPhone code base, porting of C, C++ and Objective-C to the Android NDK or otherwise.

Yes of course in a perfect world all apps would just plug into the magical cloud and all the reusable logic would be up in Google App Engine or some web services, but that is not the spirit of this question. After experiencing a port of iPhone to Android with no code reuse at all second-hand and seeing the pain that person had to endure, I'd like to know how other people are avoiding it.

question from:https://stackoverflow.com/questions/2380258/crossplatform-iphone-android-code-sharing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In my experience, you can use Android NDK to compile C and C++ , so if you use iPhone Obj-C++ (.mm) bindings for a C++/C engine in the iPhone, and in Android you use Java bindings to the same engine, It should be totally possible.

So C++/C engine ( almost same codebase for Android and iPhone ) + Thin bindings layer = Portable code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...