SDK » History » Version 22
John Smith, 03/30/2012 05:45 PM
1 | 1 | John Smith | h1. SDK |
---|---|---|---|
2 | |||
3 | h2. Rationale |
||
4 | |||
5 | Replicant uses its own SDK, which differs notably from the default Android SDK, as the latter contains non-free components. |
||
6 | |||
7 | [TODO: it might be helpful to try to list those, and summarize their functionality] |
||
8 | |||
9 | h2. Obtaining the Replicant SDK |
||
10 | |||
11 | The Replicant SDK can be obtained via FTP from: |
||
12 | |||
13 | http://ftp.osuosl.org/pub/replicant/sdk/0001/ |
||
14 | |||
15 | h2. Installing the Replicant SDK |
||
16 | |||
17 | h3. Dependencies |
||
18 | |||
19 | 5 | John Smith | h4. Java Development Kit (JDK) |
20 | 1 | John Smith | |
21 | You need a computer with a Java SE (Standard Edition) development kit version 1.6 or greater installed. |
||
22 | |||
23 | 2 | John Smith | Unless the Java installer for your platform does this automatically (installing an OpenJDK package from a repository under most Linux distributions does this) you may need to add your Java SDK's "bin" directory into your "PATH" environment variable, so that the command "javac" starts when issued from command line. |
24 | 1 | John Smith | |
25 | 6 | John Smith | In some unlikely cases, creating a "JAVA_HOME" environment variable and pointing it to your JDK's true install location (not the "bin" directory but one level upward) may prove necessary. |
26 | 2 | John Smith | |
27 | 3 | John Smith | h4. Eclipse |
28 | 1 | John Smith | |
29 | You also need the Eclipse development environment -- preferably version 3.5. Version 3.6 is cautioned against in SDK documentation, mentioning that it currently has known isses. |
||
30 | |||
31 | 3 | John Smith | h3. Installing the "Android Development Tools" plugin for Eclipse |
32 | 1 | John Smith | |
33 | If you have Eclipse installed and running properly, you need to install the Android Development Tools plugin. |
||
34 | |||
35 | 8 | John Smith | A solution for Eclipse 3.6 (not advised): some documentation recommends adding "https://dl-ssl.google.com/android/eclipse/" as a software update site in Eclipse, and pulling ADT from there. People have observed that this currently results in getting an ADT version which requires Eclipse 3.6, which has known issues and is not available in some widespread Linux distributions (e.g. Debian) at the moment. |
36 | 1 | John Smith | |
37 | A somewhat manual solution: |
||
38 | |||
39 | * download ADT 0.9.8 into a stable location in your computer |
||
40 | |||
41 | http://dl.google.com/android/ADT-0.9.8.zip |
||
42 | Size: 8301417 B |
||
43 | MD5: 27e0de800512f13feae46fb554e6ee2f |
||
44 | |||
45 | * in Eclipse 3.5 |
||
46 | |||
47 | - select "Window" > "Preferences" > "Install/Update" > "Available Software Sites" |
||
48 | - click the "Add" button |
||
49 | - name your software site something recognizable, e.g. "ADT 0.9.8" |
||
50 | - click "Archive" and select the "ADT-0.9.8.zip" file |
||
51 | |||
52 | * in Eclipse 3.5 |
||
53 | |||
54 | - select "Help" > "Install New Software" |
||
55 | - select the "ADT 0.9.8" software site from the dropdown menu |
||
56 | - select the "Developer Tools" software package |
||
57 | - verify that the "Android DDMS" and "Android Development Tools" sub-packages were selected |
||
58 | - click the "Next" to install Android Developer Tools |
||
59 | |||
60 | 2 | John Smith | * restart Eclipse |
61 | |||
62 | 1 | John Smith | h3. Pointing "Android Development Tools" to the SDK directory |
63 | |||
64 | 9 | John Smith | When you have installed ADT and restarted Eclipse, select the "Window" menu. You should see a menu entry named "Android SDK and AVD Manager". Then select "Preferences" from the "Window" menu. A menu item named "Android" should be available on the left panel. |
65 | 3 | John Smith | |
66 | 11 | John Smith | If not, something is wrong. You might have the wrong flavour of Eclipse installed (the Classic, Java or RCP flavours are recommended). For example, it has been observed that the default Eclipse version which installs under Debian 6.0 ("squeeze") does not install ADT correctly, while an installation of Eclipse Classic 3.5.2 ("Galileo") downloaded from http://archive.eclipse.org/eclipse/downloads/drops/R-3.5.2-201002111343/download.php?dropFile=eclipse-SDK-3.5.2-linux-gtk.tar.gz (MD5: bde55a2354dc224cf5f26e5320e72dac) works fine. |
67 | 2 | John Smith | |
68 | 12 | John Smith | Once the "Android" menu item is available in the "Window" > "Preferences" dialog, select it. In the main panel, click the "Browse" button for the "SDK Location" field, and point it to the directory where you unzipped your Replicant SDK. Then click "Apply" or "OK". |
69 | |||
70 | Next time you enter this dialog, a line saying "Android 2.2.1 / Android Open Source Project / Platform: 2.2.1 / API level: 8" should be present in the list of SDK targets. |
||
71 | |||
72 | 13 | John Smith | h3. Writing a "Hello World" app |
73 | |||
74 | h4. Creating an Android Virtual Device |
||
75 | |||
76 | To run your app in an emulator, you need to create an Android Virtual Device. In Eclipse, choose "Window" > "Android SDK and AVD Manager" > "Virtual Devices" > "New" and fill in the properties of the virtual device as follows: |
||
77 | |||
78 | 14 | John Smith | - Name: something descriptive like "AVD_for_Nexus_S" |
79 | 13 | John Smith | - Target: choose "Android 2.2.1 - API level 8" from the dropdown menu |
80 | - SD Card: specify the size of an emulated SD card, alternatively browse for an existing SD card image |
||
81 | - Skin: better choose "Default" and the screen resolution of your physical device, e.g. "WVGA800" for Nexus S |
||
82 | - leave other values at defaults and click "Create AVD" |
||
83 | 1 | John Smith | - if your disk is slow and you specified a large SD card image for creation, it may take a few seconds to complete |
84 | 14 | John Smith | |
85 | 17 | John Smith | h4. Creating a project |
86 | 14 | John Smith | |
87 | In Eclipse, choose "File" > "New" > "Project". In the tree of possible project types, a branch named "Android" should exist. Open it, select the project type "Android Project" and click "Next". |
||
88 | 15 | John Smith | |
89 | Enter a name for your project, e.g. "hello". For "Content", select "Create new project in workspace" and "use default location". The project will be created in your local Eclipse workspace directory, in a subdirectory corresponding to the project name. |
||
90 | |||
91 | 16 | John Smith | Besides the project name, enter a friendly name for your application, e.g. "Hello World". Enter its package name, which can be either public (e.g. "com.example.hello") or private (e.g. "hello.test"). If you want the first piece of your application's user interface to be auto-created, leave the "Create Activity" checkbox checked and enter someting like "MainActivity" for the name of the "Activity" class to create. |
92 | 15 | John Smith | |
93 | 1 | John Smith | Leave the minimum SDK version blank. Finally click "Finish" and your project should appear in Eclipse's left-hand projects tree. |
94 | 17 | John Smith | |
95 | h4. Adding some code and resources into a project |
||
96 | |||
97 | To have your application's MainActivity class do something, consider adding some code. For example, you might want your application to have a button which closes it. In this sample, we specify the design of user interface elements in a separate XML resource file, so don't be surprised when you don't see anything related to their design here: |
||
98 | |||
99 | <pre>package hello.test; |
||
100 | |||
101 | import android.app.Activity; |
||
102 | import android.os.Bundle; |
||
103 | import android.view.View; |
||
104 | import android.widget.Button; |
||
105 | |||
106 | public class MainActivity extends Activity { |
||
107 | |||
108 | @Override |
||
109 | public void onCreate(Bundle savedInstanceState) { |
||
110 | |||
111 | super.onCreate(savedInstanceState); |
||
112 | setContentView(R.layout.main); |
||
113 | |||
114 | Button buttonFinish = (Button) findViewById(R.id.buttonFinish); |
||
115 | buttonFinish.setOnClickListener(new View.OnClickListener() { |
||
116 | @Override |
||
117 | public void onClick(View v) { |
||
118 | finish(); |
||
119 | } |
||
120 | }); |
||
121 | } |
||
122 | }</pre> |
||
123 | |||
124 | You may notice how the constructor of MainActivity calls "setContentView(R.layout.main)". In this statement, R is a special resource class, pointing to resources hosted in the "res" directory of your project. The "layout" class limits the choice to layout resources hosted under the "res/layout" while "main" is the name of a layout resource file "main.xml" located there. |
||
125 | |||
126 | We need to create this resource file now. I would recommend having it be like this: |
||
127 | |||
128 | <pre><?xml version="1.0" encoding="utf-8"?> |
||
129 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||
130 | android:orientation="vertical" |
||
131 | android:layout_width="fill_parent" |
||
132 | android:layout_height="fill_parent" |
||
133 | > |
||
134 | <TextView |
||
135 | android:id="@+id/textInfo" |
||
136 | android:layout_width="fill_parent" |
||
137 | android:layout_height="wrap_content" |
||
138 | android:text="Click button to close app." |
||
139 | /> |
||
140 | <Button android:id="@+id/buttonFinish" |
||
141 | android:layout_width="wrap_content" |
||
142 | android:layout_height="wrap_content" |
||
143 | 18 | John Smith | android:text="Close" /> |
144 | 17 | John Smith | </LinearLayout> |
145 | 1 | John Smith | </pre> |
146 | 18 | John Smith | |
147 | 19 | John Smith | Together, it makes sense. The "LinearLayout" element directs the application to fill the screen with its window ("fill_parent" for width and height). The "TextView" element displays a text field expanding to cover window width, but limits itself to content height ("wrap_content"). The "Button" element is a button named "buttonFinish", big enough to accommodate its content. Code obtains a handle to it by calling "Button buttonFinish = (Button) findViewById(R.id.buttonFinish);"), and creates an event listener for its OnClick event. This event listener calls "finish()" to close the app. |
148 | 20 | John Smith | |
149 | h4. Running the app on an Android Virtual Device |
||
150 | |||
151 | Once you've coded your app, choose "Run" > "Run" in Eclipse. A dialog named "Android Device Chooser" will open, asking you to choose a device for it. Select the "Launch a new Android Virtual Device" checkbox and the virtual device you previously made, should become available for selection (select it and click "OK"). The virtual device will start booting up and will eventually run your app. Beware, on slow computers (e.g. an old model of Asus EEE PC) this can take minutes. |
||
152 | 21 | John Smith | |
153 | h4. Running the app on a real Replicant device |
||
154 | |||
155 | 22 | John Smith | 1. Declare your app as debuggable. In the left-hand sidebar of Eclipse, your project's resource tree should contain a file resource named "AndroidManifest.xml". Right-click it and choose "Open With". Proceed by choosing either "Android Manifest Editor" or "Text Editor". If you preferred the manifest editor GUI, select the tab "Application" at its bottom. On the "Application" tab, set the field "Debuggable" to "true". If you preferred the text editor, append the property "android:debuggable="true" to the "<application>" element. |
156 | |||
157 | 2. Enable USB debugging on your device, for example by choosing "Menu" > "Settings" > "Applications" > "Development" and checking the "USB Debugging" checkbox. |