How to properly implement a C++ project in Android?

Such a story, I have a project written in C++, which compiles and works.

I also have a project android.

In fact, there are only a few functions in the C++ project(a small project) and I need all of them in my android project.

Now the question is: how to do this integration correctly?

I think that you need to build this C++ project as a library, add it to android as a library and work with it.

Or can add this one the project as an additional module and through the NDK use it as something...

In general, I have never done this. Tell me who faced this how it should work? What is the sequence of adding a C++ project to a android project?

Edit

I realized that there is an option to add ndk to the project and following this tutorial

Https://developer.android.com/studio/projects/add-native-code

Add code "like" C++, because the code is in JNI it looks like this

extern "C" JNIEXPORT jstring JNICALL
Java_com_google_ar_core_examples_java_helloar_HelloArActivity_stringFromJNINew(
    JNIEnv *env,
    jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}

But this is not the C++ syntax ... At least as far as I know...

This means that I can't take a class that is written in C++ and copy it and use it, since the syntax in my C++ class and the syntax that offers Android Studio it is similar, but it is not the same. So I need to rewrite it...

I thought about the second option... After all, it should also be possible to open a project in VisualStudio and build something like .so and already add this library as something like this

Https://stackoverflow.com/questions/24357687/how-to-include-so-library-in-android-studio

Any suggestions are welcome

Author: Aleksey Timoshchenko, 2019-05-28

1 answers

See, here's the documentation from Google https://developer.android.com/studio/projects/add-native-code

 -3
Author: androidx, 2019-05-28 15:00:20