32,99 €
Take your Android programming skills to the next level by unleashing the potential of Android Studio Expert Android Studio bridges the gap between your Android programing skills with the provided tools including Android Studio, NDK, Gradle and Plugins for IntelliJ Idea Platform. Packed with best practices and advanced tips and techniques on Android tools, development cycle, continuos integration, release management, testing, and performance, this book offers professional guidance to experienced developers who want to push the boundaries of the Android platform with the developer tools. You'll discover how to use the tools and techniques to unleash your true potential as a developer. * Discover the basics of working in Android Studio and Gradle, as well as the application architecture of the latest Android platform * Understand Native Development Kit and its integration with Android Studio * Complete your development lifecycle with automated tests, dependency management, continuos integration and release management * Writing your own Gradle plugins to customize build cycle * Writing your own plugins for Android Studio to help your development tasks. Expert Android Studio is a tool for expert and experienced developers who want to learn how to make use of the tools while creating Android applications for use on mobile devices.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 434
Veröffentlichungsjahr: 2016
Title Page
INTRODUCTION
Who this Book is For
What this Book Covers
How this Book is Structured
What you Need to Use this Book
Why we Wrote this Book
Conventions
Source Code
Errata
p2p.wrox.com
CHAPTER 1: GETTING STARTED
System Requirements for Windows, Mac OS X, and Linux
Installing Java
Installing Android Studio
Launching Android Studio for the First Time
Standalone SDK Installation
Summary
CHAPTER 2: ANDROID STUDIO BASICS
Creating a New Sample Project
Android Emulator
Migrating Projects from Eclipse
Summary
CHAPTER 3: ANDROID APPLICATION DEVELOPMENT WITH ANDROID STUDIO
Android Projects
Android Activities
Android Services
Add Assets for Android Project
Adding XML Files to an Android Project
Android Manifest File
Android Modules
Summary
CHAPTER 4: ANDROID STUDIO IN DEPTH
Android Studio Menu Items
Android Studio Shortcuts
Android Studio Tool Views
Android Studio Editor
Android Studio Live Templates
Code Refactoring in Android Studio
Creating a Signing Key for Android Applications in Android Studio
Building APKs in Android Studio
Summary
CHAPTER 5: LAYOUTS WITH ANDROID STUDIO
Layouts with Android Studio
Layout Previews
Designing Layouts with Android Studio
Managing Resources
Using Layout Tools
Asset Management
Summary
CHAPTER 6: ANDROID BUILD SYSTEM
Using Gradle
Dependency Management with Gradle
Android Plugin for Gradle
Gradle Plugins
Summary
CHAPTER 7: MULTI-MODULE PROJECTS
Adding Modules to Android Project
Phone & Tablet Module
Android Libraries
Java Libraries
Android Wear Module
Android TV Module
Glass Module
Android Auto Module
Google Cloud Module
Importing Modules
Removing Modules from a Project
Summary
CHAPTER 8: DEBUGGING AND TESTING
Debugging Android Code
Android Monitor
Android Device Monitor
Android Virtual Device Extended Controls
Using Lint
Testing Android Code and Application UIs
Summary
CHAPTER 9: USING SOURCE CONTROL: GIT
Introduction to Git
Using Git
Using the GitHub Client
Using Git in Android Studio
Git Flow
Summary
CHAPTER 10: CONTINUOUS INTEGRATION
What Is Continuous Integration?
Integrating Android Projects with a Continuous Integration Server
Installing Jenkins
Creating Build Jobs
Release Management
Summary
CHAPTER 11: USING ANDROID NDK WITH ANDROID STUDIO
Introduction to Android NDK
Android Studio NDK Integration
Android NDK with Android Studio Projects
Android NDK Projects Release and Deployment
Summary
CHAPTER 12: WRITING YOUR OWN PLUGIN
IntelliJ Idea Plugin Architecture
Packaging and Distribution
Summary
CHAPTER 13: THIRD-PARTY TOOLS
Android Studio Plugins
Intel's Android Software Tools
Qualcomm Android Software Tools
NVIDIA Software Tools
Summary
End User License Agreement
vi
vii
ix
xi
xii
xiii
xxiii
xxiv
xxv
xxvi
xxvii
xxviii
xxix
xxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
Table of Contents
Begin Reading
Chapter 1: Getting Started
Figure 1.1 JDK download page
Figure 1.2 Java installation setup wizard
Figure 1.3 Java installation setup window
Figure 1.4 Java path setup for Windows 10
Figure 1.5 Java Environment Variables setup for Windows 10 64-bit
Figure 1.6 Mac OS X Java installation
Figure 1.7 Java installation Max OS X
Figure 1.8 Android Studio download page
Figure 1.9 Android Studio Setup window
Figure 1.10 Android Studio Setup configuration for Windows
Figure 1.11 Intel HAXM configuration dialog for Windows
Figure 1.12 Android Studio theme selection on Windows
Figure 1.13 Android Studio installer for Mac OS X
Figure 1.14 Android Studio Setup Wizard for Max OS X
Figure 1.15 Intel HAXM configuration for Mac OS X
Figure 1.16 Summary window for Max OS X installation
Figure 1.17 Android Studio Setup Wizard for Linux
Figure 1.18 Theme selection window for Linux
Figure 1.19 Android SDK configuration on Linux
Figure 1.20 First launch of Android Studio
Figure 1.21 Welcome to Android Studio
Chapter 2: Android Studio Basics
Figure 2.1 Welcome to Android Studio window
Figure 2.2 Import Sample—Browse Samples window
Figure 2.3 Import Sample—Sample Setup window
Figure 2.4 SDK Manager button in Android Studio
Figure 2.5 Android Default Preferences for Android SDK window
Figure 2.6 Android SDK Manager installation window
Figure 2.7 Android Studio after importing the sample project
Figure 2.8 Project view on Android Studio
Figure 2.9 Traditional project view
Figure 2.10 Expanded view of project folders
Figure 2.11 Opened Java file on Android Studio
Figure 2.12 res folder in Android project view
Figure 2.13 Build menu list
Figure 2.14 Run menu items in Android Studio
Figure 2.15 Android Studio Run ‘Application’ button
Figure 2.16 Intel HAXM selection in Windows
Figure 2.17 Android Studio AVD Manager button
Figure 2.18 AVD Manager's initial appearance
Figure 2.19 List of virtual device hardware
Figure 2.20 System Image selection for AVD
Figure 2.21 AVD configuration window
Figure 2.22 List of created virtual devices
Figure 2.23 Start migrating from Eclipse
Figure 2.24 Select project path to import
Figure 2.25 Export from Eclipse
Figure 2.26 Export window on Eclipse
Chapter 3: Android Application Development With Android Studio
Figure 3.1 Android Studio Welcome window
Figure 3.2 Create New Project window
Figure 3.3 Target device selection window
Figure 3.4 Android Platform/API Version Distribution window
Figure 3.5 Add activity window
Figure 3.6 Activity customization window
Figure 3.7 First Project View in Android Studio
Figure 3.8 Multiple target device selection
Figure 3.9 Adding a Wear Activity
Figure 3.10 Wear Activity configuration window
Figure 3.11 Two modules shown in Project View
Figure 3.12 Android Studio toolbar Run ‘app’ button
Figure 3.13 Device selection window
Figure 3.14 Launch emulator option in the Device selection window
Figure 3.15 Hello World application running on the emulator
Figure 3.16 Android Activity lifecycle
Figure 3.17 Adding a new activity template
Figure 3.18 Activity template customization
Figure 3.19 Empty Activity template on an Android device
Figure 3.20 Fragment lifecycle
Figure 3.21 Tabbed Activity customization window
Figure 3.22 Tabbed Activity template screenshot with Swipe Views navigation style
Figure 3.23 Action Bar Tabbed and Spinner UI screenshots for the Tabbed Activity template
Figure 3.24 Customizing the service class name
Figure 3.25 IntentService customization window
Figure 3.26 res folder content
Figure 3.27 New Image Asset menu
Figure 3.28 Image Asset Studio window
Figure 3.29 Image Asset Studio summary
Figure 3.30 string.xml and the values folder content
Figure 3.31 New Module selection window
Figure 3.32 Creating a new module
Figure 3.33 Project View after a new module iscreated
Chapter 4: Android Studio In Depth
Figure 4.1 Menus on Mac OS X
Figure 4.2 Preferences window
Figure 4.3 File operations menu
Figure 4.4 New menu action items
Figure 4.5 Project Structure window
Figure 4.6 Edit menu items
Figure 4.7 Find menu items
Figure 4.8 View menu items
Figure 4.9 Navigate menu items
Figure 4.10 Implementation of the superclass BroadcastReceiver
Figure 4.11 Code menu items
Figure 4.12 Analyze menu items
Figure 4.13 Inspection window
Figure 4.14 Refactor menu items
Figure 4.15 Refactor options
Figure 4.16 Build menu items
Figure 4.17 Android Studio Tools menu
Figure 4.18 VCS menu items
Figure 4.19 Keymap window
Figure 4.20 Enter Keyboard Shortcut window
Figure 4.21 Tools Window items
Figure 4.22 Accessing the tools shortcuts
Figure 4.23 Activated tools
Figure 4.24 Messages tool window
Figure 4.25 Project view options
Figure 4.26 Favorites window
Figure 4.27 Android Monitor window
Figure 4.28 Structure view of a Java class
Figure 4.29 Android Model view for mobile applications
Figure 4.30 Run window
Figure 4.31 Debug window
Figure 4.32 Android Studio Terminal
Figure 4.33 Live Template window
Figure 4.34 Auto complete for a Live Template
Figure 4.35 Cursor highlight in a Live Template
Figure 4.36 Insert Live Template
Figure 4.37 Surrounding Live Templates
Figure 4.38 Add template button
Figure 4.39 Adding a Live Template
Figure 4.40 Edit Template Variables window
Figure 4.41 Live Template context list
Figure 4.42 Surrounding Live Template
Figure 4.43 Refactoring options right-click menu
Figure 4.44 Push Members Down window
Figure 4.45 Pull Members Up window
Figure 4.46 Encapsulation
Figure 4.47 Change Signature window
Figure 4.48 Select the module to create a signed APK
Figure 4.49 Create new key for the signing certificate
Figure 4.50 Certificate form
Chapter 5: Layouts with Android Studio
Figure 5.1 Layouts in the Project view
Figure 5.2 Adding a new layout in Android Studio
Figure 5.3 Configuring a new layout file
Figure 5.4 Layout in text mode
Figure 5.5 Visually designing in Android Studio
Figure 5.6 Preview window
Figure 5.7 Layout rendering options
Figure 5.8 Selecting a layout to preview in Android Studio
Figure 5.9 List of generic devices
Figure 5.10 Picking the Android SDK version for previewing
Figure 5.11 Theme selection window
Figure 5.12 Palette tool
Figure 5.13 New components added to a layout
Figure 5.14 Editing properties
Figure 5.15 Adding a new component in XML files
Figure 5.16 Editing view properties in XML
Figure 5.17 Resource selection window
Figure 5.18 Color resources definition
Figure 5.19 Translation Editor
Figure 5.20 Expanded list of locales
Figure 5.21 Translated and default value
Figure 5.22 Android Studio language ordering web page
Figure 5.23 Associate with other Activity
Figure 5.24 Asset resolution list
Figure 5.25 Visual structure for asset resources
Figure 5.26 Adding an image asset
Figure 5.27 Asset Studio window
Figure 5.28 Asset type listing
Figure 5.29 Foreground options
Figure 5.30 Adding a vector asset
Figure 5.31 Creating a vector asset
Chapter 6: Android Build System
Figure 6.1 Build variant selection
Chapter 7: Multi-Module Projects
Figure 7.1 New Module selection
Figure 7.2 Configuring a new Phone & Tablet module
Figure 7.3 Phone & Tablet module in Project view
Figure 7.4 Android Library module
Figure 7.5 Module dependencies
Figure 7.6 Add a dependency
Figure 7.7 Java Library module configuration
Figure 7.8 Java Library module in Project view
Figure 7.9 Wear module preview
Figure 7.10 Wear virtual device selection
Figure 7.11 Wear virtual device configuration
Figure 7.12 List of runnable modules
Figure 7.13 Wear app in Android Wear AVD
Figure 7.14 APK generation completed notification
Figure 7.15 Android TV module activity configuration
Figure 7.16 Android TV module view in the project window
Figure 7.17 Select TV resolution and density
Figure 7.18 Android TV image selection
Figure 7.19 TV module selection
Figure 7.20 Running Android TV application on AVD
Figure 7.21 Android TV module debug selection
Figure 7.22 Glass module naming
Figure 7.23 Glass module activity selection
Figure 7.24 Android Auto activities
Figure 7.25 Google Cloud module setup wizard
Figure 7.26 Google Cloud module types
Figure 7.27 Google Cloud module configuration
Figure 7.28 Google Cloud module after module creation
Figure 7.29 Runnable modules with Google Cloud module
Figure 7.30 Message output for the Google Cloud module run
Figure 7.31 Google Cloud module launch from browser
Figure 7.32 Gradle project module naming
Figure 7.33 Module naming for an imported Eclipse ADT project
Figure 7.34 Dependency replacement confirmation for an imported Eclipse ADT project
Figure 7.35 Missing Android SDK version warning
Figure 7.36 Importing a JAR/AAR package
Figure 7.37 Project view of an imported JAR/AAR module
Figure 7.38 Module Remove confirmation
Chapter 8: Debugging and Testing
Figure 8.1 Android Studio adb integration
Figure 8.2 Break point in Android Studio
Figure 8.3 Debug window console
Figure 8.4 Debug window left pane actions
Figure 8.5 Breakpoints window
Figure 8.6 Thread dump data
Figure 8.7 Debug window actions toolbar
Figure 8.8 Evaluate Expression window
Figure 8.9 Undefined result in the Evaluate Expression window
Figure 8.10 Actions accessible inside Java code
Figure 8.11 Debugger tab in the Debug window
Figure 8.12 Variable actions
Figure 8.13 Watches pane
Figure 8.14 Highlighted variables and values in code
Figure 8.15 Hovering over a variable to reveal its value
Figure 8.16 Android Monitor tabs
Figure 8.17 List of system information available with Android Monitor
Figure 8.18 Screenshot preview window
Figure 8.19 Screen Recorder Options dialog box
Figure 8.20 System information Captures window
Figure 8.21 Device and process selection
Figure 8.22 No Filters output in logcat
Figure 8.23 Log type selection
Figure 8.24 Memory monitor
Figure 8.25 Java Heap dump
Figure 8.26 hprof memory dump
Figure 8.27 Allocation tracking file
Figure 8.28 Allocation tracking with allocator grouping
Figure 8.29 CPU monitor
Figure 8.30 CPU track dump
Figure 8.31 GPU monitor
Figure 8.32 Network monitor
Figure 8.33 Android Device Monitor
Figure 8.34 Threads in Android Device Monitor
Figure 8.35 Thread trace
Figure 8.36 Heap tracing in Android Device Monitor
Figure 8.37 XML dump icon
Figure 8.38 XML dump view
Figure 8.39 Android Device Monitor File Explorer
Figure 8.40 System Information view in Android Device Monitor
Figure 8.41 Hierarchy view generation
Figure 8.42 Hierarchy view details
Figure 8.43 Virtual device toolbar
Figure 8.44 Extended controls window
Figure 8.45 GPS location setting
Figure 8.46 Emulator call
Figure 8.47 Android virtual device keyboard shortcuts
Figure 8.48 Android Lint output
Figure 8.49 Creating a new class in the tests folder
Figure 8.50 CalculatorTest results
Figure 8.51 Debugging a mock class
Figure 8.52 Running an Espresso test
Figure 8.53 Test output
Figure 8.54 Systrace output
Chapter 9: Using Source Control: GIT
Figure 9.1 Distributed version control using Git
Figure 9.2 Git branch
Figure 9.3 Merging a non-conflicting branch
Figure 9.4 Merging conflicting branch
Figure 9.5 GitHub page
Figure 9.6 Git configuration output
Figure 9.7 GitHub Desktop Application Install – Security Warning window
Figure 9.8 GitHub Desktop installation process
Figure 9.9 GitHub Desktop start screen
Figure 9.10 GitHub Desktop welcome screen
Figure 9.11 Connecting to GitHub
Figure 9.12 GitHub repositories list
Figure 9.13 Creating a new repository with GitHub Desktop
Figure 9.14 Repository path selection
Figure 9.15 Other projects list
Figure 9.16 Untracked changes shown on the GitHub Client
Figure 9.17 List of changes on GitHub Desktop
Figure 9.18 Importing a project
Figure 9.19 Git project path
Figure 9.20 Sign-in warning
Figure 9.21 Sign-in screen
Figure 9.22 Entering the repository name and description
Figure 9.23 GitHub project display
Figure 9.24 The Sync button on GitHub
Figure 9.25 Creating a new project
Figure 9.26 Selecting modules and an SDK version
Figure 9.27 Enabling version control integration in Android Studio
Figure 9.28 List of version control systems available for Android Studio
Figure 9.29 Import into Version Control options
Figure 9.30 Untracked changes in Android Studio
Figure 9.31 Adding items to the Git repository
Figure 9.32 Added changes to Git in Android Project View
Figure 9.33 Commit action in Android Studio
Figure 9.34 Android Studio Commit Changes wizard
Figure 9.35 The Commit button in Android Studio
Figure 9.36 Code Analysis warning window
Figure 9.37 Branch menu item
Figure 9.38 New Branch selection
Figure 9.39 Branch naming
Figure 9.40 Simple change in code
Figure 9.41 Uncommitted changes indicated in Android Studio
Figure 9.42 Commit the file changes
Figure 9.43 Diff tool output
Figure 9.44 Changelist window
Figure 9.45 Commit changes window
Figure 9.46 Merging changes
Figure 9.47 Branch merge
Figure 9.48 Master branch visualization from GitUp
Figure 9.49 Branch visualization from GitUp
Figure 9.50 Merge conflict warning
Figure 9.51 Merge Revisions window
Figure 9.52 Manual merge
Figure 9.53 Saving changes notification
Figure 9.54 Updated commit message
Figure 9.55 GitUp visualization after conflict resolution
Figure 9.56 Defining a remote in the Push Commit window
Figure 9.57 Remote repository definition
Figure 9.58 Push commit summary
Chapter 10: Continuous Integration
Figure 10.1 Jenkins download page
Figure 10.2 Jenkins installation window
Figure 10.3 Jenkins license agreement
Figure 10.4 Jenkins installation directory selection
Figure 10.5 Jenkins installation final window
Figure 10.6 Jenkins server URL
Figure 10.7 Accessing Jenkins from a browser
Figure 10.8 Jenkins plugins
Figure 10.9 Searching Jenkins plugins
Figure 10.10 Plugin search results
Figure 10.11 Jenkins plugin download
Figure 10.12 Jenkins plugin download progress
Figure 10.13 Creating build jobs
Figure 10.14 Sample application fork
Figure 10.15 Build job for the application fork sample
Figure 10.16 Jenkins access to GitHub
Figure 10.17 Repository initialization
Figure 10.18 Credentials for Jenkins
Figure 10.19 Build frequency selection
Figure 10.20 Email notification initialization
Figure 10.21 Email notification to user
Figure 10.22 Building the project
Figure 10.23 Schedule for the build
Figure 10.24 Build properties by build number
Figure 10.25 Console output of the build process
Figure 10.26 Jenkins dashboard
Figure 10.27 Status of the build in Jenkins
Figure 10.28 Plugin search
Figure 10.29 Download selected plugins
Figure 10.30 Configuring a Jenkins build job
Figure 10.31 Running on Android emulator
Figure 10.32 Emulator configuration
Figure 10.33 Google Play account configuration for Jenkins
Figure 10.34 Google Play account credentials configuration
Figure 10.35 Google Service Account private key
Figure 10.36 Getting your JSON key from the Google Developer Console
Figure 10.37 Release configuration
Figure 10.38 Build progress to install Android SDK and tools
Figure 10.39 Build progress to install the emulator
Figure 10.40 Jenkins creating the emulator
Figure 10.41 Jenkins launching the emulator
Chapter 11: Using Android NDK with Android Studio
Figure 11.1 Android NDK bundle license agreement
Figure 11.2 Project Structure window
Figure 11.3 Android Studio installs Android NDK
Figure 11.4 Android Studio Project Structure window in Windows 10
Figure 11.5 Android NDK setup completion
Figure 11.6 Importing a sample project from the Welcome to Android Studio window
Figure 11.7 Sample NDK projects list
Figure 11.8 Sample configuration
Figure 11.9 Downloading the sample project
Figure 11.10 Project View of the Hello JNI project
Figure 11.11 Importing an NDK project
Figure 11.12 Gradle scripts after importing an NDK project
Figure 11.13 Syncing the project after changing the plugin
Figure 11.14 Gradle build failure after changing the plugin
Chapter 12: Writing Your Own Plugin
Figure 12.1 IntelliJ IDEA download page
Figure 12.2 IntelliJ IDE Start screen
Figure 12.3 List of project types
Figure 12.4 IntelliJ SDK location configuration
Figure 12.5 Plugin option on the IntelliJ toolbar
Figure 12.6 IntelliJ IDEA welcome wizard
Figure 12.7 Contents of the plugin.xml file
Figure 12.8 Smart fix options
Figure 12.9 Class inheritance control
Figure 12.10 Smart assistance to help class extension
Figure 12.11 New menu view
Figure 12.12 New menu item
Figure 12.13 New plugin's popup greeting
Figure 12.14 New action selection
Figure 12.15 New Action window
Figure 12.16 New plugin creation
Figure 12.17 Creating the EditorAction class
Figure 12.18 Implement methods selection
Figure 12.19 The plugin action with text selected
Figure 12.20 Right-click actions when no text is selected
Figure 12.21 CustomWizard class creation
Figure 12.22 Implementing the CustomWizard action
Figure 12.23 ActionWizard class methods
Figure 12.24 Creating the new wizard
Figure 12.25 Custom wizard steps
Figure 12.26 Plugin deployment selection
Figure 12.27 Plugin package info popup dialog box
Figure 12.28 Installing the plugin from disk
Chapter 13: Third-Party Tools
Figure 13.1 Installed plugins in Android Studio
Figure 13.2 Installable Android Studio plugins
Figure 13.3 JetBrains plugins website
Figure 13.4 After plugin installation
Figure 13.5 .ignore plugin
Figure 13.6 ADB Idea action list
Figure 13.7 ADB WIFI menu
Figure 13.8 ADB WIFI connection information
Figure 13.9 Android Drawable Importer plugin actions
Figure 13.10 Icon Pack Drawable Importer
Figure 13.11 Generate menu for the Parcelable class
Figure 13.12 Android Holo Colors configuration page
Figure 13.13 Key Prompter popup
Figure 13.14 jimu Mirror tool menu and action buttons
Figure 13.15 Genymotion Device Manager window
Figure 13.16 Genymotion Virtual Device List
Figure 13.17 Genymotion application window
Figure 13.18 Genymotion Player window
Figure 13.19 Intel System Studio version comparison
Figure 13.20 Intel System Studio components
Figure 13.21 Eclipse Integration selection
Figure 13.22 Intel System Studio Android NDK integration
Figure 13.23 Intel C++ Compiler Hello JNI sample
Figure 13.24 Intel VTune Amplifier
Figure 13.25 Intel VTune Amplifier new project view
Figure 13.26 Multi-OS Engine SDK path selections
Figure 13.27 Multi-OS Engine Installation path selection
Figure 13.28 Multi-OS Engine Android Studio menu items
Figure 13.29 Intel Context Sensing SDK installer
Figure 13.30 Intel Context Sensing SDK installation content
Figure 13.31 Importing the Intel Context Sensing SDK library
Figure 13.32 PhysicalActivitySensingSample screenshot
Figure 13.33 FastCV SDK directory
Figure 13.34 FastCV demo application in Android Studio
Figure 13.35 Facial Recognition API Tests
Figure 13.36 Importing FacialRecognitionSample
Figure 13.37 Adding a jar file as a library
Figure 13.38 JNI library dependency for Snapdragon SDK
Figure 13.39 Snapdragon SDK Face Recognition sample application
Figure 13.40 AllPlay Click download package contents
Figure 13.41 AllPlay Click demo project view
Figure 13.42 AllPlay Click demo application
Figure 13.43 Windows system path variables list
Figure 13.44 Snapdragon Profiler in use
Figure 13.45 NVIDIA CodeWorks path configuration
Figure 13.46 NVIDIA CodeWorks components
Murat YenerOnur Dundar
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.
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.
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
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.
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.
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.
Be sure to read our blog athttp://www.devchronicles.com/2016/06/expert-android-studio-book-updates.htmlto see the changes announced at Google I/O 2016.
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.
Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.
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.
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.
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 at http://www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.
We make every effort to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error in one of our books, such as a spelling mistake or a faulty piece of code, we would be very grateful for your feedback. By sending in errata, you may save another reader hours of frustration and at the same time you will be helping us provide even higher quality information.
To find the errata page for this book, go to http://www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page you can view all errata that have been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.
If you don't spot “your” error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.
For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a Web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to e-mail you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.
At http://p2p.wrox.com you will find a number of different forums that will help you not only as you read this book, but also as you develop your own applications. To join the forums, just follow these steps:
Go to
p2p.wrox.com
and click the Register link.
Read the terms of use and click Agree.
Complete the required information to join as well as any optional information you wish to provide and click Submit.
You will receive an e-mail with information describing how to verify your account and complete the joining process.
You can read messages in the forums without joining P2P but in order to post your own messages, you must join.
Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the Web. If you would like to have new messages from a particular forum e-mailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.
For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.
WHAT'S IN THIS CHAPTER?
System requirements for Android Studio
Java installation instructions for Microsoft Windows, Mac OSX, and Linux
Android Studio installation instructions for Microsoft Windows, Mac OSX, and Linux
In this chapter you get started with setting up your development environment so you can start Android development with Android Studio. To that end, this chapter covers the basic installation instructions for Android Studio and its system requirements.
Although the Android operating system is based on Linux, the Android SDK and tools are available for all major operating systems, so you can set up your development environment for the operating system you are working with. Throughout this book we use Mac OS as the main environment; however, we cover Linux and Windows setup as well.
To use Android Studio, your development system must meet the minimum system requirements. This section lists the minimum requirements for Windows, Mac OS X, and Linux.
Microsoft Windows
Microsoft Windows 10/8/7/Vista/2003 (32 or 64 bit)
2GB RAM minimum, 4GB RAM recommended
400MB hard disk space
At least 1GB for Android SDK, emulator system images, and caches
1280 × 800 minimum screen resolution
Java Runtime Environment (JRE) 6 or higher
Java Development Kit (JDK) 7
Optional for accelerated emulator: Intel processor with support for Intel VT-x, Intel EM64T (Intel 64), and Execute Disable (XD) Bit functionality
Mac OS X
Mac OS X 10.8.5 or higher, up to 10.9 (Maverick)
2GB RAM minimum, 4GB RAM recommended
400MB hard disk space
At least 1GB for Android SDK, emulator system images, and caches
1280 × 800 minimum screen resolution
Java Runtime Environment (JRE) 6
Java Development Kit (JDK) 7
Optional for accelerated emulator: Intel processor with support for Intel VT-x, Intel EM64T (Intel 64), and Execute Disable (XD) Bit functionality
Linux
GNOME or KDE desktop
GNU C Library (glibc) 2.15 or later
2GB RAM minimum, 4GB RAM recommended
400MB hard disk space
At least 1GB for Android SDK, emulator system images, and caches
1280 × 800 minimum screen resolution
Java Runtime Environment (JRE) 6 or higher
Oracle Java Development Kit (JDK) 7
More details about system requirements can be found at https://developer.android.com/sdk/index.html#Requirements.
Keep in mind that based on the size of the project, number of your dependencies, and emulator usage, you will likely need more resources. Typically, you will need at least 8GB of RAM and GPU support to run an emulator and work smoothly with better compilation times.
In most cases, developers need to test applications on multiple devices. Because they usually don't have enough devices to test adequately, they rely on emulators. Emulators require a high amount of storage and memory to run faster.
Emulators are virtual devices, so having a CPU with virtualization support is crucial for developers to get the best experience with Android emulators.
Java is essential for all operating systems. You must install Java SE (Standard Edition) Development Kit (JDK) for your operating system.
We suggest the Java distribution provided by Oracle. It is possible to encounter problems with OpenJDK or other Java distributions.
At the time of this writing, Java SE 8 is the latest version of JDK.
The JDK 7 download page can be accessed directly at http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html. When you navigate there, the page shown in Figure 1.1 appears.
Figure 1.1 JDK download page
To download the required installation binary or packages, select the Accept License Agreement option and then click the download link of the binary or package for your operating system.
The following sections provide installation instructions for Oracle Java version 7 on 64 bit Windows, Mac OS X, and Linux.
Java installation on Windows is pretty straightforward. As mentioned in the previous section, installing JDK provides JRE as well.
Depending on the version of your Windows installation, you need to download and install either the 64 bit or 32 bit version of the JDK. Since most modern computers are equipped with 64 bit CPUs, we will continue with installation of the 64 bit version. If you have a 32 bit Windows installation, use the 32 bit JDK, which is listed as the Windows x86 version.
Download the jdk-7u79-windows-x64.exe file and run it to start the installation.
Start the Java installation by clicking the jdk-7u79-windows-x64.exe file after downloading it; you will see the dialog box shown in Figure 1.2.
Figure 1.2 Java installation setup wizard
Click the Next button to continue.
In the window that opens, all items are selected by default to be installed on your local hard drive. You can change the installation path and which installation modules to install. For Android application development, the Public JRE and Development Tools options must be selected if they are not already installed on your machine. (If they are already installed, they will not be listed inside the window.) You may deselect Source Code, which is used to install public Java API classes. It is not mandatory to install the source code. Make your selections in the dialog shown in
Figure 1.3
.
We suggest that you continue with the default selections and use the default installation path, then click Next to finish the installation.
Figure 1.3 Java installation setup window
After the installation finishes, you need to set the Windows 10 environment paths for Java to configure the system environment. You need to set a path for the JAVA_HOME system variable.
In earlier versions of Windows, the steps for setting the environment path might be a little different.
Right-click the Start menu icon and click File Explorer. In the window that opens, right-click This PC and select Properties to open the System window.
From the options at the left of the System window, select Advanced system settings. This will open the dialog box shown in
Figure 1.4
with the Advanced tab enabled.
Click the Environment Variables… button shown in
Figure 1.4
.
From the Environment Variables window that opens, click the New button and set the Java path with your installation directory. As shown in
Figure 1.5
, the path is
C:\Program Files\Java\jdk1.7.0_79
for our 64 bit installation. If you installed the x86 version, your path would be different, such as
C:\Program Files (x86)\Java\jdk1.7.0_79
.
Figure 1.4 Java path setup for Windows 10
Figure 1.5 Java Environment Variables setup for Windows 10 64-bit
Java used to be a part of Mac OS X and was shipped by Apple. This changed several years ago. Apple also decided to remove Java from Mac OS so JDK, which is provided by Oracle, needs to be installed separately.
Start by downloading the
jdk-7u79-macosx-x64.dmg
file from the page shown in
Figure 1.1
.
Launch the dmg file to display the window shown in
Figure 1.6
.
Double click the JDK 7 Update 79.pkg file link to start the installation.
Select the installation directory you want and complete the installation in the window shown in
Figure 1.7
.
Figure 1.6 Mac OS X Java installation
Figure 1.7 Java installation Max OS X
Now JDK is ready to use on Mac OS X. You can check the installed JDK version from System Preferences of Mac OS X or type 'java –version' in the terminal window to see whether Java installed properly.
Two types of installation packages are available for Linux. If you use a distribution with an rpm package manager like Fedora, you can download the rpm package and install Java via rpm. In this section you install JDK with the tar.gz package on Ubuntu 14.04.
Download
jdk-7u79-x64.tar.gz
from the download page shown in
Figure 1.1
and extract it to the directory where you downloaded the
tar.gz
file using the following command:
user@ubuntu$ tar xzvf jdk-7uXX-x64.tar.gz
That command will extract JDK into the jdk1.7.0_79 folder where you ran the command.
Move that folder to
/usr/local/java
with the following command:
user@ubuntu$ mv jdk1.7.0_79 /usr/local/java
Edit the
/etc/profile
file to set Java paths for your session. You can copy and paste the following lines to the end of the
/etc/profile
file.
##Java Path JAVA_HOME=/usr/local/java/jdk1.7.0_79 JRE_HOME=$JAVA_HOME/jre PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin export JAVA_HOME export JRE_HOME export PATH
Install Java binaries for system-wide use with the following commands:
Install the Java binary:
user@ubuntu$ sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_79/bin/java" 1
Install the Java Compiler binary
javac
:
user@ubuntu$ sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_79/bin/javac" 1
Install the Java Web Start binary
javaws
:
user@ubuntu$ sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_79/bin/javaws" 1
Set Oracle Java as the default Java for your system with the following commands:
user@ubuntu$ sudo update-alternatives --set java /usr/local/java/jdk1.7.0_79/bin/java user@ubuntu$ sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_79/bin/javac user@ubuntu$ sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_79/bin/javaws
When you are done with the previous instructions, JDK and JRE will be ready to use when you restart Ubuntu. You can test whether Java installed correctly with version control. The command and output for that will look like this:
user@ubuntu~$ java -version java version "1.7.0_79" Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
Android Studio installation, like Java installation, differs by operating system. The following sections provide installation instructions for Windows, Mac OS X, and Linux platforms.
The direct link for the installation binaries is https://developer.android.com/sdk/index.html.
The download link that's available when you go to this site will be correct for the operating system you are running, as shown in Figure 1.8.
Figure 1.8 Android Studio download page
Download options have installers bundled with Android SDK tools.
This section covers the installation instructions for Android Studio on Microsoft Windows 10.
Make sure you are connected to Internet while you are installing the Android Studio because installation process includes downloading required Android SDK installation files from the web.
Click the Download Android Studio for Windows link to download the latest Android Studio installer exe file.
Run the exe file after the download completes. You will see the window shown in
Figure 1.9
.
Click the Next button to select installation components. The Android Studio option can't be changed, but you can deselect the Android SDK, Emulator, and Intel HAXM installations, as shown in
Figure 1.10
.
The next window prompts you for installation paths for Android Studio and Android SDK separately.
As shown in
Figure 1.11
, the installation asks about Intel HAXM memory configuration, and lets you choose a custom memory configuration.
Figure 1.9 Android Studio Setup window
Figure 1.10 Android Studio Setup configuration for Windows
Figure 1.11 Intel HAXM configuration dialog for Windows
Recommended memory for HAXM is 2GB, but you can change that based on your hardware. We recommend that you install HAXM if you plan to use the emulator.
HAXM is a hardware-assisted virtualization engine that lets you use your computer's processor to generate x86 Android images. Without HAXM, the emulator's performance will greatly suffer.
You are now ready to launch Android Studio on Windows. The first time you launch Android Studio, it asks you to select the theme for the IDE, as shown in Figure 1.12.
Figure 1.12 Android Studio theme selection on Windows
Finally, the installation completes and Android Studio is ready to work on Android application projects.
This section covers the basic steps to install Android Studio on Mac OS X.
From the page shown in
Figure 1.8
, click the Download Android Studio for MAC link.
Download the android-studio-ide-141.2178183-mac.dmg file, which includes the Android Studio IDE installer for Mac OS.
Launch the file you just downloaded.
Drag and drop the Android Studio.app icon into Applications folder, as shown in
Figure 1.13
.
Figure 1.13 Android Studio installer for Mac OS X
After copying Android Studio to the Applications folder, Android Studio is ready to launch. You can then remove the .dmg file from your system.
When you first launch Android Studio, it asks if you want to install Android SDK, the Android emulator, and Intel HAXM. It will also ask for the setup path for them, as shown in Figure 1.14.
Figure 1.14 Android Studio Setup Wizard for Max OS X
If you selected Intel HAXM installation, you are asked for the amount of RAM memory you want to make available for the virtual devices, as shown in Figure 1.15.
Figure 1.15 Intel HAXM configuration for Mac OS X
