Project

General

Profile

SDK » History » Version 30

James Adams, 10/05/2013 03:32 AM

1 1 John Smith
h1. SDK
2
3
The [[ReplicantSDK]] page holds a list of the released Replicant SDK builds.
4
5 25 Paul Kocialkowski
h2. Rationale
6 1 John Smith
7 29 Paul Kocialkowski
Replicant provides its own SDK, built from source, since the Android SDK as released by Google is distributed under a non-free license and suggests installing non-free plug-ins such as the Google APIs.
8
The Replicant SDK contains only free software and will not check for plug-ins or updates from Google.
9 1 John Smith
10 29 Paul Kocialkowski
h2. Installation
11 25 Paul Kocialkowski
12 1 John Smith
After downloading the Replicant SDK from the [[ReplicantSDK]] page, it should work the same as the Android SDK as provided by Google except that the Replicant SDK already contains a built and ready to use emulator image. 
13
Please refer to: http://developer.android.com/sdk/installing/index.html for further assistance. 
14
15 25 Paul Kocialkowski
h3. Dependencies
16
17 29 Paul Kocialkowski
h4. Required Packages
18
19
The Replicant SDK requires the following packages:
20 1 John Smith
* SDL
21 29 Paul Kocialkowski
* OpenJDK 6
22 1 John Smith
23
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.
24
25 29 Paul Kocialkowski
h5. Additional requirements for amd64
26 1 John Smith
27
Note that the Replicant SDK is built for x86 platforms and you may need compatibility libraries such as @ia32-libs@.
28 29 Paul Kocialkowski
29
h4. Command line installation
30
31
h5. Trisquel/Ubuntu/Debian
32
33
Required packages:
34
<pre>
35
apt-get install libsdl1.2debian openjdk-6-jdk
36
</pre>
37
38
Additional requirements for amd64:
39 25 Paul Kocialkowski
<pre>
40
apt-get install ia32-libs
41
</pre>
42 1 John Smith
43 25 Paul Kocialkowski
h2. Usage guides
44 2 John Smith
45 25 Paul Kocialkowski
h3. Using Eclipse
46 1 John Smith
47 25 Paul Kocialkowski
You may want to install Eclipse to work on Android Java applications. Note that this is not strictly necessary as all the required tools are already present on the SDK package. 
48 1 John Smith
49 25 Paul Kocialkowski
h4.  Installing the "Android Development Tools" plugin for Eclipse
50 1 John Smith
51 30 James Adams
The following instructions work with Eclipse 3.7.2 (Indigo) as installed via Apt under Trisquel Toutatis GNU/Linux.
52
<pre>
53
sudo aptitude install eclipse
54
</pre>
55 1 John Smith
56 30 James Adams
Once you have Eclipse installed and running properly, you may want to install the Android Development Tools plugin.
57 1 John Smith
58 30 James Adams
* The Replicant 4 SDK requires ADT version 16. You will need to download it from Google's archives and then manually install it in Eclipse:
59 1 John Smith
60 30 James Adams
http://dl.google.com/android/ADT-16.0.0.zip
61 1 John Smith
62 30 James Adams
* in Eclipse 3.7
63 1 John Smith
64
- select "Window" > "Preferences" > "Install/Update" > "Available Software Sites"
65
- click the "Add" button
66 30 James Adams
- name your software site something recognizable, e.g. "ADT 16.0.0"
67
- click "Archive" and select the "ADT-16.0.0.zip" file
68 1 John Smith
69 30 James Adams
* in Eclipse 3.7
70 1 John Smith
71
- select "Help" > "Install New Software"
72 30 James Adams
- select the "ADT 16.0.0" software site from the dropdown menu
73 1 John Smith
- select the "Developer Tools" software package
74 2 John Smith
- verify that the "Android DDMS" and "Android Development Tools" sub-packages were selected
75
- click the "Next" to install Android Developer Tools
76 25 Paul Kocialkowski
77 1 John Smith
* restart Eclipse
78
79 9 John Smith
h4. Pointing "Android Development Tools" to the SDK directory
80 11 John Smith
81 2 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.
82 12 John Smith
83 30 James Adams
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 4 SDK. Then click "Apply" or "OK".
84 12 John Smith
85 30 James Adams
Next time you enter this dialog, a line saying "Android 4.0.3 / Android Open Source Project / Platform: 4.0.3 / API level: 15" should be present in the list of SDK targets.
86 25 Paul Kocialkowski
87 13 John Smith
h3. Writing a "Hello World" app in Eclipse
88
89
h4. Creating an Android Virtual Device
90
91
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:
92 14 John Smith
93 13 John Smith
- Name: something descriptive like "AVD_for_Nexus_S"
94 30 James Adams
- Target: choose "Android 4.0.3 - API level 15" from the dropdown menu
95 13 John Smith
- SD Card: specify the size of an emulated SD card, alternatively browse for an existing SD card image
96
- Skin: better choose "Default" and the screen resolution of your physical device, e.g. "WVGA800" for Nexus S
97 1 John Smith
- leave other values at defaults and click "Create AVD"
98 14 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
99 17 John Smith
100 14 John Smith
h4. Creating a project
101
102 15 John Smith
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".
103
104
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.
105 16 John Smith
106 15 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.
107 1 John Smith
108 17 John Smith
Leave the minimum SDK version blank. Finally click "Finish" and your project should appear in Eclipse's left-hand projects tree.
109
110
h4. Adding some code and resources into a project
111
112
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:
113
114
<pre>package hello.test;
115
116
import android.app.Activity;
117
import android.os.Bundle;
118
import android.view.View;
119
import android.widget.Button;
120
121
public class MainActivity extends Activity {
122
123
    @Override
124
    public void onCreate(Bundle savedInstanceState) {
125
    	
126
        super.onCreate(savedInstanceState);
127
        setContentView(R.layout.main);
128
        
129
        Button buttonFinish = (Button) findViewById(R.id.buttonFinish);
130
        buttonFinish.setOnClickListener(new View.OnClickListener() {
131
			@Override
132
			public void onClick(View v) {
133
				finish();
134
			}
135
		});
136
    }
137
}</pre>
138
139
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.
140
141
We need to create this resource file now. I would recommend having it be like this:
142
143
<pre><?xml version="1.0" encoding="utf-8"?>
144
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
145
    android:orientation="vertical"
146
    android:layout_width="fill_parent"
147
    android:layout_height="fill_parent"
148
    >
149
<TextView
150
    android:id="@+id/textInfo"
151
    android:layout_width="fill_parent" 
152
    android:layout_height="wrap_content" 
153
    android:text="Click button to close app."
154
    />
155
<Button android:id="@+id/buttonFinish"
156
    android:layout_width="wrap_content"
157 18 John Smith
    android:layout_height="wrap_content"
158 17 John Smith
    android:text="Close" />
159 1 John Smith
</LinearLayout>
160 18 John Smith
</pre>
161 19 John Smith
162 20 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.
163
164
h4. Running the app on an Android Virtual Device
165
166 21 John Smith
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.
167
168
h4. Running the app on a real Replicant device
169 22 John Smith
170
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.
171
172 23 John Smith
2. Enable USB debugging on your device, for example by choosing "Menu" > "Settings" > "Applications" > "Development" and checking the "USB Debugging" checkbox.
173
174
3. Verify that your device is visible. Prior to this, on Windows, you should install the ADB USB driver. On Mac, you should not need to configure anything. On some Linuxes (e.g. Ubuntu), you might need to add uDev rules (consult the "docs/guide/developing/device.html" file in your SDK directory, it contains detailed instructions).
175 24 John Smith
176 23 John Smith
Do the verification by issuing "adb devices" on command line. Make your your ADB (Android Debug Bridge) is included in your PATH variable. If it lists your device and its numeric ID, all should be fine. If it lists "?????????" for the ID and says "No permissions" under Linux, you might need to restart the ADB server (become root and issue: "adb kill-server; adb start-server", this presumes that ADB is also present in the root user's PATH).
177 24 John Smith
178 23 John Smith
4. Run the app. Without a customized run configuration, Eclipse should display the "Android Device Chooser" dialog, letting you choose. 
179
180 1 John Smith
5. Optionally, configure automatic deployment: if you want to automatically deploy to devices when they're attached, create a run configuration for your app, proceeding to select "Deployment Target Selection Mode: Automatic" in the "Target" tab.