diff --git a/docs/html/images/tools/studio-inspections-config.png b/docs/html/images/tools/studio-inspections-config.png new file mode 100644 index 0000000000000..e41afa16b519a Binary files /dev/null and b/docs/html/images/tools/studio-inspections-config.png differ diff --git a/docs/html/tools/debugging/debugging-ui.jd b/docs/html/tools/debugging/debugging-ui.jd index f927d08c7347b..cf7e3ba8b7a88 100644 --- a/docs/html/tools/debugging/debugging-ui.jd +++ b/docs/html/tools/debugging/debugging-ui.jd @@ -34,17 +34,17 @@ parent.link=index.html

Related videos

  1. -
  2. -
  3. @@ -52,11 +52,10 @@ parent.link=index.html -

    -Sometimes your application's layout can slow down your application. - To help debug issues in your layout, the Android SDK provides the Hierarchy Viewer and - lint tools. -

    + +

    Sometimes your application's layout can slow down your application. +To help debug issues in your layout, the Android SDK provides the Hierarchy Viewer and +lint tools.

    The Hierarchy Viewer application allows you to debug and optimize your user interface. It provides a visual representation of the layout's View hierarchy (the View Hierarchy window) @@ -64,8 +63,10 @@ Sometimes your application's layout can slow down your application. and a magnified view of the display (the Pixel Perfect window) to closely examine the pixels in your layout.

    -

    Android lint is a static code scanning tool that helps you optimize the layouts and layout - hierarchies of your applications, as well as detect other common coding problems. You can run it against your layout files or resource +

    Android lint is a static code + scanning tool that helps you optimize the layouts and layout + hierarchies of your applications, as well as detect other common coding problems. You can run it + against your layout files or resource directories to quickly check for inefficiencies or other types of problems that could be affecting the performance of your application.

    @@ -493,7 +494,10 @@ Sometimes your application's layout can slow down your application. alt="" height="600"/>

    Figure 4. The Pixel Perfect window

    + +

    Using lint to Optimize Your UI

    -

    The Android {@code lint} tool lets you analyze the XML files that define your application's UI to find inefficiencies in the view hierarchy.

    -

    Note: The Android layoutopt tool has been replaced by the {@code lint} tool beginning in ADT and SDK Tools revision 16. The {@code lint} tool reports UI layout performance issues in a similar way as layoutopt, and detects additional problems.

    -

    For more information about using {@code lint}, see Improving Your Code with lint and the lint reference documentation.

    +

    The Android lint tool lets you analyze the XML +files that define your application's UI to find inefficiencies in the view hierarchy.

    +

    Note: The Android layoutopt tool has been replaced by the {@code lint} tool beginning in SDK Tools revision 16. The {@code lint} tool reports UI layout performance issues in a similar way as layoutopt, and detects additional problems.

    +

    For more information about using {@code lint}, see Improving Your Code with lint and the lint tools help.

    diff --git a/docs/html/tools/debugging/improving-w-lint.jd b/docs/html/tools/debugging/improving-w-lint.jd index 7e238fa5a86fc..ff94b7f6bc938 100644 --- a/docs/html/tools/debugging/improving-w-lint.jd +++ b/docs/html/tools/debugging/improving-w-lint.jd @@ -9,11 +9,11 @@ parent.link=index.html
    1. Overview
    2. -
    3. Running lint from Eclipse
    4. +
    5. Running lint from Android Studio
    6. Running lint from the command-line
    7. Configuring lint
        -
      1. Configuring lint in Eclipse
      2. +
      3. Configuring lint in Android Studio
      4. Configuring the lint file
      5. Configuring lint checking in Java and XML source files
      @@ -31,8 +31,15 @@ parent.link=index.html In addition to testing that your Android application meets its functional requirements, it's important to ensure that your code has no structural problems. Poorly structured code can impact the reliability and efficiency of your Android apps and make your code harder to maintain. For example, if your XML resource files contain unused namespaces, this takes up space and incurs unnecessary processing. Other structural issues, such as use of deprecated elements or API calls that are not supported by the target API versions, might lead to code failing to run correctly.

      Overview

      -

      The Android SDK provides a code scanning tool called {@code lint} that can help you to easily identify and correct problems with the structural quality of your code, without having to execute the app or write any test cases. Each problem detected by the tool is reported with a description message and a severity level, so that you can quickly prioritize the critical improvements that need to be made. You can also configure a problem's severity level to ignore issues that are not relevant for your project, or raise the severity level. The tool has a command-line interface, so you can easily integrate it into your automated testing process.

      -

      The {@code lint} tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. You can run {@code lint} from the command-line or from the Eclipse environment.

      +

      The Android SDK provides a code scanning tool called lint +that can help you to easily identify and correct problems with the structural quality of your code, without having to execute the app or write any test cases. Each problem detected by the tool is reported with a description message and a severity level, so that you can quickly prioritize the critical improvements that need to be made. You can also configure a problem's severity level to ignore issues that are not relevant for your project, or raise the severity level. The tool has a command-line interface, so you can easily integrate it into your automated testing process.

      +

      The {@code lint} tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. You can run {@code lint} from the command-line or from Android Studio.

      + +

      Note: In Android Studio, additional +IntelliJ code inspections run when your code is compiled in Android Studio to +streamline code review.

      +

      Figure 1 shows how the {@code lint} tool processes the application source files.

      Figure 1. Code scanning workflow with the {@code lint} tool

      @@ -42,25 +49,51 @@ In addition to testing that your Android application meets its functional requir
      The lint.xml file
      A configuration file that you can use to specify any {@code lint} checks that you want to exclude and to customize problem severity levels.
      The {@code lint} tool
      -
      A static code scanning tool that you can run on your Android project from the command-line or from Eclipse. The {@code lint} tool checks for structural code problems that could affect the quality and performance of your Android application. It is strongly recommended that you correct any errors that {@code lint} detects before publishing your application.
      +
      A static code scanning tool that you can run on your Android project from the command-line or Android Studio. The {@code lint} tool checks for structural code problems that could affect the quality and performance of your Android application. It is strongly recommended that you correct any errors that {@code lint} detects before publishing your application.
      Results of {@code lint} checking
      -
      You can view the results from {@code lint} in the console or in the Lint Warnings view in Eclipse. Each issue is identified by the location in the source files where it occurred and a description of the issue.
      +
      You can view the results from {@code lint} in the console or in the Event Log in Android Studio. Each issue is identified by the location in the source files where it occurred and a description of the issue.
      -

      The {@code lint} tool is automatically installed as part of the Android SDK Tools revision 16 or higher. If you want to use {@code lint} in the Eclipse environment, you must also install the Android Development Tools (ADT) Plugin for Eclipse revision 16 or higher. For more information about installing the SDK or the ADT Plugin for Eclipse, see Installing the SDK.

      +

      The {@code lint} tool is automatically installed as part of the Android SDK Tools revision 16 or higher.

      + + +

      Running lint in Android Studio

      +

      In Android Studio, the configured lint and +IDE inspections run automatically whenever you build your app. The IDE inspections are +configured along with the {@code lint} checks to run +IntelliJ code inspections to streamline code review.

      + +

      Note: To view and modify inspection severity +levels, use the File > Settings > Project Settings menu to open the +Inspection Configuration page with a list of the supported inspections.

      + + +

      With Android Studio, you can also run {@code lint} inspections for a specific build variant, +or for all build variants from the build.gradle file. Add the +lintOptions property to the android settings in the build file. +This code snippet from a Gradle build file shows how to set the quiet option to +true and the abortOnError option to false.

      + +
      +android {
      +    lintOptions {
      +       // set to true to turn off analysis progress reporting by lint
      +       quiet true
      +       // if true, stop the gradle build if errors are found
      +       abortOnError false
      +       // if true, only report errors
      +       ignoreWarnings true
      +       }
      +       ...
      +    }
      +
      + + +

      To manually run inspections in Android Studio, from the application or right-click menu, +choose Analyze > Inspect Code. The Specify Inspections Scope dialog +appears so you can specify the desired inspection scope and profile.

      + -

      Running lint from Eclipse

      -

      If the ADT Plugin is installed in your Eclipse environment, the {@code lint} tool runs automatically when you perform one of these actions:

      -
        -
      • Export an APK
      • -
      • Edit and save an XML source file in your Android project (such as a manifest or layout file)
      • -
      • Use the layout editor in Eclipse to make changes
      • -
      -

      Note that when you export an APK, {@code lint} only runs an automatic check for fatal errors and aborts the export if fatal errors are found. You can turn off this automatic checking from the Lint Error Checking page in Eclipse Preferences.

      -

      The output is displayed in the Lint Warnings view. If the Lint Warnings view is not showing in the workbench, you can bring it up from the Eclipse menu by clicking Window > Show View > Other > Android > Lint Warnings.

      -

      Figure 2 shows an example of the output in the Lint Warnings view.

      - -

      Figure 2. Sample output in the Lint Warnings view

      -

      You can also run a {@code lint} scan manually on your Android project in Eclipse by right-clicking on the project folder in the Package Explorer > Android Tools > Run Lint: Check for Common Errors.

      Running lint from the Command-Line

      @@ -96,38 +129,45 @@ res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMiss

      By default, when you run a {@code lint} scan, the tool checks for all issues that are supported by {@code lint}. You can also restrict the issues for {@code lint} to check and assign the severity level for those issues. For example, you can disable {@code lint} checking for specific issues that are not relevant to your project and configure {@code lint} to report non-critical issues at a lower severity level.

      You can configure {@code lint} checking at different levels:

        -
      • Globally, for all projects
      • -
      • Per project
      • -
      • Per file
      • -
      • Per Java class or method (by using the @SuppressLint annotation), or per XML element (by using the tools:ignore attribute.
      • +
      • Globally, for the entire project
      • +
      • Per project module
      • +
      • Per production module
      • +
      • Per test module
      • +
      • Per open files
      • +
      • Per class hierarchy
      • +
      • Per Version Control System (VCS) scopes
      -

      Configuring lint in Eclipse

      -

      You can configure global, project-specific, and file-specific settings for {@code lint} from the Eclipse user interface.

      +

      Configuring lint in Android Studio

      +

      Android Studio allows you to enable or disable individual inspections and configure +project-global, directory-specific, and file-specific settings for {@code lint}.

      + +

      You can manage inspection profiles and configure inspection severity within Android Studio using +the File > Settings > Project Settings menu to open the Inspections +page with a list of the supported profiles and inspections.

      +

      +

      Figure 3. Inspection Configuration

      Global preferences

        -
      1. Open Window > Preferences > Android > Lint Error Checking.
      2. -
      3. Specify your preferences and click OK.
      4. -
      -

      These settings are applied by default when you run {@code lint} on your Android projects in Eclipse.

      +
    8. To specify global project settings, select the project folder in the Project View and choose +Analyze > Inspect Code.
    9. -

      Project and file-specific preferences

      -
        -
      1. Run the {@code lint} tool on your project by right-clicking on your project folder in the Package Explorer and selecting Android Tools > Run Lint: Check for Common Errors. This action brings up the Lint Warnings view which displays a list of issues that {@code lint} detected in your project.
      2. -
      3. From the Lint Warnings view, use the toolbar options to configure {@code lint} preferences for individual projects and files in Eclipse. The options you can select include: -
          -
        • Suppress this error with an annotation/attribute - If the issue appears in a Java class, the {@code lint} tool adds a @SuppressLint annotation to the method where the issue was detected. If the issue appears in an {@code .xml} file, {@code lint} inserts a tools:ignore attribute to disable checking for the {@code lint} issue in this file.
        • -
        • Ignore in this file - Disables checking for this {@code lint} issue in this file.
        • -
        • Ignore in this project - Disables checking for this {@code lint} issue in this project.
        • -
        • Always ignore - Disables checking for this {@code lint} issue globally for all projects.
        • -
        -
      4. +
      5. Specify your inspection scope and profile, and click OK.
      -

      If you select the second or third option, the {@code lint} tool automatically generates a lint.xml file with these configuration settings in your Android application project folder.

      +

      The configured settings run the specified {@code lint} inspections. The {@code lint} +inspections are also run whenever you build and run your Android project and modules.

      + +

      Module and file-specific preferences

      +
        +
      1. Run the {@code lint} tool on your module by right-clicking on your module folder or file in the Project View and selecting Analyze > Inspect Code. This displays the {@code lint} inspection results +with a list of issues that {@code lint} detected in your module.
      2. +
      3. From the Lint Warnings view, use the toolbar options to configure {@code lint} preferences for individual modules and files, and set the issue display options.
      4. +
      +

      Configuring the lint file

      -

      You can specify your {@code lint} checking preferences in the lint.xml file. If you are creating this file manually, place it in the root directory of your Android project. If you are configuring {@code lint} preferences in Eclipse, the lint.xml file is automatically created and added to your Android project for you.

      +

      You can specify your {@code lint} checking preferences in the lint.xml file. If you are creating this file manually, place it in the root directory of your Android project. If you are configuring {@code lint} preferences in Android Studio, the lint.xml file is automatically created and added to your Android project for you.

      The lint.xml file consists of an enclosing <lint> parent tag that contains one or more children <issue> elements. Each <issue> is identified by a unique id attribute value, which is defined by {@code lint}.

       <?xml version="1.0" encoding="UTF-8"?>
      @@ -165,12 +205,9 @@ res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMiss
       

      Configuring lint checking in Java and XML source files

      You can disable {@code lint} checking from your Java and XML source files.

      -

      Tip: If you are using Eclipse, you can use the Quick Fix feature to automatically add the annotation or attribute to disable {@code lint} checking to your Java or XML source files: -

        -
      1. Open the Java or XML file that has a {@code lint} warning or error in an Eclipse editor.
      2. -
      3. Move your cursor to the location in the file where is {@code lint} issue is found, then press Ctrl+1 to bring up the Quick Fix pop-up.
      4. -
      5. From the Quick Fix pop-up, select the action to add an annotation or attribute to ignore the {@code lint} issue.
      6. -
      +

      Tip: If you are using Android Studio, you can use the +File > Settings > Project Settings > Inspections feature to manage the +{@code lint} checking to your Java or XML source files.

      Configuring lint checking in Java

      diff --git a/docs/html/tools/help/lint.jd b/docs/html/tools/help/lint.jd index ba31f6d6bc1c2..0f52689b33426 100644 --- a/docs/html/tools/help/lint.jd +++ b/docs/html/tools/help/lint.jd @@ -14,14 +14,23 @@ parent.link=index.html -

      The Android {@code lint} tool is a static code analysis tool that checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization.

      -

      For more information on running {@code lint}, see Improving Your Code with lint.

      +

      The Android {@code lint} tool is a static code analysis tool that checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization.

      -

      Syntax

      +

      In Android Studio, the configured lint and other IDE inspections run automatically +whenever you compile your program. You can also manually run inspections in Android Studio +by selecting Analyze > Inspect Code from the application or right-click menu. +The Specify Inspections Scope dialog appears so you can specify the desired inspection +profile and scope.

      + +

      For more information on enabling {@code lint} inspections and running {@code lint}, +see Improving Your Code with lint.

      + +

      Command Line Syntax

      lint [flags] <project directory>
      -For example, you can issue the following command to scan the Java and XML files under the {@code myproject} directory and its subdirectories. The result is displayed on the console. +For example, you can issue the following command to scan the Java and XML files under the +{@code myproject} directory and its subdirectories. The result is displayed on the console.
      lint myproject
      You can also use {@code lint} to check for a specific issue. For example, you can run the following command to scan the files under the {@code myproject} directory and its subdirectories to check for XML attributes missing the Android namespace prefix. The issue ID {@code MissingPrefix} tells lint to only scan for this issue. @@ -172,7 +181,11 @@ You can create an HTML report for the issues that {@code lint} detects. For exam

      Configuring Java and XML Source Files

      To configure lint checking, you can apply the following annotation or attribute to the source files in your Android project.

        -
      • To disable lint checking for a specific Java class or method, use the @SuppressLint annotation.
      • -
      • To disable lint checking for specific sections of your XML file, use the tools:ignore attribute.
      • +
      • To disable {@code lint} checking for a specific Java class or method, use the @SuppressLint +annotation.
      • +
      • To disable {@code lint} checking for specific sections of your XML file, use the +tools:ignore attribute.
      -

      You can also specify your lint checking preferences for a specific Android project in the lint.xml file. For more information on configuring lint, see Improving Your Code with lint.

      +

      You can also specify your {@code lint} checking preferences for a specific Android project in +the lint.xml file. For more information on configuring {@code lint}, see +Improving Your Code with lint.

      diff --git a/docs/html/tools/studio/index.jd b/docs/html/tools/studio/index.jd index 11c1c74249ed8..f5c3629e0f92f 100644 --- a/docs/html/tools/studio/index.jd +++ b/docs/html/tools/studio/index.jd @@ -36,7 +36,7 @@ Android Studio offers:

    10. Build variants and multiple apk file generation
    11. Code templates to help you build common app features
    12. Rich layout editor with support for drag and drop theme editing
    13. -
    14. Lint tools to catch performance, usability, version compatibility, and other problems
    15. +
    16. {@code lint} tools to catch performance, usability, version compatibility, and other problems
    17. ProGuard and app-signing capabilities
    18. Built-in support for Memory Monitor +

      Memory Monitor

      Android Studio provides a memory monitor view so you can more easily monitor your app's memory usage to find deallocated objects, locate memory leaks and track the amount of memory the connected device is using. With your app running on a device or emulator, click the @@ -255,33 +255,81 @@ memory the connected device is using. With your app running on a device or emula -

      Lint inspections

      -

      The Android {@code lint} tool is a static code analysis tool that checks your Android project -source files for potential bugs and optimization improvements. Choose the Analyze > -Inspect Code to manually run the inspections. The {@code lint} settings icon in the -Inspection display provides a complete list of the current inspections.

      +

      Code Inspections

      +

      In Android Studio, the configured lint and +other IDE inspections run automatically whenever you compile your program. In addition to the +configured {@code lint} checks, additional +IntelliJ code inspections +run to streamline code review.

      -

      Hovering over a Lint error displays the full issue explanation inline for easy error + +

      Android Studio enables several lint checks +to ensure: +

        +
      • Cipher.getInstance() is used with safe values
      • +
      • In 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 validation
      • +
      • Required API version
      • +
      • many others
      • +
      + + +

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

      -

      With Android Studio, you can run Lint for a specific build variant, or for all build variants. -You can configure Lint by adding a lintOptions property to the Android settings in the -build.gradle file.

      +

      With Android Studio, you can also run {@code lint} inspections for a specific build variant, or +for all build variants. You can configure the {@code lint} inspections that run by adding a +lintOptions property to the Android settings in the build.gradle +file.

      + +
      +android {
      +    lintOptions {
      +       // set to true to turn off analysis progress reporting by lint
      +       quiet true
      +       // if true, stop the gradle build if errors are found
      +       abortOnError false
      +       // if true, only report errors
      +       ignoreWarnings true
      +    }
      +
      + + +

      You can also manage inspection profiles and configure inspections within Android Studio. +Choose File > Settings > Project Settings. 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, for example from warning +to error.

      + + +

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

      + + + +

      Running Inspections from the command line

      +

      You can also run {@code lint} inspections from the command line in your SDK directory.

      +
      +sdk$ lint [flags] 
      +
      + +

      Note: The {@code lint} --show and --list +flags can be used to display the available issues and explanations.

      -
      -    android {
      -        lintOptions {
      -           // set to true to turn off analysis progress reporting by lint
      -           quiet true
      -           // if true, stop the gradle build if errors are found
      -           abortOnError false
      -           // if true, only report errors
      -           ignoreWarnings true
      -    

      For more information, see -Improving Your Code with Lint.

      +Improving Your Code with {@code lint} and +lint tool.

      Dynamic layout preview

      @@ -346,6 +394,7 @@ types.

      For easy cross-platform development, the Project Wizard provides new templates for creating your apps for Android Wear and 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 for your project.

      @@ -519,7 +568,8 @@ and <animated-selector>, are supported.

      Easy access to Android code samples on GitHub

      -

      Clicking Import Samples from the File menu or Welcome page +

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

      Figure 13. Code Sample Access

      diff --git a/docs/html/training/improving-layouts/optimizing-layout.jd b/docs/html/training/improving-layouts/optimizing-layout.jd index 520ce5677ae33..003e7a2312781 100644 --- a/docs/html/training/improving-layouts/optimizing-layout.jd +++ b/docs/html/training/improving-layouts/optimizing-layout.jd @@ -126,13 +126,15 @@ layout is used for every item in a list.

      Most of this time difference is due to the use of {@code layout_weight} in the {@link android.widget.LinearLayout} design, which can slow down the speed of measurement. It is just one -example of how each layout has appropriate uses and you should carefully consider whether using +example of how each layout has appropriate uses and you should carefully consider whether using layout weight is necessary.

      Use Lint

      -

      It is always good practice to run the Lint tool on your layout files to search for possible view hierarchy optimizations. Lint has replaced the Layoutopt tool and has much greater functionality. Some examples of Lint It is always good practice to run the lint +tool on your layout files to search for possible view hierarchy optimizations. Lint has replaced +the Layoutopt tool and has much greater functionality. Some examples of lint rules are:

        @@ -143,11 +145,18 @@ href="http://tools.android.com/tips/lint-checks">rules are:

      • Deep layouts - Layouts with too much nesting are bad for performance. Consider using flatter layouts such as {@link android.widget.RelativeLayout} or {@link android.widget.GridLayout} to improve performance. The default maximum depth is 10.
      -

      Another benefit of Lint is that it is integrated into the Android Development Tools for Eclipse (ADT 16+). Lint automatically runs whenever you export an APK, edit and save an XML file or use the Layout Editor. To manually force Lint to run press the Lint button in the Eclipse toolbar.

      +

      Another benefit of Lint is that it is integrated into Android Studio. Lint automatically runs +whenever you compile your program. With Android Studio, you can also run lint inspections for a +specific build variant, or for all build variants.

      - +

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

      +

      +

      Figure 5. Inspection Configuration

      -

      When used inside Eclipse, Lint has the ability to automatically fix some issues, provide suggestions for others and jump directly to the offending code for review. If you don’t use Eclipse for your development, Lint can also be run from the command line. More information about Lint is available at tools.android.com.

      +

      Lint has the ability to automatically fix some issues, provide suggestions for others and jump +directly to the offending code for review.