Android unittest googletest - android

I use Android Studio to build simple application with c++ support. Now I want to write unittest for functions in my native lib. How can I include google test in my CMakeLists.txt to build and run my tests on Android device?
When I put
enable_testing()
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
add_executable(foo foo.cc)
target_link_libraries(foo ${GTEST_BOTH_LIBRARIES})
add_test(AllTestsInFoo foo)
in CMakeLists.txt I've go an error that GTest is not found.
I saw this and this questions. And the documentation, but they all are about .mk files not about CMakeLists.txt
How should I find googletest library on android device and link my test project with it?
Maybe i should write my own CMakeLists.txt for sourses located in
${ANDROID_NDK}/sources/third_party/googletest
to apply paches and build this library by myself?

Related

link dependent android ndk cmake project to main android ndk library project

I have 2 modules in this project: app and libdatacpp
libdatacpp is mainly a C++ project but uses some java code
app is mainly a java project, but uses some c++ code
When building the project, I get c++ linker errors for undefined functions from libdatacpp, because the app project doesn't link libDataCpp.o
In my cmake for app, I am linking against libDataCpp like this:
target_link_libraries(
native-lib
DataCpp)
I also link against the other project in the app module's build.gradle like this:
dependencies {
api project(':libdatacpp')
How can I get the app module to automatically link against my libdatacpp module?
If you intend to provide libdatacpp native library for other AndroidStudio projects through .aar, then you need to use prefab feature.
But if these native library is part of your own project, then I don't see the need to put it in the .aar, just put its stuff (sources and CMakeLists.txt) in a subfolder and add it to build by using add_subdirectory (datacpp) in your main CMake.

Android build c++ with dependency

I am working on an Android application with NDK. My c++ code has some dependencies from c++ open source libraries, so I can download the source code of the dependencies and package them in my app. I have created my CMakeList files, but I don't know how to include the external library.
I would like to build the dependency to be able to use it in my own project, so the flow would be as follows:
cd external/library/path
./configure
make
build my app and link the built dependency
Is this possible? If so, how can this be done? Sorry if this is a dumb question, I'm new on C++ and Cmake.
The way I solved this was by cross compiling the libraries and adding them as static libraries. You can cross compile using the clang binaries included in the ndk directory, using the one that targets your app min sdk.

How to include <glib.h> in android cmake project

I have created an android project on windows with ndk template. I want to include ndk-build project into android studio. This ndk-build project is working fine separately when I run ndk-build command.
My requirement is to convert and use it in android studio so that I can debug the code on android mobile. At this time I am just using share library (so file) and call the required function from adb shell.
I have copied all the source files of my separate ndk project into my android studio project and also added them into native-lib(created by default by android studio) library. But, I am getting an exception on including glib.h.
I am not sure actually how to resolve it.
Please suggest something.
Read this:https://developer.gimp.org/api/2.0/glib/glib-compiling.html
I usually use the following:[To complie]
gcc `pkg-config --cflags --libs glib-2.0 dbus-glib-1` progname.c
Hope this will help you.

Building capicxx-core-runtime for Android

We are trying to build capicxx-core-runtime for an ARM based platform running Android Pie. It's an open source IPC framework which is part of the GENIVI initiative by major automotive OEM's. Our AIM is to bring the IPC framework into our Android system.
The git repo is placed here https://github.com/GENIVI/capicxx-core-runtime.git
I am using the Android NDK version r17b and building using the following command to configure the cmake based build.
cmake -DCMAKE_TOOLCHAIN_FILE=/home/hp/downloads/android-ndk-r17b/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_NATIVE_API_LEVEL=27 ../
When I compile using 'make', I see the individual cpp files are compiled, but I am getting following errors during linking as shown in the link below.What is the configuration that I may be missing.
Linker error log
the capicxx-core-runtime is building a shared library, so you need to resolve all of it's internal symbols, including the c++ runtime.
To quickly test this: edit the capicxx-core-runtime CMakeLists.txt to link the c++_shared runtime, line 130:
target_link_libraries(CommonAPI PRIVATE ${DL_LIBRARY} ${DLT_LIBRARIES})
becomes
target_link_libraries(CommonAPI PRIVATE ${DL_LIBRARY} ${DLT_LIBRARIES} c++_shared)
and rerun your cmake command and make command.
It seems that capicxx-core-runtime can be buildable now for Android (both NDK and AOSP) out the box, please see corresponding pull requests: https://github.com/GENIVI/capicxx-core-runtime/pulls?q=author%3Ankh-lab+
Also here is simple example for AndroidStudio how it could be used with vSOME/IP transport: https://github.com/nkh-lab/ndk-capi-hello-world

Android NDK Debugging in an included library module

I am currently working on an Android app that is using a library that is using the NDK. The library and the app are maintained in separate repositories and are worked on as separate projects. The library is compiled on its own with Gradle and the ndk-build script. The aar output and .so files are then included in the main application.
My question is:
Is there a way to use ndk-gdb (or some alternative) to debug the library while running in the main app?
I have the source code for both projects, and if need be I could combine the projects for use with ndk-gdb, but this is very messy and requires a lot of additional work that would not be version controlled.

Categories

Resources