Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Developing a shared Android / iOS network library

I have been primarily developing iOS apps but now, I'm developing applications for both iOS and Android. As much as possible, I'm trying to write code that is platform-independent as possible.

What have people done for networking functionality? I can't seem to find any resources on making GET/POST HTTP requests in Android.

How would you approach the issue of developing a shared networking library for both iOS and Android.

EDIT: I'll be doing all my Android network programming in C/C++ and not Java!

Are there any C/C++ networking libraries for Android (and subsequently can be used for iOS)?

like image 622
Mark Avatar asked Dec 19 '10 23:12

Mark


People also ask

Can I build iOS app with Android Studio?

Once you've made your Android application cross-platform, you can create an iOS application and reuse the shared business logic in it. Create an iOS project in Xcode. Connect the framework to your iOS project.

How do I make an app for both Android and iOS?

Native Script NativeScript is a free and open-source framework to develop a mobile application for both Apple iOS and Google's Android platform. It allows you to build native mobile apps in both TypeScript and JavaScript and using Angular and Vuejs.

What is Network Library in Android?

Fast Android Networking Library is a powerful library for doing any type of networking in Android applications which is made on top of OkHttp Networking Layer. Fast Android Networking Library takes care of each and everything. So you don't have to do anything, just make request and listen for the response.


5 Answers

I don't think this is as impossible as most people here make it sound like. I interviewed someone recently who worked for a large mobile game development company and he mentioned that they do as much work as they can in C/C++ libs in order to reuse the code on multiple platforms including Android and iOS. I haven't tried this myself, but I've heard this numerous times.

As an example, check out this blog post: http://thesoftwarerogue.blogspot.com/2010/05/porting-of-libcurl-to-android-os-using.html

If the cURL library can be used on Android, I don't see why your networking library couldn't. The difficulties will most likely be related to interacting with the GUI since you don't have access to the platform SDKs from your C/C++ code base. But for a networking lib, that's perfectly OK. Here is what I suggest:

  1. Write some proof of concept code to see how you can link with the lib from both platforms. Consider the limitations in the design of your library.
  2. Develop your networking library as a standalone project with a test driven development approach. That is, write unit tests to drive your code to test it as it's being developed.
  3. Write wrapper classes in native code in both Android and iOS projects to isolate the library code.

Also, as was previously mentioned, Apple is ok with developing apps in C/C++ as long as they are done with XCode. They've even relaxed on that requirement last year.

Good luck

like image 162
Sebastien Martin Avatar answered Oct 05 '22 17:10

Sebastien Martin


Considering the differences it's not really possible. It's a pain in the ass to write a Blackberry/Android shared library and they both use "Java".

If you really want to do cross platform, then you will be writing webpages in javascript and then delivering them on web-views on the devices.

You can't really share code across Objective C and Java, it's a impossibility afaik, and you can't run Java on the iPhone and you can't run ObjectiveC on Android. So there is no possible sane way to do this with native code.

Edit: As far as networking goes, don't think you'll find many places where you can access low-level network across platforms in a uniform way.

like image 39
HaMMeReD Avatar answered Oct 05 '22 18:10

HaMMeReD


I suppose you are talking about native (not web-based) applications. To make GET/POST HTTP requests in Android you should take a look to HTTPClient. This Java library comes with Android and it allows to develop the features you need:

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
try {
    HttpResponse response = client.execute(request);
    ...
} catch(Exception ex) {
    // handle
}

About how to develop a shared networking library for both iOS and Android, it is an interesting question, I can't figure out any solution because the platforms have too much differences (Java vs Objective C the most obvious), but it would be great.

I can say that Android supports C/C++ code via NDK, but I'm not sure if that works in iOS.

like image 23
Guido Avatar answered Oct 05 '22 18:10

Guido


You can try Titanium, source code is in JS then cross compiles to iOS or Android.

like image 29
aromero Avatar answered Oct 05 '22 17:10

aromero


As others have said, it won't be easy, if it's possible at all. If you decide to make an attempt, I would recommend working in C/C++ since both platforms can handle that language. (iOS is Objective-C, as you know, and Android can handle C via the NDK.) Don't bother trying to get Java to run on iOS...

like image 37
Moshe Avatar answered Oct 05 '22 18:10

Moshe