1

I am working on AOSP11/12. I am trying to understand which is the better way to understand commucate data b/w java to C++/C code.

I have created a test Android JNI application that communicates data between java and C++ code using this example(https://www.journaldev.com/28972/android-jni-application-ndk). But all java and C++ code in the same project.

In real-time, we have a C++ application it is already been developed by someone and I need to send/receive data from the java application in AOSP.

If you have any docs and examples please share them with me, It will be very helpful.

Thank you.

GNK
  • 1,036
  • 2
  • 10
  • 29
  • Q: What exactly do you mean by "send/receive data"? Are you creating a class object and populating it with data in C++, then passing that object to Java using JNI? Or can you use a communications channel (e.g. USB or BlueTooth)? Q: If you're already successfully using JNI to communicate between C++ and Java ... then what more do you need? Aren't you "done"? What's missing? – paulsm4 Jul 15 '22 at 05:33
  • What's the C++ code that's already developed? An application or library? You can use socket based communication to send/receive from C++ or you may want to create Java bindings for your C++ code. – kiner_shah Jul 15 '22 at 05:40
  • @paulsm4 I have a test application in that java and C++ code and all code together in the same android JNI project(app). For example, I need to do addition(+) operation that logic is written in C++ code. Need to send 2 (a,b) arguments from the Java(android app) it should reach C++ code. My Question is which location do I need to create C++ file in AOSP? how to pass two arguments (a,b)to C++ code ? how to receive the sum (a+b) value from c++ to java(android) app ?. – GNK Jul 15 '22 at 06:10
  • @kiner_shah it is just a sample addition(+) C++ application. I studied some articles data is not secure in socket communication – GNK Jul 15 '22 at 06:18
  • @GNK, you can use socket communication with SSL/TLS encryption. – kiner_shah Jul 15 '22 at 06:31
  • Thank you for your reply. Can you please share with me if you have any ref links? – GNK Jul 15 '22 at 08:37
  • OK: You're successfully using JNI. JNI is a two-way bridge: both java -> C/C++ and C/C++ ->Java. So it sounds like *ALL* you need to do is add a target for a JNI shared library that contains your C/C++ code to your AOSP build project. You *don't* need sockets. Look [here](https://stackoverflow.com/a/23318056/421195), [here](https://source.android.com/setup/develop/64-bit-builds) and/or study the build scripts for AOSP examples. – paulsm4 Jul 15 '22 at 15:39

0 Answers0