Chapter 2 Setting Up For Development

Transcription

Introduction to Android ApplicationDevelopment, Android Essentials,Fifth EditionChapter 2Setting Up for Development

Chapter 2Overview Learn how to set up our Android developmentenvironmentLook at many of the tools provided with theAndroid SDKReview the Android SDK License AgreementLearn about many important SDK packagesLook at the sample applications available with theSDK

Configuring Your DevelopmentEnvironment Android SDK compatible with Windows,Macintosh, or Linux systemsInstallation requirements for using this book:– Java Development Kit (JDK), Version 7 loads/index.html– Android Studio (includes the Android SDK) http://d.android.com/sdk/index.html

Included with Android Studio Android Studio– SDK tools– Platform tools– The latest Android platform– The latest Android system image for theemulator

Alternative Compatible Java IDE IntelliJ IDEA– Community Edition– Ultimate Edition

Alternative Configurations(Cont’d) When using other IDEs:– Command-line tools e.html– Debugging ects-cmdline.html– Testing http://d.android.com/tools/testing/testing otheride.html

Basic Installation Process1.2.3.4.5.6.Download and install the appropriate JDK.Download and install or unzip the appropriateAndroid Studio package for your OperatingSystem.Launch Android Studio and use the Android SDKManager to download and install specific Androidplatform versions and other components.Install appropriate USB drivers for devicedebugging, if necessary.Configure your device(s) for debugging.Start developing.

Basic Installation Process

Configuring Your OperatingSystem for Device Debugging To install and debug on real devices:– Configure OS to access device via USB– Mac OS May work without any configuration– Windows Requires appropriate USB driver http://d.android.com/sdk/win-usb.html– Linux Requires additional steps http://d.android.com/tools/device.html

Configuring Your OS for DeviceDebugging (Cont’d)

Configuring Android Hardware forDebugging Devices with Android 4.2 have debuggingdisabled by default.– This requires enabling Developer Options.1. From the Home screen, choose All Apps Settings About Phone (or AboutTablet).2. Scroll down to Build Number.3. Press Build Number seven times to unlockDeveloper Options.

Configuring Android Hardware forDebugging (Cont’d) To install our own applications, configure ourdevice to install from Unknown sources.1. From Home All Apps Settings Security.2. Enable (check) Unknown sources.–Skipping this step prevents us from installingour apps to our own device.

Configuring Android Hardware forDebugging (Cont’d)

Configuring Android Hardware forDebugging (Cont’d) Enable some Developer Options settings.– From Home All Apps Settings Developer options Then enable USB debugging.

Configuring Android Hardware forDebugging (Cont’d)

Upgrading Android Studio and theAndroid SDK To stay up-to-date with the latest advancements:– Upgrade from time to timeUpdates include:–––––New, updated, or removed featuresPackage name changesUpdated toolsEssential documents Overview of Changes API Diff Report Release NotesSee s.html

Problems with Android Studio andthe Android SDK There may be bugs!– Find open issues and their status at the Androidproject’s Issue Tracker website.– Submit new issues for review.– Issue tracker website: –To report bugs or defects for Android Dev team: rn more about the bug-fixing process: l

Exploring the Android SDK Android SDK major components:– Android SDK Platform by version– Platform tools– SDK Build Tools– System images– Google APIs– Sources for Android SDK– Extras– Sample applications

The Android SDK LicenseAgreement Before downloading the SDK, you must agree tothe Android SDK License Agreement.– This agreement is between you and Google.– Make sure that you understand this license evenif someone else has accepted the agreement onyour behalf!

The Android SDK LicenseAgreement (Cont’d) Rights granted:– Google grants you a limited, worldwide, royaltyfree, nonassignable, and nonexclusive licenseto use the SDK solely to develop applicationsfor the Android platform.– Google still holds all copyrights and intellectualproperty rights to the SDK.– Google does not grant permission to use any ofits brands, logos, or trade names.– You will not remove any copyright noticestherein.

The Android SDK LicenseAgreement (Cont’d) SDK usage:– You may only develop Android applications withthe SDK. You may not make derivative works from theSDK or distribute the SDK on any device. You may not distribute part of the SDK withother software.

The Android SDK LicenseAgreement (Cont’d) SDK changes and backward compatibility:– Google may change the Android SDK at anytime without notice and without regard tobackward compatibility. Early APIs had frequent changes, but recentreleases are reasonably stable. Each SDK update does affect at least a smallnumber of apps.– Updating your application is your ownresponsibility.

The Android SDK LicenseAgreement (Cont’d) Android application developer rights:– You retain all rights to any Android software youdevelop with the SDK, including intellectualproperty rights.– You also retain all responsibility for your ownwork.

The Android SDK LicenseAgreement (Cont’d) Android application privacy requirements:– You agree that your application will protect theprivacy and legal rights of your users.– If your app accesses personal and private info,you must provide adequate privacy notice andkeep the data stored securely. These includeusernames, passwords, and so on.– Privacy laws and regulations vary by userlocation. You are solely responsible for managing thisdata appropriately.

The Android SDK LicenseAgreement (Cont’d) Android application malware requirements:– You are responsible for all applications youdevelop.– You agree not to write disruptive applications ormalware.– You are solely responsible for all datatransmitted through your application.

The Android SDK LicenseAgreement (Cont’d) Additional terms for specific Google APIs:– Use of APIs such as Google Maps Android API issubject to further Terms of Service. You must agree to these additional terms beforeusing those specific APIs. You must always include the copyright notice,too.– Other API terms include Gmail, Blogger, GoogleCalendar, and YouTube. Your application’s usage is limited to accessingthose to which your user has explicitly grantedpermission.

The Android SDK LicenseAgreement (Cont’d) Develop at your own risk!– Any harm that comes from developing with theAndroid SDK is your own fault and not Google’s.

Reading the Android SDKDocumentation Read locally or online:– Online at http://d.android.com/index.html

Reading the Android SDKDocumentation (Cont’d)

Exploring the Core AndroidApplication Framework Which file comprises the Android framework?– android.jar

Important Packages in theAndroid SDKTop-Level Package NameDescriptionandroid.*Android application fundamentalsdalvik.*Dalvik virtual machine support classesjava.*Core classes and familiar generic utilitiesjavax.*Encryption supportjunit.*Unit-testing supportorg.apache.http.*HTTP protocol supportorg.jsonJSON supportorg.w3c.domW3C DOM XML and HTML supportorg.xml.*SAX support for XMLorg.xmlpull.*High-performance XML pull parsing

Popular Third-Party Android APIs Available outside the core Android SDKInstalled separatelySome are from Google, others from devicemanufacturers and other providers

Popular Third-Party Android APIs(Cont’d) Android Support LibraryGoogle Mobile Ads SDK (com.google.android.gms.ads.*) Google Analytics SDK for Android(com.google.android.gms.analytics.*) Android Cloud Messaging for Android (GCM)(com.google.android.gms.gcm) Google App Indexing(com.google.android.gms.appindexing)Google App Invites (com.google.android.gms.appinvite) Google Play Game Services(com.google.android.gms.games)Google Fit (com.google.android.gms.fitness)

Exploring the Core Android Tools Android Studio– Where you spend most of your time developingyour apps– Provides wizards for creating, debugging, anddeploying Android apps– Several buttons available on the toolbar forperforming helpful actions

Android Studio Launch the Android Virtual Device ManagerLaunch the Android SDK ManagerLaunch the Android Device Monitor

Android Studio (Cont’d)

Android SDK and AVD Managers The first Android toolbar icon launches theAndroid Virtual Device Manager.The second Android toolbar icon launches theAndroid SDK Manager.

Android SDK and AVD Managers(Cont’d)

Android SDK and AVD Managers(Cont’d)

Android SDK and AVD Managers(Cont’d)

Android Emulator Helpful tool used for designing and developingAndroid applicationsRuns on your computerBehaves like a real deviceLoad Android applications into the emulator to testand debug themGeneric device, not tied to any one specificconfigurationValuable, but should not be used as a replacementfor testing on actual target devices

Android Emulator (Cont’d)

Android Emulator (Cont’d)

Exploring the Android SampleApplications Demo applications are not provided as part of the AndroidSDK by default.– Android Studio provides a dialog for importing the sampleapplications—from GitHub—as a project.Android Studio sample applications code categories toinvestigate:–––––––Getting nWearable

Chapter 2Summary We have learned how to install and configurethe tools for Android development.– JDK, SDK, ADT BundleWe have explored many of the tools providedwith the Android SDK.We have reviewed the Android SDK LicenseAgreement.We have learned about important SDKpackages.We have perused the sample applicationsprovided with the SDK.

References and More Information Google’s Android Developers ex.htmlAndroid SDK download site:–http://d.android.com/sdk/index.htmlAndroid SDK License e Java Platform, Standard .jetbrains.com/Android Developer adt.htmlThe Eclipse Project:–http://www.eclipse.org

android.* Android application fundamentals dalvik.* Dalvik virtual machine support classes java.* Core classes and familiar generic utilities javax.* Encryption support junit.* Unit-testing support org.apache.http.* HTTP protocol support org.json JSON support org.w3c.dom W3C DOM XML and HTML support org.xml.* SAX support for XML org.xmlpull.* High-performance XML pull parsing . Popular