[ PUBLISHING Android NDK Beginner's Guide Discover the native side of Android and inject the power of C/C++ in your applications Sylvain Ratabouil BIRMINGHAMMUMBAI
installing installing preparing installing setting setting compiling Preface 1 Chapter 1: Setting Up your Environment 7 Getting started with Android development 7 Setting up Windows 8 preparing Windows for Android development 8 Installing Android development kits on Windows 12 Setting up Android SDK and NDK on Windows 13 Mac OS X 18 preparing Mac OS X for Android development 18 Installing Android development kits on Mac OS X 20 Android SDK and NDK on Mac OS X 20 Setting up Linux 22 Ubuntu Linux for Android development 22 Installing Android development kits on Linux 27 installing Android SDK and NDK on Ubuntu 27 Setting up the Eclipse development environment 29 Eclipse 29 Emulating Android 33 creating an Android virtual device 33 Developing with an Android device on Windows and Mac OS X 37 up your Android device on Windows and Mac OS X 37 Developing with an Android device on Linux 39 up your Android device on Ubuntu 39 Troubleshooting a development device 42 Summary 43 Chapter 2: Creating, Compiling, and Deploying Native Projects 4J> Compiling and deploying NDK sample applications 46 and deploying the hellojni sample 46
building running invoking creating Exploring Android SDK tools 51 Android debug bridge 51 Project configuration tool 54 Creating your first Android project using eclipse 56 initiating a Java project 56 Introducing Dalvik 59 Interfacing Java with C/C++ 60 calling C code from Java 60 More on Makefiles 65 Compiling native code from Eclipse 67 creating a hybrid Java/C/C++ project 67 Summary 72 Chapter 3: Interfacing Java and C/C++ with JNI 73 Working with Java primitives 74 a native key/value store 75 Referencing Java objects from native code 85 saving a reference to an object in the Store 85 Local and global JNI references 90 Throwing exceptions from native code 91 raising exceptions from the Store 92 JNI in C++ 96 Handling Java arrays 96 saving a reference to an object in the Store 97 Checking JNI exceptions 106 Summary 107 Chapter 4: Calling Java Back from Native Code 109 Synchronizing Java and native threads 110 a background thread 111 Attaching and detaching threads 120 More on Java and native code lifecycles 121 Calling Java back from native code 122 Java code from a native thread 122 More on callbacks 133 JNI method definitions 134 Processing bitmaps natively 135 decoding camera feed from native code 136 Summary 146 Chapter 5: Writing a Fullynative Application 147 Creating a native activity 148 a basic native activity 148
initializing creating handling handling Handling activity events 155 handling activity events 155 More on Native App Glue 166 Ul thread 167 Native thread 168 Android_app structure 170 Accessing window and time natively 171 displaying raw graphics and implementing a timer 172 More on time primitives 181 Summary 181 Chapter 6: Rendering Graphics with OpenGL ES Initializing OpenGL ES 184 lg3 OpenGL ES 184 Reading PNG textures with the asset manager 193 loading a texture in OpenGL ES 194 Drawing a sprite 208 drawing a Ship sprite 209 Rendering a tile map with vertex buffer objects 220 drawing a tilebased background 221 Summary 238 Chapter 7: Playing Sound with OpenSL ES 239 Initializing OpenSL ES 241 OpenSL ES engine and output 241 More on OpenSL ES philosophy 248 Playing music files 249 playing background music 249 Playing sounds 256 creating and playing a sound buffer queue 257 Event callback 266 Recording sounds 268 Summary 272 Chapter 8: Handling Input Devices and Sensors 273 Interacting with Android 274 touch events 276 Detecting keyboard, DPad, and Trackball events 288 keyboard, DPad, and trackball, natively 289 Probing device sensors 298 turning your device into a joypad 300 Summary 313
analysing Chapter 9: Porting Existing Libraries to Android 315 Developing with the Standard Template Library 316 embedding GNU STL in DroidBlaster 316 Static versus shared 326 STL performances 327 Compiling Boost on Android 328 embedding Boost in DroidBlaster 328 Porting thirdparty libraries to Android 338 compiling Box2D and Irrlicht with the NDK 339 GCC optimization levels 346 Mastering Makefiles 346 Makefile variables 347 Makefile Instructions 348 Summary 351 Chapter 10: Towards Professional Gaming 353 Simulating physics with Box2D 353 simulating physics with Box2D 354 More on collision detection 366 Collision modes 367 Collision filtering 368 More resources about Box2D 369 Running a 3D engine on Android 369 rendring 3D graphics with Irrlicht 370 More on Irrlicht scene management 381 Summary 382 Chapter 11: Debugging and Troubleshooting 383 Debugging with GDB 383 debugging DroidBlaster 384 Stack trace analysis 392 a crash dump 392 More on crash dumps 396 Performance analysis 397 running GProf 398 How it works 403 ARM, thumb, and NEON 403 Summary 405 Index 411