Porting a C/C++ program into Android - android

I am attempting to put my C++ program onto an Android phone but have run into several problems with the library linking. It seems most of the useful information I find on this topic through google is outdated (motz) or simply does not account for the complexity of my program. I have been able to run simple C programs but fail when attempting to use libraries outside of Android's Bionic/libc.
So my questions are:
Is it possible to port pre-existing *.so libraries onto Android? If so, how could I do this without seg faulting?
Should I be using the CodeSourcery compiler (arm-none-linux-gnueabi-*)?
How can I work around the lack of a seperate pthread library?
Please help me out! Thanks.
-Scott

You can't use pre-existing *.so files because they need to be compiled for Android. In order to create an *.so for Android you need to use their NDK, which is already set up to build the correct format so you don't need to worry about arm-none-linux-gnueabi or anything. If you want to use a library that isn't available on Android you'll need to build it yourself using the NDK. I had to do this with the STL.

Please refer to the following :
Can i use the native libraries (installed in android stack) in my NDK application?
This should answer you some queries...

Related

IDE to edit/modify native C/C++ files in Android Source code

I have been having tough time in finding a IDE or Editor which can help me easily modify the Android's C/C++ classes (mainly the classes under frameworks/base/core/jni)?
All the sites point to using Eclipse for development. But the dependencies were not resolved for C/C++ files. Java related dependencies are correctly resolved and the project is good enough to view the source files without any errors.
Right now, I just browse the C/C++ code in Eclipse CDT and make changes, compile using regular AOSP make commands and push it to my custom ROM. I am working on device drivers related work, so cannot use Emulator to test the changes :(
Two queries:
Is there a way, I can get content assist for Native C/C++ code for Android Source code ?
Is there any easy way to edit/build/run the native libraries quickly on Device ?
Any pointers will be highly appreciated.
You are on the right track. You build AOSP from terminal, but use IDE for browse/edit/debug sessions.
What worked for me is creating a big eclipse C/C++ project containing everything under frameworks/base. Use it for browsing/editing/debugging using all the helpers that eclipse provides.
Please check Debugging Android native applications to understand AOSP debugging.
I also have this problem! My solution is to re-set NDK path in "local.properties".
When i use default ndk path (ex: ndk.dir=C:\Users\%user\AppData\Local\Android\Sdk\ndk-bundle sdk.dir=C:\Users\%user\AppData\Local\Android\Sdk ) , I will have the same problem. So I download other NDK (from google official web-site) ,and set "ndk.dir", and I sloved.
You can try it~ maybe helpful for you.
ps. I use NDK version:14 , will happen this. I use v13 or v12 will solved.

Profiling android-ndk plain C/C++ executable

What is the best way to profile plain C/C++ android executables on a rooted android device?
android-ndk-profiler seems to support only ndk libraries linked to Java.
Any suggestions?
Thanks
I was faced with the same question recently. After looking into several alternatives I decided the best option (the one I made to work, at any rate) was to build Valgrind for Android.
This page describes how to build Valgrind for Android. See also my GitHub project for a slightly different build procedure, usage notes and prebuilt Android ARMv7 binaries.
Android NDK profiler work by GCC compiler trick so should work independent
of JNI
This link has the details
http://code.google.com/p/android-ndk-profiler/wiki/HowItWorks
As long as you can insert the startup and cleanup code into your C/C++ code it should work
You can find all the information you will need here
http://code.google.com/p/android-ndk-profiler/

How to integrate C++ file into Android Application using JNI

I want to use C++ file in my android application via JNI but i don't know how to integrate C++ file and how to Compile and run it.
Please help me if anybody knows about it
You need to do NDK programming. Android NDK
The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications.
Android applications run in the Dalvik virtual machine. The NDK allows you to implement parts of your applications using native-code languages such as C and C++. This can provide benefits to certain classes of applications, in the form of reuse of existing code and in some cases increased speed.
You can use Android NDK for your requirements.
Android-NDK
The NDK is a toolset that allows you to implement parts of your app using native-code languages such as C and C++. For certain types of apps, this can be helpful so that you may reuse existing code libraries written in these languages and possibly increased performance.
Tutorial Advanced Android: Getting Started with the NDK
Using Android NDK create shared library of your C,C++ files and load that library at runtime from your Android application. Look at tutorial I linked.

Building .so libraries on windows for use on android

I am building C libraries that will be used by an android app(through either JNI or the NDK, I've never used the NDK though) and I am wondering what IDE/development environment is best to use? I've basically only used Visual Studio for native development and I'm not sure how to adapt to building .so libraries for use on android.
Thanks
EDIT: Update -- I want to avoid makefiles if possible (never used them) and rather use a complete IDE such as the case with visual stuido to compile
Generally, cygwin (i.e. command line) is used for building Android native code. But you can also try to use Eclipse for this purpose. It doesn't help very much but it highlights syntax and you don't have to switch to other apps to write code and build your app. You can read more about using Eclipse for C/C++ Android development here.
I would strongly recommend that you use the NDK's compiler.
Normally this is done by writing an Android.mk in accordance with the instructions for the NDK. It is not complicated. The easiest thing to do is to grab the hello-jni sample app and just make the necessary changes, for example substituting your source files into its android.mk.
You can stay in visual studio if you like that as an editing environment, simply using the ability to bind an external command to a keystroke to launch the ndk build script. Ages ago I had figured out how to reformat GCC error messages with sed into something that VS could parse to make them click-able, though I soon moved development of that project under linux.
I think a lot of people use Eclipse as their IDE for Android development. I use it and its pretty good. You shouldn't have any problems if you're used to VS.
The Android SDK comes with a plugin, the Android Development Tools (ADT), to develop applications for Android inside the Eclipse IDE, which is same kind of beast as Visual Studio. And within that IDE, it is possible to use JavaCPP (disclaimer: I am the author) to have it compile all the native C/C++ stuff we need through the Android NDK, but without needing Makefiles and such. More details here:
http://code.google.com/p/javacpp/#Instructions_for_Android

Porting C to Android using Android NDK

Has anyone used the Android NDK to port a Linux app? We have an SSL VPN solution at work which Openconnect (http://www.infradead.org/openconnect.html) works with, but there is currently no client (from Cisco or otherwise) on Android. Is using the Android NDK a feasible approach to get this to work?
Thank you in advance
The NDK is a good solution for porting C/C++ Apps. You need to do a thin java shell to pass over any input, init and exit the program.
If your C app requires STL or exceptions - there are modified versions of the NDK that support them.
The Android NDK is not for porting apps. It is for creating libraries that can be accessed from a standard Android Dalvik app via JNI.
So, if you have the source code to this project, and it results in a .so, and you can write a JNI wrapper for it, the NDK may be a solution for you. Considering the project you cite seems dependent upon scripts, I suspect that's not how it was set up for use.

Categories

Resources