Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Android NDK Beginner`s Guide - Second Edition

You're reading from   Android NDK Beginner`s Guide - Second Edition Discover the native side of Android and inject the power of C/C++ in your applications

Arrow left icon
Product type Paperback
Published in Apr 2015
Publisher Packt
ISBN-13 9781783989645
Length 494 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sylvain Ratabouil Sylvain Ratabouil
Author Profile Icon Sylvain Ratabouil
Sylvain Ratabouil
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Setting Up Your Environment FREE CHAPTER 2. Starting a Native Android Project 3. Interfacing Java and C/C++ with JNI 4. Calling Java Back from Native Code 5. Writing a Fully Native Application 6. Rendering Graphics with OpenGL ES 7. Playing Sound with OpenSL ES 8. Handling Input Devices and Sensors 9. Porting Existing Libraries to Android 10. Intensive Computing with RenderScript 11. Afterword Index

Time for action – creating an Android virtual device

The Android SDK provides everything we need to easily create a new emulator Android Virtual Device (AVD):

  1. Open Android SDK Manager from a terminal by running the following command:
    android
    
  2. Go to Tools | Manage AVDs.... Alternatively, click on the dedicated Android Virtual Device Manager button in the main toolbar of Eclipse.

    Then, click on the New button to create a new Android emulator instance. Fill the form with the following information and click on OK:

    Time for action – creating an Android virtual device
  3. The newly created virtual device now appears in the Android Virtual Device Manager list. Select it and click on Start....

    Note

    If you get an error related to libGL on Linux, open a command prompt and run the following command to install the Mesa graphics library: sudo apt-get install libgl1-mesa-dev.

  4. The Launch Options window appears. Tweak the display size depending on your screen size if needed and then click on Launch. The emulator starts up and after some time, your virtual device is loaded:
    Time for action – creating an Android virtual device
  5. By default, the emulator SD card is read only. Although this is optional, you can set it in write mode by issuing the following command from a prompt:
    adb shell
    su
    mount -o rw,remount rootfs /
    chmod 777 /mnt/sdcard
    exit
    

What just happened?

Android emulators can be easily managed through the Android Virtual Device manager. We are now able to test the applications we will develop in a representative environment. Even better, we can now test them in several conditions and resolutions without requiring a costly device. However, if emulators are useful development tools, take into account that emulation is not always perfectly representative and lacks some features, especially hardware sensors, which can be partially emulated.

Android Virtual Device manager is not the only place where we can manage emulators. We can also use the command-line tool emulator provided with the Android SDK. For example, to launch the Nexus4 emulator created earlier directly from a terminal prompt, enter the following:

emulator -avd Nexus4

While creating the Nexus4 AVD, acute readers might have been surprised to see we set CPU/ABI to Intel Atom (x86), whereas most Android devices run on ARM processors. Indeed, since Windows, OS X, and Linux all run on x86, only x86 Android emulator images can benefit from hardware and GPU acceleration. On the other hand, ARM ABI can run rather slow without it, but it may be more representative of the devices your application may run on.

Tip

To benefit from full hardware acceleration with an X86 AVD, you will need to install the Intel Hardware Accelerated Execution Manager (HAXM) on your Windows or Mac OS X system. On Linux, you can install KVM instead. These programs can work only if your CPU benefits from a Virtualization Technology (which is the case most of the time nowadays).

Acuter readers may be even more surprised that we have not selected the latest Android platform. The reason is simply that x86 images are not available for all Android platforms.

Note

The Snapshot option allows saving the emulator state before closing it. Sadly, this open is incompatible with GPU acceleration. You have to select either one.

As a final note, know that customizing additional options, such as the presence of a GPS, camera, and so on, is also possible when creating an AVD to test an application in limited hardware conditions. The screen orientation can be switched with Ctrl + F11 and Ctrl + F12 shortcuts. For more information on how to use and configure the emulator, check out the Android website at http://developer.android.com/tools/devices/emulator.html.

Developing with an Android device

Although emulators can be of help, they are obviously nothing compared to a real device. So, take your Android device in hand, switch it on and let's try to connect it to our development platform. Any of the following steps may change depending on your manufacturer and phone language. So, please refer to your device documentation for specific instructions.

You have been reading a chapter from
Android NDK Beginner`s Guide - Second Edition
Published in: Apr 2015
Publisher: Packt
ISBN-13: 9781783989645
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image