I an developing a Visual C++ 32-bit application in Visual Studio 2012.
One module in my application is developed in JAVA and is available as a jar library only. I need to call functions from the jar file in my Visual C++ Console application. These functions are implemented in JAVA. My Visual C++ application will call these functions. These functions will return some value (message) back to the Visual C++ application.
Most of the links/tutorials talk using JNI for accessing C/C++ code in a JAVA Application. How can I access functions/methods from the jar file to my Visual C++ console application?
any help/idea is appreciated
JNI is my answer too. Using JNI you can create a Java Virtual machine in your c++ program and invoke methods on Java classes.
Please check the following link for a small sample. I hope you can build upon this to meet your requirement.
http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/invocation.html#wp9502
Related
Could someone explain how the Java JNI and the Android NDK differ, how they are the same and how they fit together? I haven't found anything that gives a good explanation of the differences between the two and I'm a little confused.
Thanks!
JNI is just the way that Java handles calling into native/C++ code, and calling back into Java from there. It has nothing to say about Android - it is a Java language feature.
The Android NDK is a way to write Android applications using code called by JNI. It's specific to Android and gives native code access to Android APIs at that level.
Android NDK(Native Development Kit) is basically a toolchain to reuse code written in C/C++(native code). It compiles the native code into native library. NDK is similar to a Android SDK, with primary difference of using SDK only for java codes. NDK is used in application developed for multiple platforms like iOS, Windows. Apps like Whatsapp, Instagram were developed using NDK.
Java code use JNI(Java Native Interface)to call functions from native library, like accessing the objects, methods, etc. Also the native code can access the java environment.
I managed to create a java package from a Matlab function (for image processing) using deploytool. I tested it in Eclipse and it runs perfectly. The problem is that I want to use this Matlab function for an Android Studio project and I can´t find any way to make it work.
As you may know, when you use Matlab´s deploytool for java packages it generates three folders: "for_redistribution" which contains an .exe file (MyAppInstaller_web.exe), "for_redistribution_files_only" that contains the .jar and documentation, and "for_testing" which contains pretty much the same, the .jar file, documentation and java classes
My question is: is it possible to use this in an Android App? And if so, how? And are there any other options (other than using openCV instead of a Matlab function) to make it work?
Thank you in advance
Java components that are generated from MATLAB code using deploytool (or using other functionality from MATLAB deployment products such as MATLAB Compiler, MATLAB Builder etc.) depend on the MATLAB Compiler Runtime (MCR).
The MCR has much too large a footprint to run on an Android device, and it's really not possible to deploy MATLAB Code to Android in this way.
You have two main options:
Use the add-on product MATLAB Coder to convert your MATLAB code to C. This C code does not (unlike the deployment products) depend on the MCR, and be compiled and incorporated into your Android app like other C code.
Deploy your java component as a web service, and have your Android app communicate with it remotely.
I need to call a relatively simple piece of python code (no dependencies) from my java-project for android. I have heard that it is possible to use python via Kivy. Would that be possible?
Kivy cannot be easily integrated in an existing Java app, Kivy (the android part) have already a integrated Java application. Python is the main part, and you can execute Java code from Python using Pyjnius. Or write direct Java code.
You want the inverse, which is not something we are targeting.
I suggest you to check android-python27 project instead.
I am trying to call up a user defined matlab function(.m file) from java android application which is developed in Eclipse using matlabcontrol.jar.
Actually, It works well when I use it in the java project.
But I wonder is it possible to use it when I develop android application.
The problem is When I use matlabcontrol.jar for java project, it pops up and runs matlab application(like R2009b matlab) automatically, even though I don't want to use it. then run and print result on the matlab console also.
Then, I think, if someone who didn't install matlab application in their computer or smartphone can't use application which is included matlab code.
So, I just want to run matlab code on java program(for android), not using matlab application. Give me option or alternative way to work out please?
Please help.
Thanks.
matlabcontrol just gives you a way to call a running copy of MATLAB from Java. If you have some MATLAB code that you want to run on an Android device, this is not going to work for you, as there is no version of MATLAB that will run on Android.
If you have MATLAB code that you'd like to run as part of an Android application, you have two real choices:
i) Use MATLAB Coder to convert the MATLAB algorithm to C code, that can be compiled, called from Java, and included in your app to run on the device. You'll need to ensure that your MATLAB algorithm falls within the subset of the MATLAB language that is supported by MATLAB Coder, but that usually isn't a big issue. MathWorks have a recorded webinar with a worked example of how to do this (it's Objective C on iPhone rather than Java on Android, but the principles are the same). It's called something like "MATLAB to iPhone made easy", if you want to look it up. Here's the link to it.
ii) Use either MATLAB Builder NE for .NET, or MATLAB Builder JA for Java to deploy your MATLAB algorithm as a web service, and have your Android application call that web service.
PS MATLAB Mobile is not a relevant option here - it is a tool for connecting to a MATLAB session on your machine or in the cloud, and interactively running MATLAB code. It does not give you a way of running MATLAB code on the device itself.
I read about AIDE and it's ability to develop and compile Java directly on Android but what about C support? I read that the PC Android NDK adds full C support only if you wrap it in a dll but a newer version would allow apps to be developed directly in C without any wrapper.
Is there anything like that for Android as well? I know of c4droid and it's gcc plugin but I assume that is for developing for x86 and not ARM.
With Android Native Development Kit (NDK) you can implement parts of your application using C. http://developer.android.com/sdk/ndk/index.html. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
Well, you could install linux (Ubuntu, in this case) on your phone and put your development environment in there, I guess.
Check https://play.google.com/store/apps/details?id=com.zpwebsites.ubuntuinstall
you can use NDK with JNI (Java Native Interface)
the following example is simple and could help you to understand quickly the NDK and JNI:
Using NDK to Call C code from Android Apps
The following document contains more examples and details concerning the use of NDK and JNI
JNI Examples for Android
Your C code will be build as dynamic linux library (.so) and will be loaded when your application start. The use of JNI will allow your JAVA code to use the C functions from the library. The use of such solution (calling C function from JAVA) is very useful especially if you have complicated and long duration algorithms. executing such algoritms in C take much less time comparing to Java.