• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Support Library Setup
2
3@jd:body
4
5
6<div id="qv-wrapper">
7  <div id="qv">
8
9    <h2>In this document</h2>
10    <ol>
11      <li><a href="#download">Downloading the Support Library</a></li>
12      <li><a href="#choosing">Choosing Support Libraries</a></li>
13      <li><a href="#add-library">Adding Support Libraries</a></li>
14      <li><a href="#using-apis">Using Support Library APIs</a>
15        <ol>
16          <li><a href="#manifest">Manifest Declaration Changes</a></li>
17        </ol>
18      </li>
19    </ol>
20
21    <h2>See also</h2>
22    <ol>
23      <li><a href="{@docRoot}tools/support-library/index.html#revisions">
24        Support Library Revisions</a></li>
25      <li><a href="{@docRoot}tools/support-library/features.html">
26        Support Library Features</a></li>
27    </ol>
28
29  </div>
30</div>
31
32<p>How you setup the Android Support Libraries in your development project depends on what features
33  you want to use and what range of Android platform versions you want to support with your
34  application.</p>
35
36<p>This document guides you through downloading the Support Library package and adding libraries
37  to your development environment.</p>
38
39
40<h2 id="download">Downloading the Support Libraries</h2>
41
42<p>The Android Support Repository package is provided as a supplemental download
43 to the Android SDK and is available through the Android
44  <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a>. Follow the
45  instructions below to obtain the Support Library files.
46</p>
47
48<p>To download the Support Library through the SDK Manager:</p>
49
50<ol>
51  <li>Start the Android <a href="{@docRoot}tools/help/sdk-manager.html">SDK Manager</a>.</li>
52  <li>In the SDK Manager window, scroll to the end of the <em>Packages</em> list,
53    find the <em>Extras</em> folder and, if necessary, expand to show its contents.</li>
54  <li>Select the <strong>Android Support Repository</strong> item.</li>
55  <li>Click the <strong>Install packages...</strong> button.</li>
56</ol>
57
58<img src="{@docRoot}images/tools/sdk-manager-support-libs.png" width="525" alt="" />
59<p class="img-caption"><strong>Figure 1.</strong> The Android SDK Manager with
60Android Support Repository selected.</p>
61
62<p>After downloading, the tool installs the Support Library files to your existing Android SDK
63  directory. The library files are located in the following subdirectory of your SDK:
64  <code>&lt;sdk&gt;/extras/android/m2repository/com/android/support/</code>
65  directory.</p>
66
67
68<h2 id="choosing">Choosing Support Libraries</h2>
69
70<p>Before adding a Support Library to your application, decide what features you want to include
71  and the lowest Android versions you want to support. For more information on the features
72  provided by the different libraries, see
73  <a href="{@docRoot}tools/support-library/features.html">Support Library Features</a>.</p>
74
75
76<h2 id="add-library">Adding Support Libraries</h2>
77
78<p>In order to use a Support Library, you must modify your application's project's
79  classpath dependencies within your development environment. You must perform this procedure for
80  each Support Library you want to use.</p>
81
82<p>To add a Support Library to your application project:</p>
83
84    <ol>
85      <li>Make sure you have downloaded the <strong>Android Support Repository</strong>
86        using the <a href="#download">SDK Manager</a>.</li>
87      <li>Open the {@code build.gradle} file for your application.</li>
88      <li>Add the support library to the {@code dependencies} section. For
89        example, to add the v4 core-utils library, add the following lines:
90<pre>
91dependencies {
92    ...
93    <b>compile "com.android.support:support-core-utils:24.2.0"</b>
94}
95</pre>
96      </li>
97    </ol>
98
99<p class="caution">
100  <strong>Caution:</strong> Using dynamic dependencies (for example,
101  <code>palette-v7:23.0.+</code>) can cause unexpected version updates and
102  regression incompatibilities. We recommend that you explicitly specify a
103  library version (for example, <code>palette-v7:24.2.0</code>).
104</p>
105
106<h2 id="using-apis">Using Support Library APIs</h2>
107
108<p>Support Library classes that provide support for existing framework APIs typically have the
109  same name as framework class but are located in the <code>android.support</code> class packages,
110  or have a <code>*Compat</code> suffix.</p>
111
112<div class="caution">
113  <p><strong>Caution:</strong> When using classes from the Support Library, be certain you import
114    the class from the appropriate package. For example, when applying the {@code ActionBar}
115    class:</p>
116  <ul>
117    <li>{@code android.support.v7.app.ActionBar} when using the Support Library.</li>
118    <li>{@code android.app.ActionBar} when developing only for API level 11 or higher.</li>
119  </ul>
120</div>
121
122<p class="note">
123  <strong>Note:</strong> After including the Support Library in your application project, we
124  strongly recommend using the
125  <a href="{@docRoot}tools/help/proguard.html">ProGuard</a> tool to prepare your application APK
126  for release. In addition to protecting your source code, the ProGuard tool also removes unused
127  classes from any libraries you include in your application, which keeps the download size of
128  your application as small as possible. For more information, see
129  <a href="{@docRoot}tools/help/proguard.html">ProGuard</a>.
130</p>
131
132<p>Further guidance for using some Support Library features is provided in the Android developer
133  <a href="{@docRoot}training/index.html">training classes</a>,
134  <a href="{@docRoot}guide/components/index.html">guides</a>
135  and samples. For more information about the individual Support Library classes and methods, see
136  the {@link android.support.v4.app android.support} packages in the API reference.
137</p>
138
139
140<h3 id="manifest">Manifest Declaration Changes</h3>
141
142<p>If you are increasing the backward compatibility of your existing application to an earlier
143  version of the Android API with the Support Library, make sure to update your application's
144  manifest. Specifically, you should update the <code>android:minSdkVersion</code>
145  element of the <a href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">
146  <code>&lt;uses-sdk&gt;</code></a> tag in the manifest to the new, lower version number, as
147  shown below:</p>
148
149<pre>
150  &lt;uses-sdk
151      android:minSdkVersion="<b>14</b>"
152      android:targetSdkVersion="23" /&gt;
153</pre>
154
155<p>The manifest setting tells Google Play that your application can be installed on devices with Android
156  4.0 (API level 14) and higher.  </p>
157
158<p>If you are using Gradle build files, the <code>minSdkVersion</code> setting in the build file
159  overrides the manifest settings.  </p>
160
161<pre>
162apply plugin: 'com.android.application'
163
164android {
165    ...
166
167    defaultConfig {
168        minSdkVersion 16
169        ...
170    }
171    ...
172}
173</pre>
174
175<p>In this case, the build file setting tells Google Play that the default build variant of your
176  application can be installed on devices with Android 4.1 (API level 16) and higher. For more
177  information about build variants, see
178  <a href="{@docRoot}studio/build/index.html">Build System Overview</a>. </p>
179
180<p class="note">
181  <strong>Note:</strong> If you are including several support libraries, the
182  minimum SDK version must be the <em>highest</em> version required by any of
183  the specified libraries. For example, if your app includes both the <a href=
184  "features.html#v14-preference">v14 Preference Support library</a> and the
185  <a href="features.html#v17-leanback">v17 Leanback library</a>, your minimum
186  SDK version must be 17 or higher.
187</p>
188