1page.title=Importing Legacy Apps into Android Studio
2meta.tags="android, performance, profiling, tools"
3page.tags="android", "performance", "profiling", "tools"
4page.metaDescription=Required changes when importing legacy apps into Android Studio.
5page.article=true
6
7@jd:body
8
9<div id="tb" style="margin-left: 7px; margin-bottom: 5px;">
10
11<h2>In this document</h2>
12<ul>
13  <li><a href="#WhatYouNeed">Prerequisites</a></li>
14  <li><a href="#StepsForImporting">Steps for Importing</a></li>
15</ul>
16
17<h2>You should also read</h2>
18<ul>
19  <li><a href="/tools/device.html">Using Hardware Devices</a></li>
20  <li><a href="/tools/help/index.html">Tools</a></li>
21</ul>
22
23</div>
24
25
26  <p>Importing some pre-Android-1.0 projects into Android 1.0 or newer can trigger a series of
27  errors. This document shows you how to resolve them, using a version of the Sunshine app used in
28  the <a href="https://www.udacity.com/course/ud853">Android Fundamentals Udacity Course</a> as an
29  example.</p>
30
31  <p><b>CAVEAT:</b> As with all documentation of this kind, the details are likely to vary for each
32  application and each update of Android Studio.</p>
33
34  <h2 id="WhatYouNeed">Prerequisites</h2>
35
36  <ul>
37    <li>The latest version of <a href="http://developer.android.com/sdk/index.html">Android
38    Studio</a> (this document uses version 1.1).</li>
39
40    <li>It helps to know how to <a href="https://developer.android.com/training/index.html">build
41    and run apps from Android Studio</a> on your device.</li>
42
43    <li>To use Sunshine, you need to download code from <a href=
44    "https://github.com/">github.com</a>. More info at <a href=
45    "https://help.github.com/">help.github.com</a>.</li>
46  </ul>
47
48  <h2 id="StepsForImporting">Steps for Importing Sunshine into Android Studio 1.1.0</h2>
49
50  <ol>
51    <li>Download Sunshine ZIP from GitHub: <a href=
52    "https://github.com/udacity/sunshine/tree/6.10-update-map-intent">https://github.com/udacity/sunshine/tree/6.10-update-map-intent</a>.
53    (If you are having any problems with Android Studio or the app, use the following version, or
54    your own app, to follow along with the example.<a href=
55    "https://github.com/udacity/sunshine/tree/3.13-add-share-action-provider">https://github.com/udacity/sunshine/tree/3.13-add-share-action-provider</a>)
56
57    <li>Unzip the application to extract the code folder.</li>
58
59    <li>Start Android Studio. (This works best if you close all projects, then restart.)</li>
60
61    <li>Click <b>Import</b> <b>project (Eclipse ADT, Gradle, etc.)</b>.
62      <br><img src="{@docRoot}images/tools/performance/import_image001.png">
63    </li>
64
65    <li>In the popup, find and select the Sunshine-6-10-updated-map-intent folder and click
66      <b>OK</b>.
67      <br><img src="{@docRoot}images/tools/performance/import_image002.png">
68    </li>
69
70    <li>If prompted, choose a destination folder for your project. If prompted to choose a build
71    system, choose Gradle. (These prompts vary, depending on your project and Android Studio
72    version.) If you need more guidance, see this <a href=
73    "http://www.lynda.com/articles/eclipse-into-android-studio">Lynda tutorial</a>.</li>
74
75    <li>Wait for the import to complete. If you see no errors, you are now ready to work with your
76    app.
77
78    <p><b>If you get a Gradle error:</b></p>
79
80    <li>If you get a Gradle error, you have some extra work to do.(Because the Import
81    didn&#40t finish, at this point, you may only see the <b>Gradle
82    Scripts</b> directory in your Project view.)</li>
83
84    <li>You may see the link <b>Install missing platform(s) and sync
85    project</b>, or a link to install missing build tools.
86    Click whatever link and
87    proceed.</li>
88
89    <li>The next time through, your build will fail with:
90      <br><img src="{@docRoot}images/tools/performance/import_image003.png">
91    </li>
92
93    <li>Click the <b>Fix plugin version and re-import project</b> link
94    in the error message. This will rebuild the app and present you with new of errors.
95      <br><img src="{@docRoot}images/tools/performance/import_image004.png">
96    </li>
97
98    <li>Click the <b>Gradle Settings</b> link in the error message.</li>
99
100    <li>Check the <b>Use auto-import</b> and click <b>OK</b>.
101      <br><img src="{@docRoot}images/tools/performance/import_image005.png">
102    </li>
103
104    <li>Expand the project hierarchy and find the <b>build.gradle file</b>.The file you are looking
105      for is not the one showing at the top level, but the one inside <b>Sunshine</b> <b>&gt;</b>
106      <b>app &gt; build.gradle</b>, as shown below.
107      <br><img src="{@docRoot}images/tools/performance/import_image006.png">
108   </li>
109
110    <li>Double-click the <code>build.gradle</code> file.</li>
111
112    <li>Make the following changes to the file:</li>
113      <ul>
114        <li>Set <code>compileSdkVersion 21</code></li>
115
116        <li>Set <code>targetSdkVersion 21</code></li>
117
118        <li>Replace <code>runProguard</code> with <code>minifyEnabled</code></li>
119      </ul>
120
121      <p>Your file should look like this: </p>
122        <img src="{@docRoot}images/tools/performance/import_image007.png">
123    </li>
124
125    <li>Save (Ctrl-S).</li>
126
127  <p>For the following two messages (Steps 18/19), what you see might vary. You might see either
128  message or both messages in sequence. Click the appropriate links to continue until the Language
129  Level Changed dialog opens.</p>
130
131    <li>In the code view bar, click the <b>Try again</b> link.
132      <br><img src="{@docRoot}images/tools/performance/import_image008.png">
133    </li>
134
135    <li>If you see these warnings, click the <b>Sync now</b> link.
136      <br><img src="{@docRoot}images/tools/performance/import_image009.png">
137    </li>
138
139    <li>In the Language Level Changed dialog, click <b>Yes</b>. And if you get the Gradle Running
140      dialog, <b>Yes</b> again.
141      <br><img src="{@docRoot}images/tools/performance/import_image010.png">
142    </li>
143
144    <li>After the project reloads, run the app on your device. (If it crashes the first time, try
145    again, and it will run.)
146    <br><img src="{@docRoot}images/tools/performance/import_image011.png">
147    </li>
148  </ol>
149
150