Android Native Development Kit Cookbook
Copyright 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: March 2013
Production Reference: 1140313
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-84969-150-5
www.packtpub.com
Cover Image by Artie Ng (<>
)
Credits
Author
Feipeng Liu
Reviewers
Roger Belk
Frank Grtzmacher
Sylvain Ratabouil
Acquisition Editor
Martin Bell
Commissioning Editor
Shreerang Deshpande
Lead Technical Editor
Mayur Hule
Technical Editors
Lubna Shaikh
Worrell Lewis
Project Coordinator
Leena Purkait
Proofreader
Aaron Nash
Indexer
Monica Ajmera Mehta
Graphics
Aditi Gajjar
Valentina D'silva
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade
About the Author
Feipeng Liu is a technology enthusiast who is focused on multimedia systems and applications. He started mobile applications development in 2008 on Windows Mobile. Since Feb 2010, he has been developing apps for Android with NDK. His Android apps have been used by many users. One of his apps, video converter Android , has reached one million downloads within 10 months. Feipeng received his B.ENG in Electrical and Electronic Engineering degree from Nanyang Technological University, and Master of Computing degree in the Department of Computer Science from National University of Singapore.
I would like to thank Shreerang Deshpande for offering me the opportunity to author this book and for helping me throughout the writing, and Leena Purkait for keeping track of its progress and coordination, Mayur Hule, Lubna Shaikh, and Worrell Lewis for editing the book drafts! I would like to express my gratitude to other Packt Publishing staff who helped with the book! My grateful thanks are also extended to Roger, Frank and Sylvain, who offered great suggestions during the review.
I also would like to thank Assoc. Prof. Wei Tsang Ooi in National University of Singapore, the supervisor of my master project. A lot of stuff in this book is based on the things I learnt during the project.
Last but not least, I would like to thank my parents Zhulan Shen and Yi Liu, and Ms. Yang Xiaoqing for the support and understanding during the writing of the book.
About the Reviewers
Roger Belk is a 45-year-old self-taught Android developer with 20 + apps in Googles Play Store under the developer name BigTexApps . He started out using Googles & MITs App Inventor and then after two years of learning to use AI, he taught himself to use Java to build Android apps. He has reviewed two other books, Google App Inventor , Ralph Roberts , Packt Publishing (ISBN 978-1-84969-212-0) and Android 3.0 Animation , Alex Shaw , Packt Publishing (ISBN 978-1-84951-528-3).
Frank Grtzmacher spent some years in the research of distributed electronic design tools and worked for several German blue chip companies such as Deutsche Post and AEG. He was involved in Android platform extensions for a mobile manufacturer. Therefore, on one hand he knows how to build large enterprise apps and on the other hand how to make Android system apps.
He is currently working for the IT daughter of the largest German Telco company.
In the past, he has reviewed Corba- and Java-related books for American and German publishers.
Sylvain Ratabouil is a confirmed IT consultant experienced with C++ and Java technologies. He worked in the space industry and got involved in aeronautic projects at Valtech, where he is now taking part in the digital revolution.
As a technology lover, he is passionate about mobile technologies and cannot live or sleep anymore without his Android smart phone.
www.PacktPub.com
Support files, eBooks, discount offers and more
You might want to visit www.PacktPub.com for support files and downloads related to your book.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at > for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
http://PacktLib.PacktPub.com
Do you need instant solutions to your IT questions? PacktLib is Packts online digital book library. Here, you can access, read and search across Packts entire library of books.
Why Subscribe?
- Fully searchable across every book published by Packt
- Copy and paste, print and bookmark content
- On demand and accessible via web browser
Free Access for Packt account holders
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.
Preface
Since its first release in 2008, Android has become the largest mobile platform in the world. The total number of apps in Google Play is expected to reach 1,000,000 in mid 2013. Most of the Android apps are written in Java with Android Software Development Kit (SDK). Many developers only write Android code in Java even though they are experienced with C/C++, without realizing what a powerful tool they are giving up.
Android Native Development Kit ( NDK ) was released in 2009 to help developers write and port native code. It offers a set of cross-compiling tools and a few libraries. Programming in NDK offers two main advantages. Firstly, you can optimize your apps in native code and boost performance. Secondly, you can reuse a large number of existing C/C++ code. Android Native Development Kit is a practical guide to help you write Android native code with NDK. We will start with the basics such as Java Native Interface ( JNI ), and build and debug a native app (chapter 1 to 3). We will then explore various libraries provided by NDK, including OpenGL ES, Native Application API, OpenSL ES, OpenMAX AL, and so on (Chapters 4 to 7). After that, we will discuss porting existing applications and libraries to Android with NDK (Chapters 8 and 9). Finally, we will demonstrate how to write multimedia apps and games with NDK (Bonus chapters 1 and 2).