blob: 04d1684b43bbcbe1b07132adde68b0ad2f85d9fe [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
12 emulator-arm -avd <Name> -partition-size 500
13
14 Where <Name> is the literal name of the AVD that you entered.
Michael Meeksa0ce2a22012-01-20 09:44:00 +000015
16 Then:
17
Michael Meeks739252d2012-02-27 14:16:54 +000018 make cmd cmd=bash
Michael Meeksa0ce2a22012-01-20 09:44:00 +000019 cd android/qa/sc
20 make clean all install
21 make run ; adb shell logcat
22
Tor Lillqvistb58498f2012-05-17 10:09:22 +030023 And if all goes well - you should have some nice unit test output to
24enjoy. After a while of this loop you might find that you have lost a lot of
25space on your emulator's or device's /data volume. If using the emulator, you
26can do:
Michael Meeks56db0772012-01-20 10:19:42 +000027
Tor Lillqvistb58498f2012-05-17 10:09:22 +030028 adb shell stop; adb shell start
29
30but on a (non-rooted) device you probably just need to reboot it. On the other
31hand, this phenomenon might not happen on actual devices.
Michael Meeks56db0772012-01-20 10:19:42 +000032
33 and continue onwards & upwards.
Michael Meeksa0ce2a22012-01-20 09:44:00 +000034
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +030035* What about using a real device?
36
37 That works fine, too. You won't be able to use the "adb shell
38stop" and "adb shell start" commands to do anything, as far as I
39know. But don't seem to be necessary on a real device anyway?
40
Michael Meeks0eef5f62012-01-20 12:08:01 +000041* Debugging
42
43 Debugging is fun, the default NDK gdb (in v7) is busted, you
44need to download a new one from:
45
46 http://code.google.com/p/mingw-and-ndk/
47
48 Even this 'fixed' gdb is broken in the way that it can see
49symbols only for shlibs that were already loaded when the debuggee was
50attached, so you need to carefully guess where to put:
51
52 fprintf(stderr, "Sleeping NOW!\n"); ::sleep(20);
53
54 into the code; and when you see that in logcat, you have time
55to run: ndk-gdb and it will attach the process.
56
Michael Meekse74a3582012-01-23 17:08:55 +000057 thread 12 # or perhaps 13
58 backtrace
59
60 may show you the native code trace.
61
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +030062 In r8b the ndk-gdb seems to work a bit better, and I think it isn't
63necessary to use the mingw-and-ndk ndb-gdb any longer.
64
65
Michael Meeksdb9ca8e2012-01-20 17:18:35 +000066* Common Errors / Gotchas
67
68lo_dlneeds: Could not read ELF header of /data/data/org.libreoffice...libfoo.so
69 This (most likely) means that the install quietly failed, and that
70the file is truncated; check it out with adb shell ls -l /data/data/....
71
72
Michael Meeksa0ce2a22012-01-20 09:44:00 +000073* Detailed explanation
74
Tor Lillqvista9d167b2011-11-11 16:44:18 +020075Unit tests are the first thing we want to run on Android, to get some
76idea how well, if at all, the basic LO libraraies work. We want to
77build even unit tests as normal Android apps, i.e. packaged as .apk
78files, so that they run in a sandboxed environment like that of
79whatever eventual end-user Android apps there will be that use LO
80code.
81
Tor Lillqvist05d0bdb2012-01-03 15:27:41 +020082Sure, we could quite easily build unit tests as plain Linux
83executables (built against the Android libraries, of course, not
84GNU/Linux ones), push them to the device or emulator with adb and run
85them from adb shell, but that would not be a good test as the
86environment such processs run in is completely different from that in
87which real end-user apps with GUI etc run. We have no intent to
88require LibreOffice code to be used only on "rooted" devices etc.
Tor Lillqvista9d167b2011-11-11 16:44:18 +020089
90All Android apps are basically Java programs. They run "in" a Dalvik
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +030091virtual machine. Yes, you can also have apps where all *your* code is
Tor Lillqvista9d167b2011-11-11 16:44:18 +020092native code, written in a compiled language like C or C++. But also
93also such apps are actually started by system-provided Java
94bootstrapping code (NativeActivity) running in a Dalvik VM.
95
96Such a native app (or actually, "activity") is not built as a
97executable program, but as a shared object. The Java NativeActivity
98bootstrapper loads that shared object with dlopen.
99
Tor Lillqvist0f9f8ef2012-09-10 14:28:34 +0300100Anyway, our current "experimental" apps (DocumentLoader and
101LibreOffice4Android) are not based on NativeActivity any more. They
102have normal Java code for the activity, and just call out to native
103libraries to do all the heavy lifting.
104
Tor Lillqvista9d167b2011-11-11 16:44:18 +0200105It is somewhat problematic to construct .apk packages except by using
106the high-level tools in the Android SDK. At least I haven't figured
107out how to manually construct an .apk that is properly signed so that
108it will run in the emulator. (I don't have any Android device...) I
109only know how to let the SDK Ant tooling do it...
110
Tor Lillqvist05d0bdb2012-01-03 15:27:41 +0200111At this stage, the plan is that a LO Android app will work would
112something like this:
Tor Lillqvista9d167b2011-11-11 16:44:18 +0200113
Tor Lillqvist05d0bdb2012-01-03 15:27:41 +0200114We have a Java class org.libreoffice.android.Bootstrap that that loads
115a small helper native library liblo-bootstrap.so that implements JNI
116wrappers for dlopen(), dlsym(), and ELF header scanning coresponding
117to looking for DT_NEEDED entries with readelf.
Tor Lillqvista9d167b2011-11-11 16:44:18 +0200118
119The Java code then loads the actual native library that corresponds to
120the LibreOffice-related "program" we want to run. For unit tests, a
121library that corresponds to cppunittester program. Then through helper
122functions in liblo-bootstrap it calls a named function in that
123"program".
124
Tor Lillqvist172b1f02011-12-01 16:08:44 +0200125This Android-specific native code (the lo-bootstrap library) is for
126now in sal/android, and the Java code in the android "module"
127(subdirectory right here).