Googletest for Android NDK

爱⌒轻易说出口 提交于 2019-12-03 10:47:45

You need to built Googletest for Android to be able to run it with your toolchain, as you working with cross-compilation.

Download source code of googletest

$ mkdir googletest
$ cd googletest
$ svn checkout http://googletest.googlecode.com/svn/trunk/ .

Copy jni directory to googletest directory

$ cd /path/to/this/git
$ cp -r jni googletest/

run ndk-build script

$ cd googletest/ $ ndk-build 

You can find libgtest.a in googletest/obj/local/armeabi/libgtest.a

Source: sfuku7 / googletest_android_ndk-build - github

GoogleTest is now distributed with the NDK (mainly because it's used by the NDK test suite itself).

It's very easy to use in your own projects, see $NDK/sources/third_party/googletest/README.NDK for usage examples.

jni/Android.mk:

  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_SHARED_LIBRARIES := foo
  LOCAL_STATIC_LIBRARIES := googletest_main
  include $(BUILD_EXECUTABLE)

  $(call import-module,third_party/googletest)

This gradle plugin https://github.com/fsbarata/ndktest-plugin will help you get the Googletest working. Still worth to look at the Googletest framework though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!