Jni layer in Android - c++

I am confused with Jni layer, NDk LAYER and the C/C++ source code components LAYER in the Android system.
When writing feature on Android based platform, introducing new custom components:
Can I refer any component written in c/C++ as NDK component ?
What is jni, a file which helps loading c/C++ shared objects ?
I have refered below link: It talks about how to use it but not exactly clarifies the naming convention used in Android platform.
https://developer.android.com/training/articles/perf-jni.html
Can someone please clarify the distinction between JNI,NDK and c/c++components?

Here's a worlflow.
You have a class named NativeGoodAlgorithm written in C/C++.
Write a wrapper for NativeGoodAlgorithm called NativeGoodAlgorithmInterface(JNI).
Write a Android.mk that links your native code and wrapper to generate a library(.so).
In Android, you load the generated library and write a Java class named GoodAlgorithm.
Then you call GoodAlgorithm wherever you want.

The Java Native Interface (JNI) is a way for you to call C++ code from your Java code, and the other way around.
The Native Development Kit (NDK) uses JNI to let you call C++ from an Android application.
You will most likely have to do some work to call existing C/C++ from an Android app using NDK. For example, you'd have to make sure your C/C++ ran on the ARM CPU on the phones you want to support. You'll have to define the data structures you want to pass back and forth between the two layers. I'm not sure what the limitations on OS-level calls are for native code running in an app, but there probably are some.

Related

Can we use iOS framework like coremotion in c++ code

I need to build a library in C++, which have to get data from motion sensors. And then library in both android and iOS. It looks like it is possible to do it for android but I am struggling to find an answer for iOS.
You would be needing bridges for ios and android separately. Like for android you need different wrapper / JNI Bridge and different wrapper for ios Objective-c (.mm) files to used the sensor values. Ofcourse you can't share the sensor its different for each platform.
You can check this open source repository to get an idea how the wrappers around C++ and obj-c / Swift can be used.
https://github.com/foundry/OpenCVSwiftStitch
You can use C++ with iOS. The most typical way to do this is through hybrid "Objective-C++" files (.mm), which can compile C++ functionality in an Objective-C wrapper, but you can also use straight C/C++ source and C/C++ libraries. If you want your iOS app to be written in Swift (recommended), it can still use such code - I recommend wrapping the C++ in Objective-C(++) and calling the Objective-C wrappers from Swift with a bridging header.

How to differentiate between system calls and normal function calls

I am working on project which is trying to migrate some legacy application running on QNX neutrino operating system to other open source RTOS based on linux.
I have listed all the third party library and device drivers which must be ported and now analyzing design and source code which depends on some special QNX features like QNX IPC MsgSend, MsgReply, MsgSendPulse etc.
I want to know is there any tools which will help me to make a list of all QNX related system calls or functions which is getting used in code from normal user defined functions or functions provided by third party library and C++ library. Since code is written by other organisations we don't know much details about code except how to compiler and how to run it.
Thanks
Please refer link: https://sourceforge.net/projects/simpl/
You don't have direct API calls in linux which are equivalent to MsgSend, MsgReply etc.. but you can achieve it through using existing pipes/POSIX MQs (or) You can install above tgz package (Which is available in https://sourceforge.net/projects/simpl/).

JNI use in UMDF driver

I have a umdf driver and I would like to call some functions in .jar files to establish a connection between my driver (PCSC Reader) and an eclipse plugin (JCOP).
I called some java functions (from .jar) in a c++ main using JNI but can we write JNI code in a UMDF driver ?
If yes, I would appreciate some guidelines or point of views about how to approach the subject ...
There aren't much info about the subject when you google it so any info is much appreciated !
Thank you.
I don't have any UMDF driver experience, however, after reading the over view I don't see any reason why JNI would not be able to communicate directly with the Reflector. I don't think it will be able to communicate with the device stack or manager. So, if I understand this correctly, you should probably have some driver you load independently of JNI and then use JNI to talk to the driver via the Reflector.
On a more general note, I would recommend keeping your JNI code as simple as possible. My JNI code usually only functions as a Java <=> Native translation layer. All of the complexity and processing is done in a backing library that can be run independently of Java. By doing that, you can debug your native code with gdb or visual studio without having to jump around an already running JVM. You can choose to either ship the stand alone library as a native dependency and add it the the systems library load path or you can simply link it to the JNI library statically. I have had very good results using LTO and static linking in that exact scenario.

Sharing code between a dot42 project and a mono desktop project

The idea is to share code between a desktop app using Mono and a dot42 app. So my question is: Is there any way to import a Portable Class Library or even a common library in a dot42 ? If not, is there any way to share code at all between them ?
Thanks.
A dot42 project is either a Visual Studio or SharpDevelop project. There is nothing preventing you to add a class library project to your solution consisting of the same C# source code that is used in your Mono project.
The .NET types are implemented on top of the Android API. For example, the .NET Dictionary class is implemented as a wrapper of java.util.Map and System.String as a wrapper of java.lang.String. In other words, we take the API from .NET but the implementation from Java. This is in contrast to Mono.
When you refer to .NET types and compile your dot42 project to an APK, the .NET types compile to a minimum amount of wrapper DEX code that invokes the Android framework. It therefore does not require an extra runtime and makes the APKs really small.
Here is the API reference of all .NET types that are currently supported (work in progress):
http://docs.dot42.com/Reference/NS.System
We are working on adding support for Portable Class Libraries.
Disclosure: I work at dot42

What API/SDK to use for this Windows Application?

I'm going to create a utility with GUI that will run on Windows operating systems.
It should require minimum (or zero!) amount of additional libraries, files or DLLs to run because it will be executed from an installer. Because of this, i don't want to use .NET for it will require user to install .NET Framework. I know today, most of Windows installed system come with .NET Framework but in my case i cannot be sure.
The utility will...
send some data to a web site and
parse the returning data,
collect some hardware info, like MAC address,
CPU type and make, hard-disk serial
number
I suppose native Win32 API could be used for all of those above, but instead of hassling with Win32, i'd prefer using a more developer friendly API, or SDK.
Thanks in advance.
Win32 API is the only way, and of course there are standard API - for sending data over the internet, you could use WinInet.lib/dll, to obtain information about the MAC, you could use the GetAdaptersInfo by using Iphlpapi.lib/dll,(here's a link on how to use it) for the Hard disk serial number you could use GetVolumeInformation by using kernel32.lib/dll. For the CPU Id, you might look into GetSystemInfomation
Edit: There's a C++ code, but you can easily derive a wrapper from this site Unfortunately, with WinAPI is not easy, no such thing as RAD with WinAPI but what you gain out of it is lightweight code instead of relying on SDK's, frameworks and dragging buggy dll's around with your application.
Hope this helps,
Best regards,
Tom.
You can statically link most C++ GUI libraries - even MFC. Personally, I recommend WTL, wihich is very light and header-only.
If what you want is minimum dependency with external files or DLLs you could statically compile all the required DLLs with the tool exe. Then you could use something like Visual C++ to develop such tool.
WTL is perfect for this sort of application and I am surprised more people aren't recommending it. You can also statically link with the CRT and hey presto - no dependencies and a very small EXE.
Delphi (now by Embarcadero) would do the job, creating a .exe file with no dependencies, and it is much easier to work with than the raw Win32 API.
If you don't like Object Pascal, you could try C++ Builder instead.
For the GUI you can either build your application with MFC (statically linked) or use a HTML based dialog that you can interact with using COM. (It is even possible to interact with javascript present in the page displayed by the dialog).
For the specific requirement that you do have, I feel Win32 API is the only way out.
Use MFC and statically link to it. No runtime dependancies need to be installed.