51dfaf9861a7fc040347a55d5764087b51f10a7a
[vuplus_xbmc] / docs / README.android
1 TOC
2 1. Introduction
3 2. Installing and setting up the Android environment
4 3. Getting the source code
5 4. Installing the required Ubuntu packages
6 5. How to compile
7 6. Installing XBMC in an Android system
8 7. Running and debugging XBMC in an Android system
9 8. Architecture
10 9. Useful Commands
11
12 -----------------------------------------------------------------------------
13 1. Introduction
14 -----------------------------------------------------------------------------
15
16 We currently recommend Ubuntu Natty (11.04) or later. Current work has been
17 done here. Additionally, building from OSX Snow Leopard is working.
18
19 NOTE TO NEW USERS: All lines that are prefixed with the '#'
20 character are commands that need to be typed into a terminal window /
21 console (similar to the command prompt for Windows). Note that the '#'
22 character itself should NOT be typed as part of the command.
23
24 -----------------------------------------------------------------------------
25 2. Installing the required Ubuntu packages
26 -----------------------------------------------------------------------------
27 These are the minimum packages necessary for building XBMC. Non-Ubuntu
28 users will need to get the equivalents.
29
30    # sudo apt-get install build-essential default-jdk git curl autoconf \
31        unzip zip zlib1g-dev gawk gperf cmake
32
33 If you run a 64bit operating system you will also need to get ia32-libs
34
35    # sudo apt-get install ia32-libs
36
37
38 -----------------------------------------------------------------------------
39 3. Installing and setting up the Android environment
40 -----------------------------------------------------------------------------
41
42 To develop XBMC for Android the Android SDK and NDK are required.
43
44 --------------------------------------------------------------------
45 3.1. Getting the Android SDK and NDK
46 --------------------------------------------------------------------
47
48 To get the Android SDK, go to http://developer.android.com/sdk and
49 download the latest version for your operating system. The NDK
50 can be downloaded from http://developer.android.com/tools/sdk/ndk/ 
51
52 [NOTICE] Compiling XBMC for Android requires at least Android NDK
53          Revision r8e. Android NDK Revision 7 and earlier do not work
54          properly for our cause.
55
56 After downloading the SDK and NDK extract the files contained in the
57 archives to your harddisk.
58
59 Make sure you have a recent JRE and JDK installed otherwise the
60 Android SDK will not work.
61
62 --------------------------------------------------------------------
63 3.2. Installing Android SDK packages
64 --------------------------------------------------------------------
65
66 After having extracted the Android SDK to <android-sdk> you need to
67 install some android packages using the Android SDK Manager:
68
69    # cd <android-sdk>/tools
70    # ./android update sdk -u -t platform,platform-tool
71
72 --------------------------------------------------------------------
73 3.3. Setup the Android toolchain
74 --------------------------------------------------------------------
75
76 To be able to compile XBMC and the libraries it depends on for the
77 Android platform you first need to setup an Android toolchain using
78 the Android NDK which you earlier extracted to <android-ndk>. The
79 following commands will create a toolchain suitable for the most
80 common scenario.
81 The --install-dir option (and therefore the <android-toolchain> value)
82 specifies where the resulting toolchain should be installed (your choice).
83
84    # cd <android-ndk>
85    # ls platforms
86    # cd build/tools
87    # ./make-standalone-toolchain.sh --ndk-dir=../../ \
88      --install-dir=<android-toolchain>/android-14 --platform=android-14 \
89      --toolchain=arm-linux-androideabi-4.7
90
91 Make sure to pick a toolchain for your desired architecture. Currently only
92 gcc 4.7 and gcc 4.8 toolchains are supported, anything else will likely fail to build.
93
94 --------------------------------------------------------------------
95 3.4. Create a (new) debug key to sign debug APKs
96 --------------------------------------------------------------------
97
98   All packages must be signed. The following command will generate a
99   self-signed debug key. If the result is a cryptic error, it
100   probably just means a debug key already existed, no cause for alarm.
101
102   # keytool -genkey -keystore ~/.android/debug.keystore -v -alias \
103       androiddebugkey -dname "CN=Android Debug,O=Android,C=US" -keypass \
104       android -storepass android -keyalg RSA -keysize 2048 -validity 10000
105
106 -----------------------------------------------------------------------------
107 4. Getting the source code
108 -----------------------------------------------------------------------------
109
110    # cd $HOME
111    # git clone git://github.com/xbmc/xbmc.git xbmc-android
112    # cd xbmc-android
113    # git submodule update --init addons/skin.touched
114
115 -----------------------------------------------------------------------------
116 5. How to compile
117 -----------------------------------------------------------------------------
118
119 Compiling XBMC for Android consists of compiling the libraries XBMC depends
120 on with the Android toolchain and creating an Android Application Package
121 (APK) which can be installed in an Android system.
122
123 --------------------------------------------------------------------
124 5.1. Building dependencies
125 --------------------------------------------------------------------
126
127    # cd $HOME/xbmc-android/tools/depends
128    # ./bootstrap
129    # ./configure --help
130
131    Run configure with the correct settings for you local configuration.
132    See tools/depends/README for examples.
133
134    Anyone working on the dependencies themselves will want to set the
135    environment variables specified in ~/.bashrc or similar, to avoid
136    having to input these with each configure. 
137
138    # make -j <jobs>
139
140    This build was designed to be massively parallel. Don't be afraid to
141    give it a 'make -j20' or so.
142
143    Verify that all deps built correctly (it will tell you so) before
144    continuing. You will get crazy build errors otherwise.
145
146 --------------------------------------------------------------------
147 5.2. Building XBMC
148 --------------------------------------------------------------------
149
150    # cd $HOME/xbmc-android
151    # make -C tools/depends/target/xbmc
152    # make
153    # make apk
154
155    After the first build (assuming bootstrap and configure are successful),
156    subsequent builds can be run with a simple 'make' and 'make apk'.
157
158 -----------------------------------------------------------------------------
159 6. Installing XBMC in an Android system
160 -----------------------------------------------------------------------------
161
162 To install XBMC through the previously built APK in an Android system you can
163 either install it on a real device (smartphone/tablet/...) running Android
164  >= 2.3.x.
165
166 --------------------------------------------------------------------
167 6.1. Installing XBMC on the Android device
168 --------------------------------------------------------------------
169
170 Make sure your Android device is connected to your computer through
171 USB. Furthermore you have to enable the following option in your
172 device's Android settings:
173
174   - Applications
175     [X] Unknown sources
176
177    # cd $HOME/xbmc-android/tools/android/packaging
178    # adb devices
179    # adb -s <device-id> install -r images/xbmcapp-debug.apk
180       
181 The <device-id> can be retrieved from the list returned by the
182 "adb devices" command and is the first value in the row representing
183 your device.
184
185 -----------------------------------------------------------------------------
186 7. Running and debugging XBMC in an Android system
187 -----------------------------------------------------------------------------
188
189 After installing XBMC's APK in an Android system you can start it using its
190 Launcher icon in Android's Application Launcher.
191
192 --------------------------------------------------------------------
193 7.1. Debugging XBMC
194 --------------------------------------------------------------------
195
196 To be able to see what is happening while running XBMC you first need
197 to enable USB debugging in your Android settings (this is already done
198 when using the emulator):
199
200   - Applications
201     [X] Unknown sources
202      -  Development
203       [X] USB debugging
204
205 To access the log output of your Android system run (the -s parameter
206 and the <device-id> may not be needed when using the Android emulator)
207
208   # adb -s <device-id> logcat
209
210
211 --------------------------------------------------------------------
212 7.2. GDB
213 --------------------------------------------------------------------
214
215 GDB can be used to debug, though the support is rather primitive. Rather than
216 using gdb directly, you will need to use ndk-gdb which wraps it. Do NOT trust
217 the -p/--project switches, as of ndk7b they do not work. Instead you will need
218 to cd to tools/android/packaging/xbmc and execute it from there.
219
220   # ndk-gdb --start --delay=0
221
222 This will open the installed version of XBMC and break. The warnings can be
223 ignored as we have setup the appropriate paths already.
224
225 --------------------------------------------------------------------
226 8. Architecture
227 --------------------------------------------------------------------
228
229 During the early days of the android port, xbmc was launched via a stub lib
230 that then dlopen'd libxbmc. This was done to get around bionic's poor handling
231 of shared libs. We now compile everything into libxbmc itself so that it has
232 no runtime dependencies beyond system libs. Done this way, we're able to launch
233 into libxbmc directly.
234
235 But we still hit Bionic's loader's deficiencies when we dlopen a lib. There are
236 two main issues to overcome for loading:
237
238 1. Bionic imports all symbols for a lib as soon as it is loaded, and it will
239 refuse to open a lib if it has a single unresolved symbol
240
241 2. It does not search recursively during the resolve. So if liba depends on
242 libb, dlopen'ing liba will _not_ pull in missing symbols from libb. This is
243 particularly nasty considering #1.
244
245 To work-around these problems we use our own recursive loader in place of
246 dlopen. This loader mimics expected behavior. Using the example above, loading
247 libb before liba will mean that everything will resolve correctly.
248
249 Additionally, Android does not use versioned solibs. libfoo.so.1 which is
250 typical on linux would not be found by the loader. This means that we must
251 strip the SONAME and NEEDED values out of the libs as well as changing the
252 filenames themselves. The cleaner solution would be to patch libtool/cmake/etc
253 to not add versioning in the first place. For now, we use the brute-force
254 approach of modifying the binary and blanking out the versions.
255
256 See here for more info:
257 http://www.bernawebdesign.ch/byteblog/2011/11/23/creating-non-versioned-shared-libraries-for-android/
258
259 As a final gotcha, all libs must be in the form of ^lib.*so$ with no
260 exceptions (they won't even install otherwise), and the soname must match.
261 So we have to do some renaming to get some of our self-built libs loaded.
262
263 Development:
264 Typical android native activities are built with ndk-build which is a wrapper
265 around Make. It would be a nightmare to port our entire buildsystem over, so
266 instead we build as usual then package ourselves. It may be beneficial to use
267 ndk-build to do the actual packaging, but for now its behavior is emulated.
268
269 ABI:
270 Presently we are targeting armv7a+neon for arm, and i686 for x86. Note that x86
271 builds successfully but has not been tested.
272
273 --------------------------------------------------------------------
274 9. Useful Commands
275 --------------------------------------------------------------------
276
277 Below are a few helpful commands when building/debugging. These assume that pwd
278 is 'tools/android/packaging' and that the proper sdk/ndk paths are set.
279
280 -Install a new build over the existing one
281   # adb -e install -r images/xbmcapp-debug.apk
282
283 -Launch XBMC on the emulator without the GUI
284   # adb shell am start -a android.intent.action.MAIN -n org.xbmc.xbmc/android.app.NativeActivity
285
286 -Kill a misbehaving XBMC
287   # adb shell ps | grep org.xbmc | awk '{print $2}' | xargs adb shell kill
288
289 -Filter logcat messages by a specific tag (e.g. "XBMC")
290   # adb logcat -s XBMC:V
291   
292 -Enable CheckJNI (BEFORE starting the application)
293   # adb shell setprop debug.checkjni 1
294