
Expert Android Studio
Description
Alles über E-Books | Antworten auf Fragen rund um E-Books, Kopierschutz und Dateiformate finden Sie in unserem Info- & Hilfebereich.
More details
Other editions
Additional editions


Persons
Content
INTRODUCTION xxv
CHAPTER 1: GETTING STARTED 1
System Requirements for Windows, Mac OS X, and Linux 1
Installing Java 3
Installing Java for Windows OS 3
Installing Java for MacOS X 7
Installing Java for Linux 8
Installing Android Studio 9
Installing Android Studio for Microsoft Windows 10 10
Installing Android Studio for Mac OS X 12
Installing Android Studio for Linux 16
Launching Android Studio for the First Time 18
Welcome to Android Studio 18
Standalone SDK Installation 18
Summary 19
CHAPTER 2: ANDROID STUDIO BASICS 21
Creating a New Sample Project 22
Using Different SDKs 27
Android Project Structure 27
Building and Running a Project 33
Android Emulator 35
Installing HAXM 35
Creating a New Android Virtual Device 36
Using ADB 40
Migrating Projects from Eclipse 41
Summary 43
CHAPTER 3: ANDROID APPLICATION DEVELOPMENT WITH ANDROID STUDIO 45
Android Projects 46
Creating a New Android Project 46
Creating a Project with Multiple Target Devices 52
Launching Android Applications 54
Android Activities 56
The Intent Event Handler 58
Adding Template Activities to Android Projects 58
Adding a Blank Activity 59
Android Fragments 63
Adding a Tabbed Activity 64
Android Services 69
Adding a Service Template with Android Studio 69
Add Assets for Android Project 72
Adding Images Assets 73
Adding Sound Assets 74
Adding Video Assets 75
Adding XML Files to an Android Project 76
Android Manifest File 76
Android Modules 78
Summary 79
CHAPTER 4: ANDROID STUDIO IN DEPTH 81
Android Studio Menu Items 82
Android Studio 82
File 83
Edit 84
View 86
Navigate 86
Code 88
Analyze 88
Refactor 89
Build 89
Run 90
Tools 90
Version Control System 90
Window and Help Menu 90
Android Studio Shortcuts 91
Android Studio Tool Views 92
Messages 93
Android Studio Project Structure 94
Favorites 96
Android Monitor 96
Structure 97
Android Model 97
Gradle and Gradle Console 98
Run 98
Debug 99
Event Logs 100
Terminal 100
Android Studio Editor 100
Code Assist 101
Commenting Out Code Blocks 101
Moving Code Blocks 101
Navigating Inside the Editor 101
Refactoring 102
Android Studio Live Templates 102
Inserting a Live Template 103
Creating Live Templates 104
Code Refactoring in Android Studio 107
Creating a Signing Key for Android Applications in Android Studio 112
Building APKs in Android Studio 114
Summary 114
CHAPTER 5: LAYOUTS WITH ANDROID STUDIO 115
Layouts with Android Studio 116
Adding a New Layout File 116
Layout Design Structure in Android Studio 118
Layout Previews 120
Layout Rendering Options 120
Previewing Virtual Device Views 121
Previewing on Different Android SDK Versions 121
Selecting Themes 122
Designing Layouts with Android Studio 123
Managing Resources 127
Using Strings 127
Using Styles 127
Using Dimens 129
Using Colors 130
Using Drawables 130
Using Layout Tools 131
Translation 131
Activity Association 133
Asset Management 134
Summary 141
CHAPTER 6: ANDROID BUILD SYSTEM 143
Using Gradle 144
Anatomy of Gradle 144
Dependency Management with Gradle 147
External Dependencies 147
Local Dependencies 149
Legacy Maven Dependencies 149
Android Plugin for Gradle 150
Configuring Android Plugin for Gradle 150
Build Configuration 151
Build Tasks 151
Flavors 152
ProGuard 153
Automated Tests 155
Gradle Plugins 155
Writing Your Own Gradle Plugin 155
Extending Android Plugin for Gradle 156
Summary 157
CHAPTER 7: MULTI-MODULE PROJECTS 159
Adding Modules to Android Project 160
Phone & Tablet Module 161
Android Libraries 164
Working with Android Libraries 165
Java Libraries 167
Android Wear Module 169
Running and Debugging an Android Wear Module 170
Building APKs with Android Wear Support 173
Android TV Module 173
Glass Module 179
Android Auto Module 182
Google Cloud Module 184
Importing Modules 189
Importing a Gradle Project 189
Importing an Eclipse ADT Project 190
Importing a JAR/AAR Package 191
Removing Modules from a Project 192
Summary 193
CHAPTER 8: DEBUGGING AND TESTING 195
Debugging Android Code 196
Android Debug Bridge 196
Wireless Debugging 197
Start Debugging 198
Android Monitor 206
Using logcat 209
Using Memory Monitor 210
Using CPU Monitor 213
Using GPU Monitor 214
Using Network Monitor 215
Android Device Monitor 216
Android Virtual Device Extended Controls 222
Using Lint 225
Testing Android Code and Application UIs 226
Unit Tests 230
Integration Tests 232
UI Tests 235
Performance Testing 241
Performance Tests Task 242
Summary 244
CHAPTER 9: USING SOURCE CONTROL: GIT 245
Introduction to Git 246
Understanding Git 246
Installing Git 247
Using Git 248
Using the GitHub Client 249
Using Git in Android Studio 259
Git Flow 266
Summary 279
CHAPTER 10: CONTINUOUS INTEGRATION 281
What Is Continuous Integration? 281
Integrating Android Projects with a Continuous Integration Server 282
Installing Jenkins 283
Creating Build Jobs 291
Release Management 298
Summary 306
CHAPTER 11: USING ANDROID NDK WITH ANDROID STUDIO 309
Introduction to Android NDK 310
Android Studio NDK Integration 310
Android NDK Installation on Linux 311
Android NDK Installation on Windows 10 312
Android NDK Installation on Mac OS X 313
Android NDK with Android Studio Projects 315
Importing a Sample NDK Project 316
Migrating an Existing NDK Project 322
Building Android NDK Projects 326
Android NDK Projects Release and Deployment 328
Multi vs. Fat Android Application APKs 329
Summary 330
CHAPTER 12: WRITING YOUR OWN PLUGIN 331
IntelliJ Idea Plugin Architecture 332
Actions 332
Threading 341
File System 342
Projects and Components 342
Editors 351
Wizards 354
Packaging and Distribution 360
Summary 362
CHAPTER 13: THIRD-PARTY TOOLS 363
Android Studio Plugins 363
Intel's Android Software Tools 374
Intel System Studio 374
Intel C++ Compiler 377
Intel Integrated Performance Primitives (Intel IPP) 378
Intel Thread Building Blocks (Intel TBB) 379
Intel VTune Amplifier 379
Intel GPA 381
Intel INDE 382
Intel Tamper Protection Toolkit 382
Intel Multi-OS Engine 382
Intel Context Sensing SDK 384
Qualcomm Android Software Tools 387
Snapdragon LLVM Compiler for Android 388
Qualcomm Adreno GPU SDK 388
Qualcomm FastCV Computer Vision SDK 389
Snapdragon SDK for Android 393
Qualcomm AllPlay Click SDK 397
Qualcomm Profilers 399
NVIDIA Software Tools 401
Summary 404
INDEX 405
INTRODUCTION
NO MATTER HOW GOOD YOU ARE AT WRITING CODE, without proper knowledge of Integrated Development Environments (IDEs), you will face many obstacles. This book covers Google's Android Studio, the official tool for developing Android applications. Each chapter focuses on a specific topic, progressing from the basics of how to use the IDE to advanced topics such as writing plugins to extend the capabilities of the IDE.
WHO THIS BOOK IS FOR
This book is for developers with any level of experience. Whether you are new to Android or a seasoned Android developer who used Eclipse-based ADT before, this book will bring you to a level where you can unleash your true development potential by making use of Android Studio's tools.
WHAT THIS BOOK COVERS
This book not only covers features of Android Studio essential for developing Android apps but also touches on topics related to the whole development cycle. The following are just a few examples of the topics covered that are basic to Android Studio or that extend its capabilities:
- Sharing and versioning your code with Git
- Managing your builds with Gradle
- Keeping your code maintainable and bug free with testing
- Controlling the whole build and test cycle with Continuous Integration
- Writing plugins for Android Studio to extend its capabilities and add desired custom features
- Using third-party tools with Android Studio to improve the development process
HOW THIS BOOK IS STRUCTURED
Each chapter focuses on a specific topic related to Android Studio or an accompanying tool by explaining why it is needed and how it is used or configured. Some chapters provide code samples to demonstrate the use case or provide an example for the topic.
- Chapter 1: Getting Started: Installing and setting up your development environment. Creating an emulator for running your projects.
- Chapter 2: Android Studio Basics: Beginning with Android Studio, creating a new project, building your project, and migrating projects to Android Studio.
- Chapter 3: Android Application Development with Android Studio: Structure of Android Studio projects. How to use assets, XML files and the Android Manifest. Creating and working with modules.
- Chapter 4: Android Studio In Depth: Deep dive into Android Studio, explaining menus, editors, views, and shortcuts. How to use live templates and refactoring. How to build your projects and sign apks.
- Chapter 5: Layouts with Android Studio: How to use layouts with Android Studio. Explanation of previews and tools for UI development. Managing external dependencies. How to use and organize assets.
- Chapter 6: Android Build System: How to use and configure Gradle effectively. Writing plugins for Gradle
- Chapter 7: Multi-Module Projects: Adding modules in your project. How to create and work with Phone/Tablet, Library, Wear, TV, Glass, Auto, and Cloud modules.
- Chapter 8: Debugging and Testing: Debugging Android code with ADB. Learn details of the Android Devices Monitor, Android virtual devices, Lint, and testing your code.
- Chapter 9: Using Source Control: GIT: How to share your project and enable version control by using Git.
- Chapter 10: Continuous Integration: Automating your builds, tests, and releases using continuous integration servers.
- Chapter 11: Using Android NDK with Android Studio: Installing and using Android NDK for building projects with C/C++ code.
- Chapter 12: Writing Your Own Plugins: Writing your own plugins to extend the capabilities of the IntelliJ platform. Interacting with UI, editor, and adding your actions.
- Chapter 13: Third-Party Tools: Other accompanying tools that can help and speed the development lifecycle.
WHAT YOU NEED TO USE THIS BOOK
Any modern computer with an operating system that is supported by Android SDK and Android Studio is sufficient to use Android Studio, build Android apps, and run the samples given in this book. You need to install appropriate Android SDK, Android Studio, and Java Virtual Machine (JVM) for your OS. Some chapters require additional tools or frameworks to be installed such as Android NDK. You can find more information on exact hardware requirements needed in Chapter 1.
WHY WE WROTE THIS BOOK
In November 2007, Google released a preview version of Android SDK to allow developers to start playing with the new mobile operating system. Roughly two years later, in October 2009, ADT (Android Developer Tools) a plugin set for Eclipse, was released to the public.
As a Google I/O 2009 attendee, I (Murat) was lucky enough to have an Android device and was probably one of the earliest developers to download and install the plugins to my Eclipse. As years passed, we both followed the same passion to download and try new stuff released with new ADT versions.
At the time, I was an Eclipse committer who knew how to write plugins, extend the IDE's capabilities, and introduce the behavior and functionality I needed. So with each release of ADT, I was more and more excited to see what had been done with the tools.
On May 2013, at Google I/O, roughly four years after our love-hate relationship with ADT started, Google announced Android Studio, which soon became the official, supported IDE for Android development. ADT was never perfect. but it was familiar. Like many other developers, we knew all the shortcuts, how things work, what to do when something was not working, workarounds, and how the projects were structured. More significantly, we were able to write our own plugins or inspect ADT plugins to see why something went wrong. However, with the release of Android Studio, suddenly we were all in a new platform that we knew very little about.
We resisted switching to Android Studio for a while, but finally gave it a try. Suddenly, Android, a platform we were long familiar with, was a stranger. The new project structure was very different because of the changes introduced by IntelliJ and Gradle. To adopt IntelliJ, we decided to follow IntelliJ shortcuts instead of using IntelliJ shortcut mapping for Eclipse shortcuts, which made the situation even worse. We were barely able to search for a file or piece of code, navigate through menus, right-click to create files, or even generate some basic getters and setters. We went from being experts with ADT to beginners with Android Studio.
We had finally had enough! We were experienced developers, but struggled with Android Studio and were not able to show our skills. So we started following IntelliJ talks, pinning the IntelliJ shortcut cheat sheet in our cubicles, reading IntelliJ plugin code, and forcing ourselves to use Android Studio in our daily work.
This book is the summary of the lessons we learned walking unaided on this difficult path . This book is what we needed for ourselves when we were switching from Eclipse-based ADT to IntelliJ-based Android Studio. This is why we believe any developer, whether an Android newbie or a seasoned Android developer who used to work on ADT, will find this book useful for developing his or her knowledge of the tools that are actually there to support his or her coding skills.
Quoting Alex Theedom, co-author of my previous book: "Every chapter that we wrote has this goal: Write content that we would like to read ourselves." We followed the same goal with Onur and the result is the book you are holding in your hands.
We hope that you enjoy reading this book as much as we enjoyed writing it.
NOTE
Be sure to read our blog at http://www.devchronicles.com/2016/06/expert-android-studio-book-updates.html to see the changes announced at Google I/O 2016.
CONVENTIONS
To help you get the most from the text and keep track of what's happening, we've used a number of conventions throughout the book.
WARNING
Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.
NOTE
Notes, tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.
As for styles in the text:
- We highlight new terms and important words when we introduce them.
- We show keyboard strokes like this: Ctrl+A.
- We show file names, URLs, and code within the text like so:
.persistence.properties - For code:
We use a monofont type for code examples. We use bold to emphasize code that is of particular importance in the current context. SOURCE CODE
As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wiley.com/go/expertandroid. Once at the site, simply click the Download Code link on the book's detail page to obtain all the source code for the book.
NOTE
Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-1-119-08925-4.
Once you download the code, just decompress it with your favorite compression tool. Alternately, you can go to the main Wrox code download page...
System requirements
File format: ePUB
Copy protection: Adobe-DRM (Digital Rights Management)
System requirements:
- Computer (Windows; MacOS X; Linux): Install the free reader Adobe Digital Editions prior to download (see eBook Help).
- Tablet/smartphone (Android; iOS): Install the free app Adobe Digital Editions or the app PocketBook before downloading (see eBook Help).
- E-reader: Bookeen, Kobo, Pocketbook, Sony, Tolino and many more (not Kindle).
The file format ePub works well for novels and non-fiction books – i.e., „flowing” text without complex layout. On an e-reader or smartphone, line and page breaks automatically adjust to fit the small displays.
This eBook uses Adobe-DRM, a „hard” copy protection. If the necessary requirements are not met, unfortunately you will not be able to open the eBook. You will therefore need to prepare your reading hardware before downloading.
Please note: We strongly recommend that you authorise using your personal Adobe ID after installation of any reading software.
For more information, see our ebook Help page.