blob: f86c87214c38b592d012290bccc3c4593df474d9 [file] [log] [blame]
Tor Lillqvista9d167b2011-11-11 16:44:18 +02001Android-specific notes
2
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +03003Note that this document has not necessarily been updated to match
4reality...
5
6* Getting something running on an emulated device
Michael Meeksa0ce2a22012-01-20 09:44:00 +00007
8 Create an AVD in the android UI, don't even try to get
9the data partition size right in the GUI, that is doomed to producing
10and AVD that doesn't work. Instead start it from the console:
11
Miklos Vajna09189c32012-11-09 15:12:47 +010012 LD_LIBRARY_PATH=$(pwd)/lib emulator-arm -avd <Name> -partition-size 500
13
14In order to have proper acceleration, you need the 32-bit libGL.so:
15
16 sudo zypper in Mesa-libGL-devel-32bit
Michael Meeksa0ce2a22012-01-20 09:44:00 +000017
18 Where <Name> is the literal name of the AVD that you entered.
Michael Meeksa0ce2a22012-01-20 09:44:00 +000019
20 Then:
21
Michael Meeks739252d2012-02-27 14:16:54 +000022 make cmd cmd=bash
Michael Meeksa0ce2a22012-01-20 09:44:00 +000023 cd android/qa/sc
24 make clean all install
25 make run ; adb shell logcat
26
Tor Lillqvistb58498f2012-05-17 10:09:22 +030027 And if all goes well - you should have some nice unit test output to
28enjoy. After a while of this loop you might find that you have lost a lot of
29space on your emulator's or device's /data volume. If using the emulator, you
30can do:
Michael Meeks56db0772012-01-20 10:19:42 +000031
Tor Lillqvistb58498f2012-05-17 10:09:22 +030032 adb shell stop; adb shell start
33
34but on a (non-rooted) device you probably just need to reboot it. On the other
35hand, this phenomenon might not happen on actual devices.
Michael Meeks56db0772012-01-20 10:19:42 +000036
37 and continue onwards & upwards.
Michael Meeksa0ce2a22012-01-20 09:44:00 +000038
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +030039* What about using a real device?
40
41 That works fine, too. You won't be able to use the "adb shell
42stop" and "adb shell start" commands to do anything, as far as I
43know. But don't seem to be necessary on a real device anyway?
44
Michael Meeks0eef5f62012-01-20 12:08:01 +000045* Debugging
46
47 Debugging is fun, the default NDK gdb (in v7) is busted, you
48need to download a new one from:
49
50 http://code.google.com/p/mingw-and-ndk/
51
52 Even this 'fixed' gdb is broken in the way that it can see
53symbols only for shlibs that were already loaded when the debuggee was
54attached, so you need to carefully guess where to put:
55
56 fprintf(stderr, "Sleeping NOW!\n"); ::sleep(20);
57
58 into the code; and when you see that in logcat, you have time
59to run: ndk-gdb and it will attach the process.
60
Michael Meekse74a3582012-01-23 17:08:55 +000061 thread 12 # or perhaps 13
62 backtrace
63
64 may show you the native code trace.
65
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +030066 In r8b the ndk-gdb seems to work a bit better, and I think it isn't
67necessary to use the mingw-and-ndk ndb-gdb any longer.
68
69
Michael Meeksdb9ca8e2012-01-20 17:18:35 +000070* Common Errors / Gotchas
71
72lo_dlneeds: Could not read ELF header of /data/data/org.libreoffice...libfoo.so
73 This (most likely) means that the install quietly failed, and that
74the file is truncated; check it out with adb shell ls -l /data/data/....
75
76
Michael Meeksa0ce2a22012-01-20 09:44:00 +000077* Detailed explanation
78
Tor Lillqvista9d167b2011-11-11 16:44:18 +020079Unit tests are the first thing we want to run on Android, to get some
80idea how well, if at all, the basic LO libraraies work. We want to
81build even unit tests as normal Android apps, i.e. packaged as .apk
82files, so that they run in a sandboxed environment like that of
83whatever eventual end-user Android apps there will be that use LO
84code.
85
Tor Lillqvist05d0bdb2012-01-03 15:27:41 +020086Sure, we could quite easily build unit tests as plain Linux
87executables (built against the Android libraries, of course, not
88GNU/Linux ones), push them to the device or emulator with adb and run
89them from adb shell, but that would not be a good test as the
90environment such processs run in is completely different from that in
91which real end-user apps with GUI etc run. We have no intent to
92require LibreOffice code to be used only on "rooted" devices etc.
Tor Lillqvista9d167b2011-11-11 16:44:18 +020093
94All Android apps are basically Java programs. They run "in" a Dalvik
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +030095virtual machine. Yes, you can also have apps where all *your* code is
Tor Lillqvista9d167b2011-11-11 16:44:18 +020096native code, written in a compiled language like C or C++. But also
97also such apps are actually started by system-provided Java
98bootstrapping code (NativeActivity) running in a Dalvik VM.
99
100Such a native app (or actually, "activity") is not built as a
101executable program, but as a shared object. The Java NativeActivity
102bootstrapper loads that shared object with dlopen.
103
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +0300104Anyway, our current "experimental" apps (DocumentLoader and
105LibreOffice4Android) are not based on NativeActivity any more. They
106have normal Java code for the activity, and just call out to native
107libraries to do all the heavy lifting.
108
Tor Lillqvista9d167b2011-11-11 16:44:18 +0200109It is somewhat problematic to construct .apk packages except by using
110the high-level tools in the Android SDK. At least I haven't figured
111out how to manually construct an .apk that is properly signed so that
112it will run in the emulator. (I don't have any Android device...) I
113only know how to let the SDK Ant tooling do it...
114
Tor Lillqvist05d0bdb2012-01-03 15:27:41 +0200115At this stage, the plan is that a LO Android app will work would
116something like this:
Tor Lillqvista9d167b2011-11-11 16:44:18 +0200117
Tor Lillqvist05d0bdb2012-01-03 15:27:41 +0200118We have a Java class org.libreoffice.android.Bootstrap that that loads
119a small helper native library liblo-bootstrap.so that implements JNI
120wrappers for dlopen(), dlsym(), and ELF header scanning coresponding
121to looking for DT_NEEDED entries with readelf.
Tor Lillqvista9d167b2011-11-11 16:44:18 +0200122
123The Java code then loads the actual native library that corresponds to
124the LibreOffice-related "program" we want to run. For unit tests, a
125library that corresponds to cppunittester program. Then through helper
126functions in liblo-bootstrap it calls a named function in that
127"program".
128
Tor Lillqvist172b1f02011-12-01 16:08:44 +0200129This Android-specific native code (the lo-bootstrap library) is for
130now in sal/android, and the Java code in the android "module"
131(subdirectory right here).