Porting C++ code to ANdroid NDK?

878 views
Skip to first unread message

Android Wiss

unread,
Nov 16, 2011, 1:10:10 PM11/16/11
to andro...@googlegroups.com
Hello All,
I am just a beginner in the NDK world.   I have a large C++ VPROJ, which I need to Port into the Android.  I have already successfully setup the NDK, where I ran a simple program.  Now, I am running into issue with the efficiency, so I can get everything done in tight schedule, and I kind of feel overwhelmed here.  Question:
1.  Is there some quick way to port a large C++ VPROJ or I need to do everything manually?
2. If I have to do everything manually, is there some of the examples out there that shows the *.cpp before and after which could help view the differences.
 
Thank you in advance,
 
 
Android Wiss

Tor Lillqvist

unread,
Nov 17, 2011, 7:07:52 AM11/17/11
to andro...@googlegroups.com
Your question doesn't make much sense. What is a "VPROJ"? What does the code do? If it is a library with no user interface, and written in portable fashion, there really isn't much "porting", you just need to compile it. (And then use it from some GUI layer you write.)

But if your code for instance (and perhaps as is likely) is a Win32 program with Win32 GUI, then it doesn't even make sense to talk about "porting"- It is more of a re-write: You need to re-design and  re-write all the GUI parts. Hopefully you have separated them cleanly from the non-interactive calculations.

--tml

Vinay Julme

unread,
Nov 17, 2011, 2:02:12 PM11/17/11
to andro...@googlegroups.com
Hi Android Wiss,

VJPROJ is a kind of WIN32 program you can't directly port it. I guess you would need to rewrite the code.

Look how  tesseract code is used to compile for android. Tesseract is an OCR code written with VC++ and then complied to work with JNI. You can also see how OpenGL sources are complied, but i don't think it would be of much help but you can certainly look at tesseract code.

Vinay Julme
**************





--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/4UR2AMj633kJ.

To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

bdk

unread,
Nov 18, 2011, 5:32:04 AM11/18/11
to android-ndk
I never used this, but maybe it could help

http://code.google.com/p/vs-android/

--
Mathieu

Android Wiss

unread,
Nov 28, 2011, 11:18:27 AM11/28/11
to andro...@googlegroups.com
Thank you, I greatly appreciate it..

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.

Javier Pajuelo

unread,
Jun 26, 2013, 1:43:46 PM6/26/13
to andro...@googlegroups.com
Hello All,

I know that this post is very old, but I have a similar question. I believe that it is very relevant and there should be copious material on the net, but I have been unable to find it.

I am trying to port a C++ project into Android. My project uses NTL, GMP, and OpenSSL. I am able to compile this libraries using instructions on the net, but I wonder how to go about calling the code in the project.
I have seen examples that individually call a function from a library in C++. So, this function would be wrapped in JAVA JNI form. 
I highly doubt that this is the way to go in porting a huge project with many lines of code in many different files and different function calls.

Any one can help?
Thank you.

Reece Dunn

unread,
Jun 26, 2013, 6:05:49 PM6/26/13
to andro...@googlegroups.com

The approach I am taking is to define a Java-based API that the Android code calls into. This is designed around the needs of the application.

I then create the native methods on the Java side and create the associated C/C++ code to bridge the Android/Java and C/C++ worlds. NOTE: If you need to bind a C++ class, the |int nativeCreate()|, |void nativeDestroy(int handle)|, |void nativeFoo(int handle, String arg)| structure works well.

I then have the JNI methods call the appropriate C/C++ calls. Any type conversion is restricted to the JNI methods, so you can have the JNI layer in a single file.

The JNI methods, or the code they call, can do complex things -- you don't need the JNI binding to be a thin layer on the C/C++ APIs you are using.

For example, if you want to encrypt a message, you may create an API like:

    public class Encrypter {
        public static String encrypt(String message, String password) {
            return nativeEncrypt(message, password);
        }

        private native String nativeEncrypt(String message, String password);
    }

Even if the nativeEncrypt message is interacting with OpenSSL, etc. in a way that does not correlate directly to a single C/C++ call.

- Reece
Reply all
Reply to author
Forward
0 new messages