summaryrefslogtreecommitdiff
path: root/docs/html/topic/libraries/support-library/setup.jd
blob: adb263cbcd9a1bf8f9af453407f059e2e0a6b44c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
80
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
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
page.title=Support Library Setup

@jd:body


<div id="qv-wrapper">
  <div id="qv">

    <h2>In this document</h2>
    <ol>
      <li><a href="#download">Downloading the Support Library</a></li>
      <li><a href="#choosing">Choosing Support Libraries</a></li>
      <li><a href="#add-library">Adding Support Libraries</a></li>
      <li><a href="#using-apis">Using Support Library APIs</a>
        <ol>
          <li><a href="#manifest">Manifest Declaration Changes</a></li>
        </ol>
      </li>
    </ol>

    <h2>See also</h2>
    <ol>
      <li><a href="{@docRoot}tools/support-library/index.html#revisions">
        Support Library Revisions</a></li>
      <li><a href="{@docRoot}tools/support-library/features.html">
        Support Library Features</a></li>
    </ol>

  </div>
</div>

<p>How you setup the Android Support Libraries in your development project depends on what features
  you want to use and what range of Android platform versions you want to support with your
  application.</p>

<p>This document guides you through downloading the Support Library package and adding libraries
  to your development environment.</p>


<h2 id="download">Downloading the Support Libraries</h2>

<p>The Android Support Repository package is provided as a supplemental download
 to the Android SDK and is available through the Android
  <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a>. Follow the
  instructions below to obtain the Support Library files.
</p>

<p>To download the Support Library through the SDK Manager:</p>

<ol>
  <li>Start the Android <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a>.</li>
  <li>In the SDK Manager window, scroll to the end of the <em>Packages</em> list,
    find the <em>Extras</em> folder and, if necessary, expand to show its contents.</li>
  <li>Select the <strong>Android Support Repository</strong> item.</li>
  <li>Click the <strong>Install packages...</strong> button.</li>
</ol>

<img src="{@docRoot}images/tools/sdk-manager-support-libs.png" width="525" alt="" />
<p class="img-caption"><strong>Figure 1.</strong> The Android SDK Manager with
Android Support Repository selected.</p>

<p>After downloading, the tool installs the Support Library files to your existing Android SDK
  directory. The library files are located in the following subdirectory of your SDK:
  <code>&lt;sdk&gt;/extras/android/m2repository/com/android/support/</code>
  directory.</p>


<h2 id="choosing">Choosing Support Libraries</h2>

<p>Before adding a Support Library to your application, decide what features you want to include
  and the lowest Android versions you want to support. For more information on the features
  provided by the different libraries, see
  <a href="{@docRoot}tools/support-library/features.html">Support Library Features</a>.</p>


<h2 id="add-library">Adding Support Libraries</h2>

<p>In order to use a Support Library, you must modify your application's project's
  classpath dependencies within your development environment. You must perform this procedure for
  each Support Library you want to use.</p>

<p>To add a Support Library to your application project:</p>

    <ol>
      <li>Make sure you have downloaded the <strong>Android Support Repository</strong>
        using the <a href="#download">SDK Manager</a>.</li>
      <li>Open the {@code build.gradle} file for your application.</li>
      <li>Add the support library to the {@code dependencies} section. For
        example, to add the v4 core-utils library, add the following lines:
<pre>
dependencies {
    ...
    <b>compile "com.android.support:support-core-utils:24.2.0"</b>
}
</pre>
      </li>
    </ol>

<p class="caution">
  <strong>Caution:</strong> Using dynamic dependencies (for example,
  <code>palette-v7:23.0.+</code>) can cause unexpected version updates and
  regression incompatibilities. We recommend that you explicitly specify a
  library version (for example, <code>palette-v7:24.2.0</code>).
</p>

<h2 id="using-apis">Using Support Library APIs</h2>

<p>Support Library classes that provide support for existing framework APIs typically have the
  same name as framework class but are located in the <code>android.support</code> class packages,
  or have a <code>*Compat</code> suffix.</p>

<div class="caution">
  <p><strong>Caution:</strong> When using classes from the Support Library, be certain you import
    the class from the appropriate package. For example, when applying the {@code ActionBar}
    class:</p>
  <ul>
    <li>{@code android.support.v7.app.ActionBar} when using the Support Library.</li>
    <li>{@code android.app.ActionBar} when developing only for API level 11 or higher.</li>
  </ul>
</div>

<p class="note">
  <strong>Note:</strong> After including the Support Library in your application project, we
  strongly recommend using the
  <a href="{@docRoot}tools/help/proguard.html">ProGuard</a> tool to prepare your application APK
  for release. In addition to protecting your source code, the ProGuard tool also removes unused
  classes from any libraries you include in your application, which keeps the download size of
  your application as small as possible. For more information, see
  <a href="{@docRoot}tools/help/proguard.html">ProGuard</a>.
</p>

<p>Further guidance for using some Support Library features is provided in the Android developer
  <a href="{@docRoot}training/index.html">training classes</a>,
  <a href="{@docRoot}guide/components/index.html">guides</a>
  and samples. For more information about the individual Support Library classes and methods, see
  the {@link android.support.v4.app android.support} packages in the API reference.
</p>


<h3 id="manifest">Manifest Declaration Changes</h3>

<p>If you are increasing the backward compatibility of your existing application to an earlier
  version of the Android API with the Support Library, make sure to update your application's
  manifest. Specifically, you should update the <code>android:minSdkVersion</code>
  element of the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">
  <code>&lt;uses-sdk&gt;</code></a> tag in the manifest to the new, lower version number, as
  shown below:</p>

<pre>
  &lt;uses-sdk
      android:minSdkVersion="<b>14</b>"
      android:targetSdkVersion="23" /&gt;
</pre>

<p>The manifest setting tells Google Play that your application can be installed on devices with Android
  4.0 (API level 14) and higher.  </p>

<p>If you are using Gradle build files, the <code>minSdkVersion</code> setting in the build file
  overrides the manifest settings.  </p>

<pre>
apply plugin: 'com.android.application'

android {
    ...

    defaultConfig {
        minSdkVersion 16
        ...
    }
    ...
}
</pre>

<p>In this case, the build file setting tells Google Play that the default build variant of your
  application can be installed on devices with Android 4.1 (API level 16) and higher. For more
  information about build variants, see
  <a href="{@docRoot}studio/build/index.html">Build System Overview</a>. </p>

<p class="note">
  <strong>Note:</strong> If you are including several support libraries, the
  minimum SDK version must be the <em>highest</em> version required by any of
  the specified libraries. For example, if your app includes both the <a href=
  "features.html#v14-preference">v14 Preference Support library</a> and the
  <a href="features.html#v17-leanback">v17 Leanback library</a>, your minimum
  SDK version must be 17 or higher.
</p>