12
IN THIS DOCUMENT Project and File Structure Android Build System Debug and Performance Installation, Setup, and Update Management HTTP Proxy Settings Other Highlights SEE ALSO IntelliJ FAQ on migrating to IntelliJ IDEA Android Studio Overview Android Studio is the official IDE for Android application development, based on IntelliJ IDEA (https://www.jetbrains.com/idea/) . On top of the capabilities you expect from IntelliJ, Android Studio offers: Flexible Gradle-based build system Build variants and multiple apk file generation Code templates to help you build common app features Rich layout editor with support for drag and drop theme editing lint tools to catch performance, usability, version compatibility, and other problems ProGuard and app-signing capabilities Built-in support for Google Cloud Platform , making it easy to integrate Google Cloud Messaging and App Engine And much more Download Android Studio now (/sdk/index.html) . If you're new to Android Studio or the IntelliJ IDEA interface, this page provides an introduction to some key Android Studio features. For specific Android Studio how-to documentation, see the pages in the Workflow (/tools/workflow/index.html) section, such as Managing Projects from Android Studio (/tools/projects/projects-studio.html) and Building and Running from Android Studio (/tools/building/building-studio.html) . Project and File Structure Android Project View By default, Android Studio displays your profile files in the Android project view. This view shows a flattened version of your project's structure that provides quick access to the key source files of Android projects and helps you work with the Gradle-based build system (/sdk/installing/studio-build.html) . The Android project view: Groups the build files for all modules at the top level of the project hierarchy. Shows the most important source directories at the top level of the module hierarchy. Groups all the manifest files for each module. Shows resource files from all Gradle source sets. Groups resource files for different locales, orientations, and screen types in a single group per resource type. Figure 1. Show the Android project view.

Android Studio Overview _ Android Developers

  • Upload
    gilbedt

  • View
    89

  • Download
    2

Embed Size (px)

DESCRIPTION

nada de nada

Citation preview

  • IN THIS DOCUMENT

    Project and File StructureAndroid Build SystemDebug and PerformanceInstallation, Setup, andUpdate ManagementHTTP Proxy SettingsOther Highlights

    SEE ALSO

    IntelliJ FAQ on migrating toIntelliJ IDEA

    Android Studio OverviewAndroid Studio is the official IDE for Android application development, basedon IntelliJ IDEA (https://www.jetbrains.com/idea/) . On top of the capabilities youexpect from IntelliJ, Android Studio offers:

    Flexible Gradle-based build systemBuild variants and multiple apk file generationCode templates to help you build common app featuresRich layout editor with support for drag and drop theme editinglint tools to catch performance, usability, version compatibility, and otherproblemsProGuard and app-signing capabilitiesBuilt-in support for Google Cloud Platform , making it easy to integrateGoogle Cloud Messaging and App EngineAnd much more

    Download Android Studio now (/sdk/index.html).

    If you're new to Android Studio or the IntelliJ IDEA interface, this page providesan introduction to some key Android Studio features.

    For specific Android Studio how-to documentation, see the pages in the Workflow (/tools/workflow/index.html) section, such asManaging Projects from Android Studio (/tools/projects/projects-studio.html) and Building and Running from Android Studio(/tools/building/building-studio.html).

    Project and File Structure

    Android Project View

    By default, Android Studio displays your profile files in the Android project view. This view shows a flattened version ofyour project's structure that provides quick access to the key source files of Android projects and helps you work with theGradle-based build system (/sdk/installing/studio-build.html). The Android project view:

    Groups the build files for all modules at the top level of the project hierarchy.Shows the most important source directories at the top level of the module hierarchy.Groups all the manifest files for each module.Shows resource files from all Gradle source sets.Groups resource files for different locales, orientations, and screen types in a single group per resource type.

    Figure 1. Show the Android project view.

    http://confluence.jetbrains.com/display/IntelliJIDEA/FAQ+on+Migrating+to+IntelliJ+IDEAhttp://developers.google.com/cloud/devtools/android_studio_templates/https://developer.android.com/tools/projects/projects-studio.htmlhttps://developer.android.com/tools/workflow/index.htmlhttps://developer.android.com/tools/building/building-studio.htmlhttps://developer.android.com/sdk/installing/studio-build.htmlhttps://developer.android.com/sdk/index.htmlhttps://www.jetbrains.com/idea/

  • Figure 2. Project Build Files.

    The Android project view shows all the build files at the top level of the project hierarchy under Gradle Scripts. Each projectmodule appears as a folder at the top level of the project hierarchy and contains these three elements at the top level:

    java/ - Source files for the module.manifests/ - Manifest files for the module.res/ - Resource files for the module.

    For example, Android project view groups all the instances of the ic_launcher.png resource for different screen densitiesunder the same element.

    Note: The project structure on disk differs from this flattened representation. To switch to back to the segregatedproject view, select Project from the Project drop-down.

    Android Studio Project and Directory Structure

    When you use the Project view of a new project in Android Studio, you should notice that the project structure appearsdifferent than you may be used to in Eclipse. Each instance of Android Studio contains a project with one or moreapplication modules. Each application module folder contains the complete source sets for that module, includingsrc/main and src/androidTest directories, resources, build file and the Android manifest. For the most part, you willneed to modify the files under each module's src/main directory for source code updates, the gradle.build file for buildspecification and the files under src/androidTest directory for test case creation.

    Figure 3. Android Studio project structure

    For more information, see IntelliJ project organization (http://confluence.jetbrains.com/display/IntelliJIDEA/Project+Organization) andManaging Projects (/tools/projects/index.html).

    http://confluence.jetbrains.com/display/IntelliJIDEA/Project+Organizationhttps://developer.android.com/tools/projects/index.html

  • Creating new files

    You can quickly add new code and resource files by clicking the appropriate directory in the Project pane and pressing ALT+INSERT on Windows and Linux or COMMAND+N on Mac. Based on the type of directory selected, Android Studio offersto create the appropriate file type.

    For example, if you select a layout directory, press ALT+INSERT on Windows, and select Layout resource file, a dialogopens so you can name the file (you can exclude the .xml suffix) and choose a root view element. The editor thenswitches to the layout design editor so you can begin designing your layout.

    Android Build System

    Android Build System

    The Android build system is the toolkit you use to build, test, run and package your apps. This build system replaces theAnt system used with Eclipse ADT. It can run as an integrated tool from the Android Studio menu and independently fromthe command line. You can use the features of the build system to:

    Customize, configure, and extend the build process.Create multiple APKs for your app with different features using the same project and modules.Reuse code and resources across source sets.

    The flexibility of the Android build system enables you to achieve all of this without modifying your app's core source files.To build an Android Studio project, see Building and Running from Android Studio (/tools/building/building-studio.html). Toconfigure custom build settings in an Android Studio project, see Configuring Gradle Builds (/tools/building/configuring-gradle.html).

    Application ID for Package Identification

    With the Android build system, the applicationId attribute is used to uniquely identify application packages for publishing.The application ID is set in the android section of the build.gradle file.

    applyplugin:'com.android.application'

    android{compileSdkVersion19buildToolsVersion"19.1"

    defaultConfig{applicationId"com.example.my.app"minSdkVersion15targetSdkVersion19versionCode1versionName"1.0"}...

    Note: The applicationId is specified only in your build.gradle file, and not in the AndroidManifest.xml file.

    When using build variants, the build system enables you to uniquely identify different packages for each product flavorsand build types. The application ID in the build type is added as a suffix to those specified for the product flavors.

    productFlavors{pro{applicationId="com.example.my.pkg.pro"}free{applicationId="com.example.my.pkg.free"}}

    buildTypes{debug{applicationIdSuffix".debug"

    https://developer.android.com/tools/building/configuring-gradle.htmlhttps://developer.android.com/tools/building/building-studio.html

  • }}....

    The package name must still be specified in the manifest file. It is used in your source code to refer to your R class and toresolve any relative activity/service registrations.

    package="com.example.app">

    Note: If you have multiple manifests (for example, a product flavor specific manifest and a build type manifest), thepackage name is optional in those manifests. If it is specified in those manifests, the package name must be identical tothe package name specified in the manifest in the src/main/ folder.

    For more information about the build files and process, see Build System Overview (/sdk/installing/studio-build.html).

    Debug and Performance

    Android Virtual Device (AVD) Manager

    AVD Manager has updated screens with links to help you select the most popular device configurations, screen sizes andresolutions for your app previews.

    Click the Android Virtual Device Manager in the toolbar to open it and create new virtual devices for running your app inthe emulator.

    The AVD Manager comes with emulators for Nexus 6 and Nexus 9 devices and also supports creating custom Androiddevice skins based on specific emulator properties and assigning those skins to hardware profiles. Android Studio installsthe Intel x86 Hardware Accelerated Execution Manager (HAXM) emulator accelerator and creates a default emulator forquick app prototyping.

    For more information, see Managing AVDs (/tools/devices/managing-avds.html).

    Memory Monitor

    Android Studio provides a memory monitor view so you can more easily monitor your app's memory usage to finddeallocated objects, locate memory leaks and track the amount of memory the connected device is using. With your apprunning on a device or emulator, click the Memory Monitor tab in the lower right corner to launch the memory monitor.

    Figure 5. Memory Monitor

    Code Inspections

    In Android Studio, the configured lint (/tools/help/lint.html) and other IDE inspections run automatically whenever youcompile your program. In addition to the configured lint checks, additional IntelliJ code inspections(https://www.jetbrains.com/idea/help/inspection-basics.html?search=inspection) run to streamline code review.

    Android Studio enables several lint checks to ensure:

    https://developer.android.com/tools/help/lint.htmlhttps://developer.android.com/tools/devices/managing-avds.htmlhttps://www.jetbrains.com/idea/help/inspection-basics.html?search=inspectionhttps://developer.android.com/sdk/installing/studio-build.html

  • Cipher.getInstance() is used with safe valuesIn custom Views, the associated declare-styleable for the custom view uses the same base name as the class name.Security check for fragment injection.Where ever property assignment no longer works as expected.Gradle plugin version is compatible with the SDK.Right to left validationRequired API versionmany others

    Hovering over an inspection error displays the full issue explanation inline for easy error resolution. There is also a helpfulhyperlink at the end of the error message for additional error information.

    With Android Studio, you can also run lint inspections for a specific build variant, or for all build variants. You canconfigure the lint inspections that run by adding a lintOptions property to the Android settings in the build.gradlefile.

    android{lintOptions{//settotruetoturnoffanalysisprogressreportingbylintquiettrue//iftrue,stopthegradlebuildiferrorsarefoundabortOnErrorfalse//iftrue,onlyreporterrorsignoreWarningstrue}

    You can also manage inspection profiles and configure inspections within Android Studio. Choose File > Settings > ProjectSettings. The Inspection Configuration page appears with the supported inspections.

    Figure 5. Inspection Configuration

    Note: If you wish to change the behavior of specific inspection notifications, you can change the inspection severity, forexample from warning to error.

    To manually run inspections in Android Studio, choose Analyze > Inspect Code. The Inspections Scope dialog appears soyou can specify the desired inspection profile and scope.

    Running Inspections from the command line

    You can also run lint inspections from the command line in your SDK directory.

  • sdk$lint[flags]

    Note: The lint --show and --list flags can be used to display the available issues and explanations.

    For more information, see Improving Your Code with lint (/tools/debugging/improving-w-lint.html) and lint tool (/tools/help/lint.html).

    Dynamic layout preview

    Android Studio allows you to work with layouts in both a Design View

    Figure 6. Hello World App with Design View

    and a Text View.

    Figure 7. Hello World App with Text View

    Easily select and preview layout changes for different device images, display densities, UI modes, locales, and Androidversions (multi-API version rendering).

    https://developer.android.com/tools/debugging/improving-w-lint.htmlhttps://developer.android.com/tools/help/lint.html

  • Figure 8. API Version Rendering

    From the Design View, you can drag and drop elements from the Palette to the Preview or Component Tree. The Text Viewallows you to directly edit the XML settings, while previewing the device display.

    Log messages

    When you build and run your app with Android Studio, you can view adb and device log messages (logcat) in the DDMSpane by clicking Android at the bottom of the window.

    If you want to debug your app with the Android Debug Monitor (/tools/help/monitor.html), you can launch it by clicking Monitor in the toolbar. The Debug Monitor is where you can find the complete set of DDMS (/tools/debugging/ddms.html) tools for

    profiling your app, controlling device behaviors, and more. It also includes the Hierarchy Viewer tools to help optimize yourlayouts (/tools/debugging/debugging-ui.html).

    Installation, Setup, and Update Management

    Android Studio installation and setup wizards

    An updated installation and setup wizards walk you through a step-by-step installation and setup process as the wizardchecks for system requirements, such as the Java Development Kit (JDK) and available RAM, and then prompts foroptional installation options, such as the Intel HAXM emulator accelerator.

    An updated setup wizard walks you through the setup processes as the wizard updates your system image and emulationrequirements, such GPU, and then creates an optimized default Android Virtual Device (AVD) based on Android 5 (Lollipop)for speedy and reliable emulation.

    https://developer.android.com/tools/debugging/debugging-ui.htmlhttps://developer.android.com/tools/help/monitor.htmlhttps://developer.android.com/tools/debugging/ddms.html

  • Figure 9. Setup Wizard

    Expanded template and form factor support

    Android Studio supports templates for Google Services and expands the available device types.

    Android Wear and TV support

    For easy cross-platform development, the Project Wizard provides new templates for creating your apps for Android Wearand TV.

    Figure 10. Supported Form Factors

    During app creation, the Project Wizard also displays an API Level dialog to help you choose the best minSdkVersion foryour project.

    Google App Engine integration (Google Cloud Platform/Messaging)

    Quick cloud integration. Using Google App Engine to connect to the Google cloud and create a cloud end-point is as easyas selecting File > New Module > App Engine Java Servlet Module and specifying the module, package, and client names.

  • Figure 11. Setup Wizard

    Update channels

    Android Studio provides four update channels to keep Android Studio up-to-date based on your code-level preference:

    Canary channel: Canary builds provide bleeding edge releases, updated about weekly. While these builds do get tested,they are still subject to bugs, as we want people to see what's new as soon as possible. This is not recommended forproduction.Dev channel: Dev builds are hand-picked older canary builds that survived the test of time. They are updated roughly bi-weekly or monthly.Beta channel: Beta builds are used for beta-quality releases before a production release.Stable channel: Used for stable, production-ready versions.

    By default, Android Studio uses the Stable channel. Use File > Settings > Updates to change your channel setting.

    Proxy Settings

    Proxies serve as intermediary connection points between HTTP clients and web servers that add security and privacy tointernet connections.

    To support running Android Studio behind a firewall, set the proxy settings for the Android Studio IDE and the SDKManager. Use the Android Studio IDE HTTP Proxy settings page to set the HTTP proxy settings for Android Studio. TheSDK Manager has a separate HTTP Proxy settings page.

    When running the Android Plugin for Gradle from the command line or on machines where Android Studio is not installed,such as continuous integration servers, set the proxy settings in the Gradle build file.

    Note: After the initial installation of the Android Studio bundle, Android Studio can run with internet access or off-line.However, Android Studio requires an internet connection for Setup Wizard synchronization, 3rd-party library access,access to remote repositories, Gradle initialization and synchronization, and Android Studio version updates.

    Setting up the Android Studio Proxy

    Android Studio supports HTTP proxy settings so you can run Android Studio behind a firewall or secure network. To setthe HTTP proxy settings in Android Studio:

    1. From the main menu choose File > Settings > IDE Setting -- HTTP Proxy.2. In Android Studio, open the IDE Settings dialog.

    On Windows and Linux, choose File > Settings > IDE Setting -- HTTP Proxy.On Mac, choose Android Studio > Preferences > IDE Setting -- HTTP Proxy.The HTTP Proxy page appears.

    3. Select auto-detection to use an auto-configuration URL to configure the proxy settings or manual to enter each of

  • the settings. For a detailed explanation of these settings, see HTTP Proxy.4. Click Apply to enable the proxy settings.

    Android Plugin for Gradle HTTP proxy settings

    When running the Android Plugin from the command line or on machines where Android Studio is not installed, set theAndroid Plugin for Gradle proxy settings in the Gradle build file.

    For application-specific HTTP proxy settings, set the proxy settings in the build.gradle file as required for each applicationmodule.

    applyplugin:'com.android.application'

    android{...

    defaultConfig{...systemProp.http.proxyHost=proxy.company.comsystemProp.http.proxyPort=443systemProp.http.proxyUser=useridsystemProp.http.proxyPassword=passwordsystemProp.http.auth.ntlm.domain=domain}...}

    For project-wide HTTP proxy settings, set the proxy settings in the gradle/gradle.properties file.

    #ProjectwideGradlesettings....

    systemProp.http.proxyHost=proxy.company.comsystemProp.http.proxyPort=443systemProp.http.proxyUser=usernamesystemProp.http.proxyPassword=passwordsystemProp.http.auth.ntlm.domain=domain

    systemProp.https.proxyHost=proxy.company.comsystemProp.https.proxyPort=443systemProp.https.proxyUser=usernamesystemProp.https.proxyPassword=passwordsystemProp.https.auth.ntlm.domain=domain

    ...

    For information about using Gradle properties for proxy settings, see the Gradle User Guide(http://www.gradle.org/docs/current/userguide/build_environment.html).

    Note: When using Android Studio, the settings in the Android Studio IDE HTTP proxy settings page override the HTTPproxy settings in the gradle.properties file.

    SDK Manager HTTP Proxy Settings

    SDK Manager proxy settings enable proxy internet access for Android package and library updates from SDK Managerpackages.

    To set the SDK Manager settings for proxy internet access, start the SDK Manager and open the SDK Manager page.

    On Windows, select Tools > Options from the menu bar.On Mac and Linux, choose Tools > Options from the system menu bar.

    The Android SDK Manager page appears. Enter the settings and click Apply.

    Other Highlights

    http://www.gradle.org/docs/current/userguide/build_environment.htmlhttps://www.jetbrains.com/idea/help/http-proxy.html

  • Translation Editor

    Multi-language support is enhanced with the Translation Editor plugin so you can easily add locales to the app'stranslation file. Color codes indicate whether a locale is complete or still missing string translations. Also, you can use theplugin to export your strings to the Google Play Developer Console for translation, then download and import yourtranslations back into your project.

    To access the Translation Editor, open a strings.xml file and click the Open Editor link.

    Figure 12. Translation Editor

    Editor support for the latest Android APIs

    Android Studio supports the Material Design (/design/material/index.html) themes, widgets, and graphics, such as shadowlayers and API version rendering (showing the layout across different UI versions). Also, the drawable XML tags andattributes, such as and , are supported.

    Easy access to Android code samples on GitHub

    Clicking Import Samples from the File menu or Welcome page provides seamless access to Google code samples onGitHub.

    Figure 13. Code Sample Access

    https://developer.android.com/design/material/index.html

  • Figure 14. Imported Code Sample