SDK » History » Revision 19
« Previous |
Revision 19/62
(diff)
| Next »
John Smith, 03/30/2012 05:02 PM
SDK¶
Rationale¶
Replicant uses its own SDK, which differs notably from the default Android SDK, as the latter contains non-free components.
[TODO: it might be helpful to try to list those, and summarize their functionality]
Obtaining the Replicant SDK¶
The Replicant SDK can be obtained via FTP from:
http://ftp.osuosl.org/pub/replicant/sdk/0001/
Installing the Replicant SDK¶
Dependencies¶
Java Development Kit (JDK)¶
You need a computer with a Java SE (Standard Edition) development kit version 1.6 or greater installed.
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.
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.
Eclipse¶
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.
Installing the "Android Development Tools" plugin for Eclipse¶
If you have Eclipse installed and running properly, you need to install the Android Development Tools plugin.
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.
A somewhat manual solution:
- download ADT 0.9.8 into a stable location in your computer
http://dl.google.com/android/ADT-0.9.8.zip
Size: 8301417 B
MD5: 27e0de800512f13feae46fb554e6ee2f
- in Eclipse 3.5
- select "Window" > "Preferences" > "Install/Update" > "Available Software Sites"
- click the "Add" button
- name your software site something recognizable, e.g. "ADT 0.9.8"
- click "Archive" and select the "ADT-0.9.8.zip" file
- in Eclipse 3.5
- select "Help" > "Install New Software"
- select the "ADT 0.9.8" software site from the dropdown menu
- select the "Developer Tools" software package
- verify that the "Android DDMS" and "Android Development Tools" sub-packages were selected
- click the "Next" to install Android Developer Tools
- restart Eclipse
Pointing "Android Development Tools" to the SDK directory¶
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.
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.
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".
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.
Writing a "Hello World" app¶
Creating an Android Virtual Device¶
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:
- Name: something descriptive like "AVD_for_Nexus_S"
- Target: choose "Android 2.2.1 - API level 8" from the dropdown menu
- SD Card: specify the size of an emulated SD card, alternatively browse for an existing SD card image
- Skin: better choose "Default" and the screen resolution of your physical device, e.g. "WVGA800" for Nexus S
- leave other values at defaults and click "Create AVD"
- if your disk is slow and you specified a large SD card image for creation, it may take a few seconds to complete
Creating a project¶
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".
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.
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.
Leave the minimum SDK version blank. Finally click "Finish" and your project should appear in Eclipse's left-hand projects tree.
Adding some code and resources into a project¶
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:
package hello.test; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button buttonFinish = (Button) findViewById(R.id.buttonFinish); buttonFinish.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } }
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.
We need to create this resource file now. I would recommend having it be like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/textInfo" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Click button to close app." /> <Button android:id="@+id/buttonFinish" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Close" /> </LinearLayout>
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.
Updated by John Smith over 12 years ago · 19 revisions