1. Trang chủ
  2. » Công Nghệ Thông Tin

android developer tools essentials

250 563 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 250
Dung lượng 19,36 MB

Nội dung

www.it-ebooks.info www.it-ebooks.info Mike Wolfson Android Developer Tools Essentials www.it-ebooks.info Android Developer Tools Essentials by Mike Wolfson Copyright © 2013 Mike Wolfson. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or corporate@oreilly.com. Editors: Andy Oram and Rachel Roumeliotis Production Editor: Rachel Steely Copyeditor: Gillian McGarvey Proofreader: Charles Roumeliotis Indexer: Ellen Troutman Cover Designer: Randy Comer Interior Designer: David Futato Illustrator: Rebecca Demarest August 2013: First Edition Revision History for the First Edition: 2013-08-13: First release See http://oreilly.com/catalog/errata.csp?isbn=9781449328214 for release details. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Android Developer Tools Essentials, the image of a cassowary, and related trade dress are trade‐ marks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trade‐ mark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-1-449-32821-4 [LSI] www.it-ebooks.info Table of Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix 1. Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Minimum Requirements 1 Installing Java 2 Installing the Android Software Development Kit 3 Installing the ADT Bundle 3 Developing Without Eclipse 5 Command-Line Usage 6 Using a Different IDE 6 Configuring a Device for Development 7 2. Essential Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 SDK Manager 11 SDK Components 11 Starting the SDK Manager 12 Viewing Installed and Available Components 13 ADT Preview Channel 15 Android Debug Bridge (ADB) 17 Starting ADB 17 Querying for Device Instances 18 Issuing Commands 19 The Shell Command 20 ADB Does a Lot More 22 Resetting the ADB Server 23 Additional Resources 24 3. Configuring Devices and Emulators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Using a Physical Device for Development 25 iii www.it-ebooks.info Capabilities and Limitations 25 Configuring a Physical Device for Development 26 Using an Emulator for Development 26 Supported Features 27 Android Virtual Devices 28 Creating AVDs 28 Emulator Options 32 Advanced Emulator Configuration 33 Using Hardware Acceleration 33 Disabling the Boot Animation 37 On Windows: Dedicating a Core to the Emulator 37 4. Using Devices and Emulators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Using the Emulator 39 Starting the Emulator 40 The Emulator Application 47 The Devices Tool 48 Keyboard Shortcuts 50 File Explorer 50 Developer Tools Application 52 5. Developing with Eclipse. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Anatomy of the Eclipse Workspace 55 Uncovering Additional Tools and Views 57 Quick Button 59 Code Templates 59 Properties Editors 65 XML Formatter 67 The Android Key 67 Quick Outline for XML 68 Other Essential Eclipse Shortcuts 69 Refactor Menu 70 6. Developing with Android Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Installing Android Studio 71 Bundled SDK 72 Default Project Location 74 Anatomy of the Android Studio IDE 74 Panels 74 Toolbars 75 Useful Actions in Android Studio 76 Navigation 76 iv | Table of Contents www.it-ebooks.info The New Structure of an Android Project 77 A Tour Around the New Structure 77 Running and Debugging an Android Project 78 Creating New Android Components 79 Layout Designer and Layout Preview 80 Layout Designer 80 Layout Preview 81 Generating an APK 82 Interacting with Maven and Gradle 83 Interacting with Maven 83 Interacting with Gradle 84 Version Control Integration 85 Migrating from Eclipse 86 Android Studio Tips and Tricks 86 Refactoring and Code Generation 87 Miscellaneous Shortcuts 87 7. Testing Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Logcat 89 Viewing the Logcat File 89 Anatomy of a Log Message 89 Filtering Based on Logging Level 91 Using Tags to Filter Output 92 Getting the Most Out of Logcat 92 Viewing Alternative Log Buffers 93 Predefined Output Formats 93 Logcat Viewer in Eclipse 93 Logcat Example 94 Debugging 98 Setting Your App to Debuggable 99 Setting a Debug Point 99 The Eclipse Debug Perspective 100 Debugging Example 101 Lint 107 Command-Line Usage 108 Running in Eclipse 110 8. Simulating Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Simulating Location and Routes 115 Simulating Telephony Operations 118 Changing Networking Parameters 121 Using a Device with Sensor Emulation 122 Table of Contents | v www.it-ebooks.info Advanced Sensor Testing 122 Supported Sensors 123 Simulating Sensor Events in Real Time 123 Recording Sensor Scenarios 124 Developer Options Menu 126 9. Build Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 Compiling Your Code 129 Packaging an APK for Release 130 Signing Your App 130 Building from the Command Line Using Ant 133 Setting Up Your Project 135 Building in Debug Mode 136 Building an App to Release to the Play Store 136 Additional Ant Commands 138 Advanced Packaging Steps 139 ProGuard 139 Zipalign 144 Gradle-Based Build Tools 144 Installing Gradle 144 Creating Multiple Build Variations 145 Build File 147 Build Tasks 148 Generating a Gradle Build from Eclipse 148 Using the Maven Tools 149 10. Monitoring System Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Memory Usage in Android 151 Dalvik Debug Monitor Server (DDMS) 152 Launching the DDMS Perspective 152 Analyzer Tool 154 Threads 155 Heap 156 Traceview 157 Memory Analyzer Tool (MAT) 159 Generating an HPROF File 160 HPROF File 160 Installing MAT into Eclipse 160 Launching MAT from Within Eclipse 160 Using MAT to Analyze HRPOF Files 161 The MAT Overview Screen 162 vi | Table of Contents www.it-ebooks.info Viewing a Report 162 11. Working with the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Android Layout Basic Concepts 165 Defining Layouts Using XML 165 Views and ViewGroups 167 Resources 170 Leveraging ADT to Build Great UIs 171 Editing XML Files Directly 172 Using Templates 172 Editing XML Directly 173 Working with Graphics 182 The Asset Tool 183 Using Nine-Patch Images 185 Asset Studio Website 187 12. Using the Graphical Editor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Generating Layouts Using the Graphical Layout Editor 189 Palette 191 Canvas 192 Layout Actions 194 Context-Sensitive Menu 194 Outline View 196 Properties Editor 196 Configuration Chooser 197 13. Optimizing the User Interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Introduction to UI Performance 201 How Android Draws Views, and How It Affects UI Performance 201 Hierarchy Viewer 203 Starting the Hierarchy Viewer 203 Loading the View Hierarchy into the Tools 203 Navigating the Tree Hierarchy 203 Gathering View Information 205 Gathering View Rendering Details 207 Example: Debugging a UI Using the Hierarchy Viewer 208 Fixing Problems Using Lint 218 Application Exerciser Monkey 219 Grooming the Monkey 220 Monkeyrunner 221 Using Python to Create the Script 221 Table of Contents | vii www.it-ebooks.info Thanks for Reading! 222 Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 viii | Table of Contents www.it-ebooks.info [...]... 11 www.it-ebooks.info SDK Tools These include the various utility tools you will use to develop apps These are es‐ sential tools required by all developers You can think of them as the core system tools of the platform These include android, ddms, apkbuilder, and emulator, among others You can find these in the android- sdk /tools directory Platform Tools These are additional tools that are developed... book, it’s likely that you already know a little about Android development and how challenging it can be Learning to effectively use the standard Android Developer Tools (ADT) can make the development process easier and improve the quality of your code, thereby producing a more refined and robust end product Requirements for Android Developer Tools Android is very different from other mobile platforms... following locations: • Windows: C: \android • Linux or Mac OS X: /usr/dev /android It is common and perfectly acceptable to put Android in your home directory For instance: 4 | Chapter 1: Getting Started www.it-ebooks.info • Windows: C:\Users\youruserid \android • Mac OS X: /Users/youruserid /android • Linux: /home/youruserid /android Unzip the downloaded artifact to the Android folder Use the appropriate... should see the android- sdk folder in the Android Home folder you created in the previous section On Windows, this is C: \android\ sdk, and on Mac OS X or Linux, it’s /usr/dev /android/ sdk Setting your PATH variable Next, you will need to append the location of the Android executables to your PATH environment variable This is not strictly required, but makes it much easier to use the Android tools from anywhere... care to ensure the tools run well everywhere If you do have a preference for other development tools, you most likely will be able to use them for your Android projects There are robust com‐ munities supporting various platforms, and in many cases, the alternate tools do things better than Eclipse At Google I/O 2013, the Android tools team announced support for a new IDE named Android Studio” (Chapter... site Installing the Android Software Development Kit The Android Software Development Kit (SDK) is the collection of libraries, tools, doc‐ umentation, and samples that are required to run and develop Android apps and to use the tools It is not a complete development environment, and contains only the base tools needed to download the rest of the necessary components Downloading tools and components... and test Android applications Configuring a Device for Development www.it-ebooks.info | 9 www.it-ebooks.info CHAPTER 2 Essential Tools This chapter describes the fundamental tools that you need in order to start developing Android applications In it, I will show you how to use the SDK Manager to download various development resources, and discuss using the command-line tools (in particular the Android. .. automatically stored in the ap‐ propriate folder in the location where you installed Android (see “Extracting the tools to Android Home” on page 4) The components are downloaded into the following subdirectories: 14 | Chapter 2: Essential Tools www.it-ebooks.info Platforms platforms /android- API_level Add-ons add-ons Samples samples /android- API_level Documentation docs (there is only one copy, because old docs... are: 1 Make sure your computer meets minimum requirements 2 Install the Java Development Kit (JDK) 3 Install the Android SDK 4 Install the Eclipse Integrated Development Environment (IDE) 5 Install the Android Developer Tools (ADT) plug-in for Eclipse Minimum Requirements To develop for Android, you’ll need a reasonably responsive computer You will likely be running a few memory-intensive processes... Java The Android development platform is built on the standard Java framework Android applications are built on top of the Java platform, so you will need to install it in order to do anything with Android Make sure you get the Java Developer Kit (JDK) as op‐ posed to the Java Runtime Environment (JRE) (which may already be installed on your system) The JDK has the compiler, debugger, and other tools . www.it-ebooks.info www.it-ebooks.info Mike Wolfson Android Developer Tools Essentials www.it-ebooks.info Android Developer Tools Essentials by Mike Wolfson Copyright © 2013 Mike Wolfson (JDK). 3. Install the Android SDK. 4. Install the Eclipse Integrated Development Environment (IDE). 5. Install the Android Developer Tools (ADT) plug-in for Eclipse. Minimum Requirements To develop for Android, . likely that you already know a little about Android development and how challenging it can be. Learning to effectively use the standard Android Developer Tools (ADT) can make the development process

Ngày đăng: 01/08/2014, 17:39

TỪ KHÓA LIÊN QUAN