Android Studio 2.0(2016 年 4 月)

注意:如果您正在针对 N 开发者预览版进行开发,则应使用 Android Studio 2.1 预览版。Android Studio 2.0 不支持定位 N 预览版所需的所有功能。

Instant Run:

  • Android Studio 现在部署全新构建的速度比以往任何时候都快。此外,将增量代码更改推送到模拟器或物理设备几乎是瞬时的。无需重新部署新的调试构建,在许多情况下也无需重启应用即可查看更新。
  • <li>Instant Run supports pushing the following changes to a running app:
      <ul>
        <li>Changes to the implementation of an existing instance method or
        static method
        </li>
        <li>Changes to an existing app resource
        </li>
        <li>Changes to structural code, such as a method signature or a static
        field (requires a target device running API level 21 or higher).
        </li>
      </ul>
    </li>
    
    <li>Read the documentation to learn more <a href=
    "/tools/building/building-studio.html#instant-run">about Instant
    Run</a>.
      <p class="note">
        <strong>Note:</strong> Instant Run is supported only when you deploy the
        debug build variant, use <a href=
        "/tools/revisions/gradle-plugin.html#revisions">Android plugin for
        Gradle version 2.0.0</a> or higher, and configure your app's module-level
        <code>build.gradle</code> file for <code>minSdkVersion 15</code> or higher.
        For the best performance, configure your app for <code>minSdkVersion
        21</code> or higher.
      </p>
    </li>
    

Lint 的新功能

  • 检查使用 @IntDef 注释的整数的 switch 语句,确保处理所有常量。要快速添加所有缺失的语句,请使用意向操作下拉菜单,然后选择 Add Missing @IntDef Constants
  • 标记在 build.gradle 文件中使用字符串插值插入版本号的不正确尝试。
  • 标记扩展 Fragment 类的匿名类。
  • 标记位于不安全位置的原生代码,例如 res/asset/ 文件夹。此标记鼓励将原生代码存储在 libs/ 文件夹中,以便在安装时将其安全地打包到应用的 data/app-lib/ 文件夹中。AOSP: #169950
  • 标记不安全调用 Runtime.load()System.load() 的调用。AOSP: #179980
  • 从菜单栏中选择 Refactor > Remove Unused Resources,查找并移除所有未使用的资源。未使用的资源检测现在支持仅由未使用资源引用的资源、原始文件(例如 .html 图像引用)中的引用以及 Gradle 资源压缩器使用的 tools:keeptools:discard 属性,同时考虑非活跃的源集(例如在其他构建变体中使用的资源)并正确处理静态字段导入。
  • 检查 minSdkVersion 定位的所有平台是否支持隐式 API 引用。
  • 标记 RecyclerViewParcelable 的不当使用。
  • @IntDef@IntRange@Size 检查现在也针对 int 数组和可变参数进行检查。

其他改进:

  • 针对 Android Emulator 2.0 进行了优化,该模拟器比以往任何时候都更快,支持更广泛的虚拟设备,并且具有大幅改进的 UI。要详细了解新模拟器,请阅读SDK 工具版本说明
  • <li>Improvements to the <a href=
    "/tools/devices/managing-avds.html">Android Virtual Device
    Manager</a>:
      <ul>
        <li>System images are now categorized under the following tabs:
        <em>Recommended</em>, <em>x86</em>, and <em>Other</em>.
        </li>
        <li>Under advanced settings, you can enable multi-core support and
        specify the number of cores the emulator can use.
        </li>
        <li>Under advanced settings, you can determine how graphics are rendered
        on the emulator by selecting one of the following options:
          <ul>
            <li>
              <strong>Hardware:</strong> use you computer's graphics card for
              faster rendering.
            </li>
            <li>
              <strong>Software:</strong> use software-based rendering.
            </li>
            <li>
              <strong>Auto:</strong> let the emulator decide the best option. This
              is the default setting.
            </li>
          </ul>
        </li>
      </ul>
    </li>
    
    <li>Improved AAPT packaging times by specifying deploy target before the app
    is built. This allows Android Studio to efficiently package only the
    resources required by the specified device.
    </li>
    
    <li>Added Cloud Test Lab integration to provide on-demand app testing with
    the convenience and scalability of a cloud service. Learn more about how you
    can <a href="/training/testing/start/index.html#run-ctl">use Cloud
    Test Lab with Android Studio</a>.
    </li>
    
    <li>Added a preview of the new <a class="external-link" href=
    "//tools.android.com/tech-docs/gpu-profiler">GPU Debugger</a>. For graphics
    intensive applications, you can now visually step through your OpenGL ES code
    to optimize your app or game.
    </li>
    
    <li>Added Google App Indexing Test. Add support for URLs, app
    indexing, and search functionality to your apps to help drive more
    traffic to your app, discover which app content is used most, and attract
    new users. Test and validate URLs in your app all within Android
    Studio. See <a href=
    "/tools/help/app-link-indexing.html">Supporting URLs and App
      Indexing in Android Studio</a>.
    </li>
    
    <li>Upgrades from the latest IntelliJ 15 release, including improved code
    analysis and performance. See <a class="external-link" href=
    "https://www.jetbrains.com/idea/whatsnew">What's New in IntelliJ</a> for a
    complete description of the new features and enhancements.
    </li>
    
    <li>XML editor auto-complete now adds quotations marks when completing
    attributes. To check if this option is enabled, open the <b>Setting</b> or
    <b>Preferences</b> dialogue, navigate to <b>Editor &gt; General &gt; Smart
    Keys</b>, and check the box next to <b>Add quotes for attribute value on
    attribute completion</b>. <a class="external-link" href=
    "//b.android.com/195113">Issue: 195113</a>
    </li>
    
    <li>The XML editor now supports code completion for <a href=
    "/topic/libraries/data-binding/index.html#layout_details">data binding</a>
    expressions.
    </li>