Exporting C++ project to Android - JNI/JavaCPP/Visualgdb - java

I am facing a critical issue trying to export my opencv project to android.
Since all of my code is in opencv (C++ version) under visual studio 2013, i started off looking into JNI. I ended up realizing that JNI works good when we export C stuff as name mangling is turned off. Does this affect my C++ code? I think it should as name mangling has to be there for C++ class functions.
Then I found out about JavaCPP. This seemed more promising but the extra overhead its Pointer logic seems strange to get my head around and extra build steps to create .so files.
And finally, read about Visualgdb. Though seems to be in trial, but with my liking for Visual studio, looks reasonable.
Can someone guide my which way I have to follow to translate/bind my code in android so that I can export my c++ classes? Does plain JNI have a real issue with C++ code and no problems with C? OR do I go for JavaCPP or visualgdb?
You valuable comments will be highly appreciated.
Thanks

AFAIK you can use JNI on your c++ code, I'm using it. But you should only use JNI if you want to write all your code in c++ and want java to use that exact c++ code in java side. And for that you should export all functions in your public API. And I must say, passing through custom objects such as Mat, Rect, etc is not a very easy problem, also debugging is not also straight forward. I suggest you to use OpenCV Java and port your code to Java.
Good luck!

Related

c# classLibrary.dll to be used in android studio/ android app

This is kind of a general question but anyway:
In c# I have made a class library(api) which works on windows systems. I am now looking into making an api with the same functionalityies for android. One of the functionalityes (streming data from custom bluetuth device) needs to be written in java. So (in android studio) I have written a java class to do that, compiled a .jar and tested it in Unity as a plugin. But to avoid translating a ton of c# code into java I am now wondering if it is possible to somehow import a c# api into android studio and just call it's methods from java classes( as you can do in Unity's.Monobehaviour (AndroidJavaClass.Call("functionName", object[]parameters)) or maybe as you can do wit .jar-s code in VisualStudio(IVKM.Net. IVKM.NET))? To put it as plainly as possible: I would like to convert a api.dll to api.jar.
If you can suggest another alternative solution, please do so.
Thanks.
Havent tried, but will try hinting towards C++ support in Android with Native development Kit by converting C# to C++ code, as in .net all of your code is CLI code anyways, so it should be convertible to some barely readable C++ surogate code which should compile just fine.
https://www.quora.com/Can-we-use-C++-and-Java-together-in-Android-Studio
Hope this helps!

Combine C-Code(32-bit) with Java

I have method/function to get the drive info using Visual C++ of Microsoft Visual Studio. The method only return the type of drive. But it is become difficult when I'm trying to get more information about the drive. This difficulty gets resolved by Java's existing package. Furthermore, few codes are also there which is easy to handle with C platform. So, I'm thinking, if there is any efficient process which can include a native C code with in Java so that the functionality of both the language can be used in meaningful way.
Can anyone help me in this regard?
Java Native Access (JNA) is a way you can access C libraries from Java code. Its advantage over Java Native Interface (JNI) is that the library glue code is written in Java, not C, making it more maintainable.
(I've used JNA a lot at work. If I get permission from work, I may be able to post the JNA stuff I've written, as examples for you to work with.)

making matlab code android compatible

I have an image processing code in matlab containing its inbuilt functions like graythresh(), bwareaopen(),etc. I need to make that code processable on a smartphone(preferably with android os).The code also contains methods of image segmentation like Otsu. It would be of great help if you could suggest me the best and easy way to do that. I know elementary Java, but I do not know much about android programming.
You have several options:
The best things to do is to port your code in java or port your code to use openCV.
Use Matlab coder to generate C code. This C code doesn't require the MCR, and could be compiled to run directly on Android
You could try using the very handy Octave for Android:
https://play.google.com/store/apps/details?id=com.octave&hl=en
It may not have all of the functions you need (as it is Octave, and a port) but it will be a good start.

Android and Java's JNI

I'm starting to learn java's JNI to use with an android device.
As I read somewhere, you must have some "glue" for the C++ part in order to be loaded through JNI.
My question is: Is it posible to have a run() function in C with the glue for JNI having that running the real app and having java only for the entry point?
Because I don't know if when invoking that run() function through JNI it may cause problems if that function calls another functions and so on.
Thanks for the tip!
EDIT: I want to code in C++ using ndk and trying to avoid coding in java. thus, I wanted to know if a) if I can compile and run in native with ndk or b) if i can use java only to invoke my app, example: calling woth jni something like app->run() and let it do all stuff instead of java. then, java will act only as an entry point.
If you want to develop for Android in C/C++ (no Java) AND you target newer devices (Gingerbread, android-9 app platform onwards) consider using NativeActivity.
See http://developer.android.com/reference/android/app/NativeActivity.html and folder inside NDK package $NDK/docs/NATIVE-ACTIVITY.HTML together with the sample code $NDK/samples/native-activity.
Good luck!
I made a step-by-step howto in the following post: How to create dll using android You can read it and put questions if you don't understand something.

What can I access in Androids Native libraries? And How?

I am completely new to the NDK.
I have done a couple of the tutorials including the hello from jni one
and another one that calculates the sum of two numbers.
They involved using cygwin and the ndk to create the library so file
and I have a bit of a grasp on how to insert my own libraries into the
libraries layer of Android.
I have now been asked to access the native libraries on Android and
see what I can use them for.
My question is can I do this?
The STABLE-APIS.txt document is a bit vague and mentions the following
as Stable C++ API's in Android 1.5
cstddef
new
utility
stl_pair.h
Does that mean I can access them?
If so then how do I go about it? I dont think that following the
tutorials I have already done would be any help?
Any pointers on how to do this or links to tutorials etc.. would be
greatly appreciated
As others pointed out on the android-ndk group, you probably should just use the SDK. The NDK doesn't give you access to any features beyond those available with the SDK and it reduces the portability of your application. You should only consider it if you have legacy code written C or C++ (that doesn't use exceptions or RTTI). While some operations are much faster in native code, passing data between managed and native code is expensive and thus using the NDK only speeds up certain types of applications.

Categories