0

I am at the very start of a project where we are trying to write an application for an android smartphone that will call a shared library written in C.

It seems that the way to do this is to use the Android NDK to build the library in a binary format compatible with the smartphone hardware then use JNI to call the shared library from Java. Possibly using SWIG along the way to facilitate with the JNI wrapper functions.

But before I go down this route, am I missing any, potentially much simpler, approaches to getting a C app to run on a smartphone? What got me thinking that there may be other alternatives was the Canonical project looking to run ubuntu on a smartphone (http://www.ubuntu.com/devices/android) but it doesn't seem to be available yet.

Any lateral thoughts on this topic gratefully received

1
  • First, don't comment your own question - edit the question. Second, if you install Ubuntu and code for Ubuntu, that won't be an Android app anymore, right? Commented Jul 24, 2012 at 16:53

1 Answer 1

4

As far as I know, the NDK is the preferred route to follow when using native code in android. You can also build a java wrapper library around your C code, separate from your Android project, and include that .jar in your Android app. This uses standard Java instead of Google's NDK, and I have used several libraries built in this manner in android with very little effort.

Sign up to request clarification or add additional context in comments.

10 Comments

I agree. I thought what OP described was the easy way. I've put together a few projects with native C libraries that I've used via JNI bindings to Java code. From my experience, it's just a necessity of the platform.
i was just thinking if you can run ubuntu on your phone then I can just run my code as is - no need to worry about writing an android app, messing around with NDK or JNI or anything - just fire up a terminal and run it...
JNI and NDK are two totally different technologies. JNI is a way of wrapping a native library in Java, and the NDK is a way of writing your Android application completely in C/C++
I never said that you couldn't use the NDK in that way, but if all you're doing is throwing a wrapper around a C library (ie: you don't need Android API's in your C code) then there is no point in using the NDK. Just wrap the library, make a jar, and include it in your app.
You can use the NDK to build your library, or you can use a tool like SWIG (which claims it is compatible with Android). swig.org
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.