0

I am working on AOSP11/12(Android) and want to communicate data from java/Kotlin to C++ code or vice versa.

Is that better way to create new service and communicate data or need to create NDK application?

James Z
  • 12,209
  • 10
  • 24
  • 44
GNK
  • 1,036
  • 2
  • 10
  • 29

1 Answers1

0

Yes. You need to have a JNI interface to communicate with native solution written in C/C++. The other way is also possible. You can as well call methods of Java class from your C/C++ applications. Primitive data types are copied as it is from Java to native calling and arbitrary data types (objects) are passed as pass by reference mechanism.

This would be a good read to start with: https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html

While designing an application, please ensure the following: https://developer.android.com/training/articles/perf-jni

Hope this helps!

Vidz
  • 406
  • 2
  • 4
  • 16
  • Thanks for your reply. I have developed test JNI application its java and C++ code in same project. In real time java code in android app and C++ code in some where else in AOSP source code.How to communicate in that scenario. Can you please suggest me – GNK Jul 14 '22 at 16:26