We have Objective C and Andoid Java applications and would like to create a component using C# and Xamarin that would interact.
Is there a way these technologies can communicate with each other (Objective C <-> Xamarin and Android Java <-> Xamarin).
Not sure how you do this but searching here it may be possible to create a static library in Objective C/Java that can be called from Xamarin.
From there I understand that you can start the Objective C/Java app from the Xamarin Main method and afterwards can call other static library methods.
Ideally we would like to call from the Objective C/Java app to Xamarin.
According to Miguel in this post it is possible but are there any examples anywhere.
Hope the explanation makes sense.
Thanks
From the wording of your question, this is not possible.
Xamarin does offer the ability to create 'bindings' between C# and Objective C/Java static libraries and has a section on the Developer documentation on doing so (Objective C Bindings or Java Wrappers).
The key part is that this is for static libraries and not for general application functionality i.e. user interactions.
You will need to weigh up the benefit between migrating the disparate projects to a shared Xamarin solution whereby you will enjoy the code sharing (especially with the Xamarin Forms offering) or simply writing the functionality into separate libraries for the different platforms.
Good luck
Related
I have a source code library from Renesas for their Co2 sensor. The source code library is completely written in C language and a static library (with .a extension) of it is given for the Co2 sensor which was helpful for me to use it in any microcontroller that uses C/C++ language. Even there are a lot of examples of it.
So, I have a microcontroller called DPM5050 which runs in Java programming language. Therefore, I came to know, that it is possible to use the native code in JAVA using JNI (Java Native Interface). I also came to know that to use native source code in Java, I need a dynamic link library. But I only have a static library which is provided by the Renesas.
My question is how can I do that using a static library that was given by Renesas?
Can I able to change the static library to the dynamic link library by myself without contacting Renesas?
And how to implement this in Java using JNI to use the native source code library provided by the Renesas?
Since I just came to know about this JNI technology to use native
source code in Java. So, I would also like to ask you to give me
suggestions or opinions on this topic. And I am also looking for some
good documentation with examples or tutorials or guidance to proceed
further.
Right now, I am reading Java APIs, Extensions and Libraries: With JavaFX, JDBC, jmod, jlink, Networking, and the Process API - by Kishori Sharan's book in Chapter 7 of this book they have some details about JNI.
I am looking forward to your responses. Thanks in advance.
Kind Regards,
Mustaq.
Good day.
It is possible to change for example native-plasma, which is a fully native Android app with only C++ and no Java or Kotlin, to be able to call Java?
I have used native-plasma as a base for an application, and now I need to call into third-party libraries, which they provided as Java, of course. But I cannot seem to find a way to now import their libraries and use their classes.
Thanks, help is appreciated.
I wrote a Java application for my company which works great. Now I am asked to interface my application with an API of a piece of hardware.
The API is implemented in a Windows dynamic link library (DLL). The samples that come with the API were written in Visual C++ 6.0
and Visual Basic 5.0 (seems very old).
There is no Java API available. I am wondering if there is a way to use the DLLs with my Java application I wrote? Should I rewrite the application
in VB.NET or... (Would these APIs even work with VB.NET)?
This is the piece of hardware whose API I need to use:
http://www.sealevel.com/store/8004e-pci-express-16-reed-relay-output-16-isolated-input-digital-interface-3-13v.html
Any suggestions or ideas are appreciated.
Thank you
The API should work with VB .NET.
If the API is Open-Source you could try to add JNI support, so that you can use it in Java.
Otherwise you could try to write the Application in C++. The difference to Java is not that big.
1) Use JNI, try using some java-c++ bridge which will make your life easy - see this https://code.google.com/p/javacpp/
2) Yes you can call native api's in vb.net
My company uses .NET for all development, and we integrate with an ERP made in .NET.
The ERP API is a collection of interops that we simply reference from our .NET project and we are ready to do whatever we want with it.
Recently we are thinking in JAVA development, but we have one concern, the integration with the .NET products we sell.
I've googled a bit and found JNA and JNI.
My questions are:
What is the best solution to "use" a .NET dll in JAVA?
Do they have limitations in functionality or performance?
Thank you.
I prefer JNA over JNI. JNI is more error prone. Boilerplate code you need to write makes it ugly. Also JNI is more C-ish than JNA. I haven't used JNI lately but JNA is hosted at Github, making it more reliable for me. I'm not sure whether JNI will be supported in future. You can see JNA#Github here.
In both you need to be get used to type mappings.
I've been playing around with the NDK recently, finding that many of the tutorials available online really don't help. I've been using this tutorial and I've got it running great.
However. Is this the correct use of the NDK? I mean if I have a game say with many classes all in C++ that I wish to port over to the android. Do I have to really manually change all my methods to the likes of:
JNIEXPORT jstring JNICALL Java_com_domain_ndk_NativeLib_hello
(JNIEnv * env, jobject obj) {
return (*env)->NewStringUTF(env, "Hello World!");
}
I can't see this being a very efficient way of porting my code over and I get the feeling I'm using the NDK wrong. I also have no idea how the NDK samples are supposed to work. Could anyone point me in the right direction?
Thanks
You do not need to change ANY of your existing methods to use the "auto-bound" JNI format. There aren't good examples in the Google NDK samples, but the Google SDK uses the other JNI binding method internally: Search for RegisterNatives() in the JNI docs. But even then, you really only need to create a wrapper for the few places that the Android SDK needs to talk to your library: user input/sensors in general, a draw callback, and possibly an "update" callback. Aside from that the rest of your app should remain untouched, except to get it to build.
To simplify things, I'd recommend you not use the native widgets; if you keep your game entirely in OpenGL, you can avoid going through Java to, e.g., draw textures to the screen, at least if you target 1.6 devices and newer, where the NDK has native bindings for OpenGL.
Contrary to some opinions (including those of Google), the NDK can and frequently is used for porting games to Android. I'm using it that way right now, in fact. You need to pass user events from Java to C++, and you need to have Java set up the basic GL context (there are no EGL bindings in the NDK), but you can do pretty much everything else in C++ with OpenGL and, once your basic Java messages are being passed to C++, you can (mostly) ignore Java. Thank goodness. :)
You'll still need to talk to Java for sound, and to get access to your files: Both still need to go through Java, and so you'll probably want to use "reverse JNI," where you call a Java function from C++. Also not hard, and there are examples all over the place.
I talk more about how to access your assets here: File Operations in Android NDK
Good luck.
I'd say your way isn't wrong, but be aware that passing data between Java and C/C++ code is a time consuming thing. Because of that I would suggest you write the most of the code actually in C/C++ and just call C/C++ functions from Java if it can't be avoided. For example you will need to pass data back for the GUI. Especially when you are programming a real time game I would avoid passing data between Java and C/C++ code too much. So just changing all the methods and then calling them in your Java code wouldn't be such a great idea.
Btw if you have to pass something back from C/C++ to Java, I would not pass it as a return value, but rather give the destination as a parameter in the function call.
The NDK is just a native C and C++ development environment for Android. Bionic (the Android version of libc) is more slightly more limited not by much. The only real complication is integrating you new component into the Android build tool chain. Android has a highly customized Makefile system. Downloading the source and looking at simple native components should give you an idea how to use it though.
Now if you want to integrate Java with C or C++ you will need to understand the Java Native Interface (JNI). You should be able to find good documentation of the JNI online.
The new release of the ndk (r5) now includes the capability to write apps entirely in native code.