README
1 Building native code applications and libraries
2
3 STEP 1
4 Building an application.
5 --------
6
7 0) set the environment variable PREBUILT to point to the Android prebuilt directory
8 export PREBUILT=<path_to_android_src>/prebuilt/<platform>
9
10 where you type in the actual path to the android source in place of <path_to_android_src>
11 and the platform you are using instead of <platform>: either linux-x86 or darwin-x86
12
13 1) Test the pndk install by building the hello world sample application:
14
15 cd <your_pndk_base>/samples/sample
16 make clean
17 make
18
19 The sample application uses hello.c to construct the hello binary, which you
20 can load and run on the ARM device. To achieve proper runtime behavior, verify
21 that:
22 * crtbegin_dynamic.o is the first linked object file
23 * crtend_android.o is last linked object.
24 Both are set by the config.mk file in pndk/config.
25
26 2) Test that this works correctly by attaching your ARM-based device to the USB
27 port and installing the application (hello) you just made by (in the commands
28 below # is the ARM device's shell prompt):
29
30 NOTE: need a development build so remount opens system permissions
31
32 adb remount
33 adb push hello system/app
34 adb shell
35 # cd system/app
36 # ./hello
37 Hello from the NDK; no user libraries.
38 # exit
39
40 3) You may also build the c++ binary hello_cpp.cpp into an application:
41
42 make -f Makefile.hello_cpp clean
43 make -f Makefile.hello_cpp hello_cpp
44
45 This uses the hello_cpp.cpp and hello_cpp.h files to construct the hello_cpp
46 binary application, which you can load and run on the ARM device. Note that
47 we do not provide for C++ exceptions thus you must use the -fno-exceptions flag
48 when compiling.
49
50 adb push hello_cpp system/app
51 adb shell
52 # cd system/app
53 # ./hello_cpp
54 C++ example printing message: Hello world!
55 # exit
56
57
58 STEP 2
59 Building and using a library
60 -------
61
62 Makefile.lib in pndk/sample shows how to make either a shared library or a
63 static library from the hellolibrary.c source. The example makes the libraries
64 libhello-shared.so and libhello-static.a .
65
66 Makefile.uselib then shows how to make an application that links against either
67 a shared or a static library. They examples shows how to build the two
68 applications use_hellolibrary-so and use-hellolibrary-a from the source
69 use_hellolibrary.c.
70
71 1) To make a shared library and an application that uses it:
72
73 make -f Makefile.lib clean
74 make -f Makefile.lib sharedlib
75 make -f Makefile.uselib clean
76 make -f Makefile.uselib use_hellolibrary-so
77
78 2) Copy the shared library libhello-shared.so to /system/lib (or the location
79 in which shared libraries are found by the kernel on your ARM-based device.)
80
81 adb push libhello-shared.so system/lib
82
83 You would not typically use the -shared or -static extensions in the filename,
84 but the distinction is important in the case where a static and shared library
85 are made in the same directory. Giving the files different names allows you to
86 override the link defaults that default to a static library of the same name.
87
88 3) The application, use_hellolibrary-so, can now be tested by loading and
89 running on the ARM device.
90
91 adb push use_hellolibrary-so /system/app
92 adb shell
93 # cd system/app
94 # ./use_hellolibrary-so
95 Library printing message: Hello from the NDK.
96 # exit
97
98 4) To make a static library:
99
100 make -f Makefile.lib clean
101 make -f Makefile.lib staticlib
102 make -f Makefile.uselib clean
103 make -f Makefile.uselib use_hellolibrary-a
104
105 5) Test the application use_hellolibrary-a by loading and running it on the ARM
106 device.
107
108 adb push use_hellolibrary-a system/app
109 adb shell
110 # cd system/app
111 # ./use_hellolibrary-a
112 Library printing message: Hello from the NDK.
113 # exit
114
115
116 SUMMARY:
117 ---------
118
119 To make everything execute the following:
120
121 make clean
122 make
123 make -f Makefile.lib clean
124 make -f Makefile.lib
125 make -f Makefile.uselib clean
126 make -f Makefile.uselib
127 make -f Makefile.hello_cpp clean
128 make -f Makefile.hello_cpp hello_cpp
129
130
131 You should have:
132 * The libraries libhello-static.a and libhello-shared.so built, the latter
133 ready for installation,
134 * The applications hello, use_hellolibrary-a, and use_hellolibrary-so
135 available for installation on the ARM device.
136