Project

General

Profile

SDK » History » Version 45

Denis 'GNUtoo' Carikli, 02/19/2021 11:33 PM
try to fix parabola [1]

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 38 dl lud
Up till version 4.2, Replicant provided 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 29 Paul Kocialkowski
The Replicant SDK contains only free software and will not check for plug-ins or updates from Google.
9 1 John Smith
10 42 Denis 'GNUtoo' Carikli
From Replicant 6.0 onward "there was no longer the need to provide a Replicant SDK":https://blog.replicant.us/2017/04/there-wont-be-a-replicant-6-0-sdk-because-there-is-already-something-better/ because some fully-free GNU/Linux distributions already provide packages for the Android SDK.
11 1 John Smith
12 42 Denis 'GNUtoo' Carikli
| Distribution | Status                                                                 |
13 45 Denis 'GNUtoo' Carikli
| Parabola     | "Work in progress":https://www.parabola.nu/packages/?q=android-sdk [1] |
14
| Trisquel 8   | Has android-sdk packages, probably complete[1]                         |
15
| Trisquel 7   | Has android-sdk packages, probably complete[1]                         |
16 39 dl lud
17 42 Denis 'GNUtoo' Carikli
There is also the "Android Rebuilds":https://android-rebuilds.beuc.net/ project that provides a free Android SDK, built from the Android source code. So it probably works on most of the the GNU/Linux distributions that exist, however, at the time of writing, it is still relied on Google's prebuit toolchain (which is free software) to build the SDK.
18 40 dl lud
19 42 Denis 'GNUtoo' Carikli
fn1. The packages are based based on "android-sdk-meta":https://salsa.debian.org/android-tools-team/android-sdk-meta by the Debian project.
20
21
h2. Installation of the Replicant SDK
22 25 Paul Kocialkowski
23 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. 
24
Please refer to: http://developer.android.com/sdk/installing/index.html for further assistance. 
25
26 25 Paul Kocialkowski
h3. Dependencies
27
28 29 Paul Kocialkowski
h4. Required Packages
29
30
The Replicant SDK requires the following packages:
31 1 John Smith
* SDL
32 29 Paul Kocialkowski
* OpenJDK 6
33 31 Paul Kocialkowski
* Ant
34 1 John Smith
35
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.
36
37 29 Paul Kocialkowski
h5. Additional requirements for amd64
38 1 John Smith
39
Note that the Replicant SDK is built for x86 platforms and you may need compatibility libraries such as @ia32-libs@.
40 29 Paul Kocialkowski
41
h4. Command line installation
42
43
h5. Trisquel/Ubuntu/Debian
44
45
Required packages:
46 1 John Smith
<pre>
47 31 Paul Kocialkowski
apt-get install libsdl1.2debian openjdk-6-jdk ant
48 29 Paul Kocialkowski
</pre>
49
50
Additional requirements for amd64:
51 25 Paul Kocialkowski
<pre>
52
apt-get install ia32-libs
53
</pre>
54 1 John Smith
55 33 Beuc Beuc
56
h2. Rebuilding the SDK from sources
57
58
See [[SDKBuild]].
59
60
61 25 Paul Kocialkowski
h2. Usage guides
62 2 John Smith
63 25 Paul Kocialkowski
h3. Using Eclipse
64 1 John Smith
65 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. 
66 1 John Smith
67 25 Paul Kocialkowski
h4.  Installing the "Android Development Tools" plugin for Eclipse
68 1 John Smith
69 30 James Adams
The following instructions work with Eclipse 3.7.2 (Indigo) as installed via Apt under Trisquel Toutatis GNU/Linux.
70
<pre>
71
sudo aptitude install eclipse
72
</pre>
73 1 John Smith
74 30 James Adams
Once you have Eclipse installed and running properly, you may want to install the Android Development Tools plugin.
75 1 John Smith
76 32 Paul Kocialkowski
* 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:
77 1 John Smith
78
http://dl.google.com/android/ADT-16.0.0.zip
79 32 Paul Kocialkowski
http://dl.google.com/android/ADT-20.0.0.zip
80 1 John Smith
81 30 James Adams
* in Eclipse 3.7
82 1 John Smith
83
- select "Window" > "Preferences" > "Install/Update" > "Available Software Sites"
84
- click the "Add" button
85 32 Paul Kocialkowski
- name your software site something recognizable, e.g. "ADT"
86
- click "Archive" and select the ADT zip file
87 1 John Smith
88 30 James Adams
* in Eclipse 3.7
89 1 John Smith
90
- select "Help" > "Install New Software"
91 32 Paul Kocialkowski
- select the "ADT"/ software site from the dropdown menu
92 1 John Smith
- select the "Developer Tools" software package
93 2 John Smith
- verify that the "Android DDMS" and "Android Development Tools" sub-packages were selected
94
- click the "Next" to install Android Developer Tools
95 25 Paul Kocialkowski
96 1 John Smith
* restart Eclipse
97
98 9 John Smith
h4. Pointing "Android Development Tools" to the SDK directory
99 11 John Smith
100 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.
101 12 John Smith
102 34 Beuc Beuc
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".
103 12 John Smith
104 34 Beuc Beuc
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.
105 25 Paul Kocialkowski
106 13 John Smith
h3. Writing a "Hello World" app in Eclipse
107
108
h4. Creating an Android Virtual Device
109
110
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:
111 1 John Smith
112 13 John Smith
- Name: something descriptive like "AVD_for_Nexus_S"
113 34 Beuc Beuc
- Screen resolution of your physical device, e.g. "WVGA800" for Nexus S
114
- Target: choose "Android 4.2.2 - API level 17" from the dropdown menu
115 13 John Smith
- SD Card: specify the size of an emulated SD card, alternatively browse for an existing SD card image
116 1 John Smith
- leave other values at defaults and click "Create AVD"
117 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
118 17 John Smith
119 14 John Smith
h4. Creating a project
120
121 34 Beuc Beuc
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".
122 1 John Smith
123 34 Beuc Beuc
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").
124 15 John Smith
125 34 Beuc Beuc
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.
126 16 John Smith
127 34 Beuc Beuc
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.
128 1 John Smith
129 34 Beuc Beuc
Finally click "Finish" and your project should appear in Eclipse's left-hand projects tree.
130
131 17 John Smith
h4. Adding some code and resources into a project
132
133
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:
134
135
<pre>package hello.test;
136
137
import android.app.Activity;
138
import android.os.Bundle;
139
import android.view.View;
140
import android.widget.Button;
141
142
public class MainActivity extends Activity {
143
144
    @Override
145
    public void onCreate(Bundle savedInstanceState) {
146
    	
147
        super.onCreate(savedInstanceState);
148
        setContentView(R.layout.main);
149
        
150
        Button buttonFinish = (Button) findViewById(R.id.buttonFinish);
151 1 John Smith
        buttonFinish.setOnClickListener(new View.OnClickListener() {
152 17 John Smith
			@Override
153
			public void onClick(View v) {
154
				finish();
155
			}
156
		});
157
    }
158
}</pre>
159
160 34 Beuc Beuc
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.
161 17 John Smith
162
We need to create this resource file now. I would recommend having it be like this:
163
164
<pre><?xml version="1.0" encoding="utf-8"?>
165
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
166
    android:orientation="vertical"
167
    android:layout_width="fill_parent"
168
    android:layout_height="fill_parent"
169
    >
170
<TextView
171
    android:id="@+id/textInfo"
172
    android:layout_width="fill_parent" 
173
    android:layout_height="wrap_content" 
174
    android:text="Click button to close app."
175
    />
176
<Button android:id="@+id/buttonFinish"
177
    android:layout_width="wrap_content"
178 18 John Smith
    android:layout_height="wrap_content"
179 17 John Smith
    android:text="Close" />
180 1 John Smith
</LinearLayout>
181 18 John Smith
</pre>
182 19 John Smith
183 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.
184
185
h4. Running the app on an Android Virtual Device
186
187 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.
188
189
h4. Running the app on a real Replicant device
190 22 John Smith
191
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.
192
193 23 John Smith
2. Enable USB debugging on your device, for example by choosing "Menu" > "Settings" > "Applications" > "Development" and checking the "USB Debugging" checkbox.
194
195 35 Wolfgang Wiedmeyer
3. Set up [[ADB]] on your PC.
196 24 John Smith
197 37 Wolfgang Wiedmeyer
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@).
198 24 John Smith
199 23 John Smith
4. Run the app. Without a customized run configuration, Eclipse should display the "Android Device Chooser" dialog, letting you choose. 
200
201 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.