0

I need to develop an Android application and use in it an algorithm that is written in C. I found a lot of tutorials for running ONE C function from a java activity. But what I need is:

1) reading a string in a java activity and "sending" it to C/C++ (this part works).

2) starting a little C algo (it is written only in C. I mean from the moment that my algorithm starts I need to call other C functions that are in another C file). This algo creates a new string (precisely char*).

3) returning this new string to the java activity (this part works).

My big problem is the second point. Is there a special way to run an internal (with C functions calls) C code in Android? Special syntax?

I really hope someone here can help me.

Thank you in advance!

elze
  • 21
  • 1
  • https://stackoverflow.com/questions/5963266/call-c-function-from-java https://developer.android.com/studio/projects/add-native-code – Ray Tayek Feb 12 '19 at 19:38
  • Correct me if I'm wrong but it explains how to call c/c++ functions from Java. This part already works for me. My problem is to call C functions from others C functions in my app. For example, **inside** the first c function that prints "hello world", calling a second C function that prints "I'm fine". The whole algorithm I need is written in C. That's the reason. Anyway thanks for your answer – elze Feb 12 '19 at 22:26
  • you should be able to call the second c function from the first, just by including a declaration of the second c function in the first c function; https://stackoverflow.com/a/1410632/51292 like: extern int foo(int,char); – Ray Tayek Feb 13 '19 at 01:20
  • or maybe https://en.wikipedia.org/wiki/Java_Native_Access is what you are after. – Ray Tayek Feb 13 '19 at 01:25

1 Answers1

0

I am also new to Android development but maybe NDK is what you may need ?

willi b.
  • 1
  • 1
  • 1
  • Yes but running c from Java already works for me. That's not my problem. But thank you very much for your answer! – elze Feb 12 '19 at 22:20