README.NDK
1This is a working copy of GoogleTest for the Android NDK.
2
3Project: https://code.google.com/p/googletest/
4Checkout: svn checkout http://googletest.googlecode.com/svn/trunk@653
5Patches: See patches.ndk/
6Licensing: 3-clause BSD. See googletest/LICENSE file.
7
8Note that the latest official release to date (1.6.0) doesn't work
9too well with Android. This is based on a more recent revision that
10includes many needed bugfixes.
11
12Usage:
13------
14
15This directory contains several module definitions that can be imported
16into your project by using the following at the end of your Android.mk:
17
18 $(call import-module,third_party/googletest)
19
20The GoogleTest modules are the following:
21
22 googletest_static:
23 GoogleTest as a static library.
24
25 googletest_shared:
26 GoogleTest as a shared library.
27
28 googletest_main:
29 A small helper static library that provides a main() implementation
30 that starts all the GoogleTest tests. This also links against
31 googletest_static.
32
33 googletest_main_shared:
34 Same as googletest_main, but links against googletest_shared.
35
36In your source code, use #include <gtest/gtest.h> as usual after ensuring
37your module depends on one of the modules above.
38
39Here's an fictuous example:
40
41jni/Android.mk:
42 LOCAL_PATH := $(call my-dir)
43
44 include $(CLEAR_VARS)
45 LOCAL_MODULE := foo
46 LOCAL_SRC_FILES := foo.cpp
47 include $(BUILD_SHARED_LIBRARY)
48
49 include $(CLEAR_VARS)
50 LOCAL_MODULE := foo_unittest
51 LOCAL_SRC_FILES := foo_unittest.cpp
52 LOCAL_SHARED_LIBRARIES := foo
53 LOCAL_STATIC_LIBRARIES := googletest_main
54 include $(BUILD_EXECUTABLE)
55
56 $(call import-module,third_party/googletest)
57
58jni/Application.mk:
59 APP_STL := gnustl_shared
60
61jni/foo.cpp:
62 int foo(int x, int y) {
63 return x + y;
64 }
65
66jni/foo.h:
67 extern int foo(int x, int y);
68
69jni/foo_unittest.cc:
70 #include <gtest/gtest.h>
71
72 #include "foo.h"
73
74 TEST(FooTest,ZeroZero) {
75 EXPECT_EQ(0, foo(0, 0));
76 }
77
78 TEST(FooTest,OneOne) {
79 EXPECT_EQ(2, foo(1, 1));
80 }
81
82Invoking 'ndk-build' will build both 'libfoo.so' and 'foo_unittest' under
83$PROJECT/libs/$ABI/. After this, to run the unit test program push it to
84the device and execute it with ADB, e.g.:
85
86 adb push libs/armeabi/libfoo.so /data/local/tmp/
87 adb push libs/armeabi/libgnustl_shared.so /data/local/tmp/
88 adb push libs/armeabi/foo_unittest /data/local/tmp/
89 adb shell chmod 775 /data/local/tmp/foo_unittest
90 adb shell "LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/foo_unittest"
91
92