Project

General

Profile

ReplicantSDKUsage » History » Version 1

Denis 'GNUtoo' Carikli, 01/31/2023 12:17 AM
Move Replicant 4.2 SDK related content from https://redmine.replicant.us/projects/replicant/wiki/SDK

1 1 Denis 'GNUtoo' Carikli
h1. ReplicantSDKUsage
2
3
{{toc}}
4
5
h2. Installation of the Replicant SDK
6
7
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. 
8
Please refer to: http://developer.android.com/sdk/installing/index.html for further assistance. 
9
10
h3. Dependencies
11
12
h4. Required Packages
13
14
The Replicant SDK requires the following packages:
15
* SDL
16
* OpenJDK 6
17
* Ant
18
19
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.
20
21
h5. Additional requirements for amd64
22
23
Note that the Replicant SDK is built for x86 platforms and you may need compatibility libraries such as @ia32-libs@.
24
25
h4. Command line installation
26
27
h5. Trisquel/Ubuntu/Debian
28
29
Required packages:
30
<pre>
31
apt-get install libsdl1.2debian openjdk-6-jdk ant
32
</pre>
33
34
Additional requirements for amd64:
35
<pre>
36
apt-get install ia32-libs
37
</pre>
38
39
40
h2. Rebuilding the SDK from sources
41
42
See [[SDKBuild]].
43
44
45
h2. Usage guides
46
47
h3. Using Eclipse
48
49
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. 
50
51
h4.  Installing the "Android Development Tools" plugin for Eclipse
52
53
The following instructions work with Eclipse 3.7.2 (Indigo) as installed via Apt under Trisquel Toutatis GNU/Linux.
54
<pre>
55
sudo aptitude install eclipse
56
</pre>
57
58
Once you have Eclipse installed and running properly, you may want to install the Android Development Tools plugin.
59
60
* The Replicant 4.0 SDK requires ADT version 16 while the Replicant 4.2 SDK requires ADT version 20. You will need to download it from Google's archives and then manually install it in Eclipse:
61
62
http://dl.google.com/android/ADT-16.0.0.zip
63
http://dl.google.com/android/ADT-20.0.0.zip
64
65
* in Eclipse 3.7
66
67
- select "Window" > "Preferences" > "Install/Update" > "Available Software Sites"
68
- click the "Add" button
69
- name your software site something recognizable, e.g. "ADT"
70
- click "Archive" and select the ADT zip file
71
72
* in Eclipse 3.7
73
74
- select "Help" > "Install New Software"
75
- select the "ADT"/ software site from the dropdown menu
76
- select the "Developer Tools" software package
77
- verify that the "Android DDMS" and "Android Development Tools" sub-packages were selected
78
- click the "Next" to install Android Developer Tools
79
80
* restart Eclipse
81
82
h4. Pointing "Android Development Tools" to the SDK directory
83
84
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.
85
86
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.2 SDK. Then click "Apply" or "OK".
87
88
Next time you enter this dialog, a line saying "Android 4.2.2 / Android Open Source Project / Platform: 4.2.2 / API level: 17" should be present in the list of SDK targets.
89
90
h3. Writing a "Hello World" app in Eclipse
91
92
h4. Creating an Android Virtual Device
93
94
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:
95
96
- Name: something descriptive like "AVD_for_Nexus_S"
97
- Screen resolution of your physical device, e.g. "WVGA800" for Nexus S
98
- Target: choose "Android 4.2.2 - API level 17" from the dropdown menu
99
- SD Card: specify the size of an emulated SD card, alternatively browse for an existing SD card image
100
- leave other values at defaults and click "Create AVD"
101
- if your disk is slow and you specified a large SD card image for creation, it may take a few seconds to complete
102
103
h4. Creating a project
104
105
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 Application Project" and click "Next".
106
107
Enter a friendly name for your application, e.g. "Hello World", then a name for your project, e.g. "hello". Enter its package name, which can be either public (e.g. "com.example.hello") or private (e.g. "hello.test").
108
109
For "Configure", select "Create 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. Leave the minimum SDK version as-is.
110
111
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.
112
113
Finally click "Finish" and your project should appear in Eclipse's left-hand projects tree.
114
115
h4. Adding some code and resources into a project
116
117
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:
118
119
<pre>package hello.test;
120
121
import android.app.Activity;
122
import android.os.Bundle;
123
import android.view.View;
124
import android.widget.Button;
125
126
public class MainActivity extends Activity {
127
128
    @Override
129
    public void onCreate(Bundle savedInstanceState) {
130
    	
131
        super.onCreate(savedInstanceState);
132
        setContentView(R.layout.main);
133
        
134
        Button buttonFinish = (Button) findViewById(R.id.buttonFinish);
135
        buttonFinish.setOnClickListener(new View.OnClickListener() {
136
			@Override
137
			public void onClick(View v) {
138
				finish();
139
			}
140
		});
141
    }
142
}</pre>
143
144
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.
145
146
We need to create this resource file now. I would recommend having it be like this:
147
148
<pre><?xml version="1.0" encoding="utf-8"?>
149
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
150
    android:orientation="vertical"
151
    android:layout_width="fill_parent"
152
    android:layout_height="fill_parent"
153
    >
154
<TextView
155
    android:id="@+id/textInfo"
156
    android:layout_width="fill_parent" 
157
    android:layout_height="wrap_content" 
158
    android:text="Click button to close app."
159
    />
160
<Button android:id="@+id/buttonFinish"
161
    android:layout_width="wrap_content"
162
    android:layout_height="wrap_content"
163
    android:text="Close" />
164
</LinearLayout>
165
</pre>
166
167
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.
168
169
h4. Running the app on an Android Virtual Device
170
171
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.
172
173
h4. Running the app on a real Replicant device
174
175
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.
176
177
2. Enable USB debugging on your device, for example by choosing "Menu" > "Settings" > "Applications" > "Development" and checking the "USB Debugging" checkbox.
178
179
3. Set up [[ADB]] on your PC.
180
181
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@, you might need to restart the ADB server (issue @adb kill-server; adb start-server@).
182
183
4. Run the app. Without a customized run configuration, Eclipse should display the "Android Device Chooser" dialog, letting you choose. 
184
185
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.