How to use googletest for testing C++ code that calls into java on android?

I am working on a rather complicated C++ library that I plan to test properly using googletest for Android NDK.

So far I follow the google test example and structure the project like this:

  • Color of TextView shows as white on a real device with ConstraintLayout
  • Java Threading Error IllegalThreadState thread already started
  • android how to convert json array to string array
  • Center elemets of HorizontalScrollView when not enough to make it scroll
  • Run time gradle exception
  • BigDecimal to the power of BigDecimal on Java/Android

      LOCAL_PATH := $(call my-dir)
      include $(CLEAR_VARS)
      LOCAL_MODULE := foo
      LOCAL_SRC_FILES := foo.cpp
      include $(BUILD_SHARED_LIBRARY)
      include $(CLEAR_VARS)
      LOCAL_MODULE := foo_unittest
      LOCAL_SRC_FILES := foo_unittest.cpp
      LOCAL_STATIC_LIBRARIES := googletest_main
      include $(BUILD_EXECUTABLE)
      $(call import-module,third_party/googletest)

    I build and call the test using a script file:

    adb push libs/armeabi/ //data/local/tmp/
    adb push libs/armeabi/ //data/local/tmp/
    adb push libs/armeabi/foo_unittest //data/local/tmp/
    adb shell chmod 775 //data/local/tmp/foo_unittest
    adb shell "LD_LIBRARY_PATH=//data/local/tmp //data/local/tmp/foo_unittest"

    This works fine with any pure C++ code that doesn’t have many references but a lot of my code actually relies on java/jni calls. How can I run googletest with a complete apk file that comes not just with C++ code but also java and resources?

    Related posts:

    SwiperefreshLayout in Android
    Native prebuilt shared library in Android Studio with experimental Gradle plugin
    VideoView is not properly rendered after Dialog's keyboard disappeared
    getActionBar() returns null in PreferenceActivity (AppCompat-v7 21)
    How to detect input data through the audio jack?
    How to embed an Http server (like i-Jetty, Paw, etc) in android application
  • Getting Image from drawable and adding to PDF using iText
  • What Android devices are small screen size and high density?
  • How to check if Async Task is already running
  • MultiDexApplication not recognized
  • How do I clear up this ambiguous call to Arrays.copyof()?
  • layout_weight is not work in scrollview
  • One Solution collect form web for “How to use googletest for testing C++ code that calls into java on android?”

    Inside your test program, you will have a main() function which looks something like this:

    int main(int argc, char **argv) {
      ::testing::InitGoogleTest(&argc, argv);
      return RUN_ALL_TESTS();

    This allows you to invoke the test program like any other: just type the name of the executable in a shell.

    More info on:

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.