Game Development Reference
In-Depth Information
How it works...
1.
First of all, we need to compile the native code. From the root of your
App2
project,
run the following command:
>ndk-build
2.
You should see the following output:
Compile++ arm: App2 <= Wrappers.cpp
SharedLibrary: libApp2.so
Install : libApp2.so => libs/armeabi-v7a/libApp2.so
3.
Now proceed to the
.apk
creation as in the previous recipe by running the following
command:
>ant debug
4.
Your
libApp2.so
native shared library will be packed into the
App2-debug.apk
package. Install and run it. It will output a
Hello World!
string into the device log.
There's more...
You can use the
adb
command to view the device log. A nice clean formatted log with
timestamps can be created using the following command:
>adb logcat -v time > 1.txt
The actual output from your device will look similar to the following command:
05-22 13:00:13.861 I/App2 ( 2310): Hello World!
Switching NDK toolchains
A toolchain is a set of tools that are used to build your project. A toolchain usually consists of a
compiler, an assembler, and a linker. Android NDK comes with different toolchains—GCC and
Clang—of different versions. It has a convenient and simple way to switch between them.
Getting ready
Look through the list of the available toolchains before proceeding. You can ind all the
available toolchains in the
$(NDK_ROOT)/toolchains/
folder.