| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 1 | Android-specific notes |
| 2 | |
| Tor Lillqvist | 0f9f8ef | 2012-09-10 14:28:34 +0300 | [diff] [blame] | 3 | Note that this document has not necessarily been updated to match |
| 4 | reality... |
| 5 | |
| 6 | * Getting something running on an emulated device |
| Michael Meeks | a0ce2a2 | 2012-01-20 09:44:00 +0000 | [diff] [blame] | 7 | |
| 8 | Create an AVD in the android UI, don't even try to get |
| 9 | the data partition size right in the GUI, that is doomed to producing |
| 10 | and AVD that doesn't work. Instead start it from the console: |
| 11 | |
| Miklos Vajna | 09189c3 | 2012-11-09 15:12:47 +0100 | [diff] [blame] | 12 | LD_LIBRARY_PATH=$(pwd)/lib emulator-arm -avd <Name> -partition-size 500 |
| 13 | |
| 14 | In order to have proper acceleration, you need the 32-bit libGL.so: |
| 15 | |
| 16 | sudo zypper in Mesa-libGL-devel-32bit |
| Michael Meeks | a0ce2a2 | 2012-01-20 09:44:00 +0000 | [diff] [blame] | 17 | |
| 18 | Where <Name> is the literal name of the AVD that you entered. |
| Michael Meeks | a0ce2a2 | 2012-01-20 09:44:00 +0000 | [diff] [blame] | 19 | |
| 20 | Then: |
| 21 | |
| Michael Meeks | 739252d | 2012-02-27 14:16:54 +0000 | [diff] [blame] | 22 | make cmd cmd=bash |
| Michael Meeks | a0ce2a2 | 2012-01-20 09:44:00 +0000 | [diff] [blame] | 23 | cd android/qa/sc |
| 24 | make clean all install |
| 25 | make run ; adb shell logcat |
| 26 | |
| Tor Lillqvist | b58498f | 2012-05-17 10:09:22 +0300 | [diff] [blame] | 27 | And if all goes well - you should have some nice unit test output to |
| 28 | enjoy. After a while of this loop you might find that you have lost a lot of |
| 29 | space on your emulator's or device's /data volume. If using the emulator, you |
| 30 | can do: |
| Michael Meeks | 56db077 | 2012-01-20 10:19:42 +0000 | [diff] [blame] | 31 | |
| Tor Lillqvist | b58498f | 2012-05-17 10:09:22 +0300 | [diff] [blame] | 32 | adb shell stop; adb shell start |
| 33 | |
| 34 | but on a (non-rooted) device you probably just need to reboot it. On the other |
| 35 | hand, this phenomenon might not happen on actual devices. |
| Michael Meeks | 56db077 | 2012-01-20 10:19:42 +0000 | [diff] [blame] | 36 | |
| 37 | and continue onwards & upwards. |
| Michael Meeks | a0ce2a2 | 2012-01-20 09:44:00 +0000 | [diff] [blame] | 38 | |
| Tor Lillqvist | 0f9f8ef | 2012-09-10 14:28:34 +0300 | [diff] [blame] | 39 | * What about using a real device? |
| 40 | |
| 41 | That works fine, too. You won't be able to use the "adb shell |
| 42 | stop" and "adb shell start" commands to do anything, as far as I |
| 43 | know. But don't seem to be necessary on a real device anyway? |
| 44 | |
| Michael Meeks | 0eef5f6 | 2012-01-20 12:08:01 +0000 | [diff] [blame] | 45 | * Debugging |
| 46 | |
| 47 | Debugging is fun, the default NDK gdb (in v7) is busted, you |
| 48 | need 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 |
| 53 | symbols only for shlibs that were already loaded when the debuggee was |
| 54 | attached, 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 |
| 59 | to run: ndk-gdb and it will attach the process. |
| 60 | |
| Michael Meeks | e74a358 | 2012-01-23 17:08:55 +0000 | [diff] [blame] | 61 | thread 12 # or perhaps 13 |
| 62 | backtrace |
| 63 | |
| 64 | may show you the native code trace. |
| 65 | |
| Tor Lillqvist | 0f9f8ef | 2012-09-10 14:28:34 +0300 | [diff] [blame] | 66 | In r8b the ndk-gdb seems to work a bit better, and I think it isn't |
| 67 | necessary to use the mingw-and-ndk ndb-gdb any longer. |
| 68 | |
| 69 | |
| Michael Meeks | db9ca8e | 2012-01-20 17:18:35 +0000 | [diff] [blame] | 70 | * Common Errors / Gotchas |
| 71 | |
| 72 | lo_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 |
| 74 | the file is truncated; check it out with adb shell ls -l /data/data/.... |
| 75 | |
| 76 | |
| Michael Meeks | a0ce2a2 | 2012-01-20 09:44:00 +0000 | [diff] [blame] | 77 | * Detailed explanation |
| 78 | |
| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 79 | Unit tests are the first thing we want to run on Android, to get some |
| 80 | idea how well, if at all, the basic LO libraraies work. We want to |
| 81 | build even unit tests as normal Android apps, i.e. packaged as .apk |
| 82 | files, so that they run in a sandboxed environment like that of |
| 83 | whatever eventual end-user Android apps there will be that use LO |
| 84 | code. |
| 85 | |
| Tor Lillqvist | 05d0bdb | 2012-01-03 15:27:41 +0200 | [diff] [blame] | 86 | Sure, we could quite easily build unit tests as plain Linux |
| 87 | executables (built against the Android libraries, of course, not |
| 88 | GNU/Linux ones), push them to the device or emulator with adb and run |
| 89 | them from adb shell, but that would not be a good test as the |
| 90 | environment such processs run in is completely different from that in |
| 91 | which real end-user apps with GUI etc run. We have no intent to |
| 92 | require LibreOffice code to be used only on "rooted" devices etc. |
| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 93 | |
| 94 | All Android apps are basically Java programs. They run "in" a Dalvik |
| Tor Lillqvist | 0f9f8ef | 2012-09-10 14:28:34 +0300 | [diff] [blame] | 95 | virtual machine. Yes, you can also have apps where all *your* code is |
| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 96 | native code, written in a compiled language like C or C++. But also |
| 97 | also such apps are actually started by system-provided Java |
| 98 | bootstrapping code (NativeActivity) running in a Dalvik VM. |
| 99 | |
| 100 | Such a native app (or actually, "activity") is not built as a |
| 101 | executable program, but as a shared object. The Java NativeActivity |
| 102 | bootstrapper loads that shared object with dlopen. |
| 103 | |
| Tor Lillqvist | 0f9f8ef | 2012-09-10 14:28:34 +0300 | [diff] [blame] | 104 | Anyway, our current "experimental" apps (DocumentLoader and |
| 105 | LibreOffice4Android) are not based on NativeActivity any more. They |
| 106 | have normal Java code for the activity, and just call out to native |
| 107 | libraries to do all the heavy lifting. |
| 108 | |
| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 109 | It is somewhat problematic to construct .apk packages except by using |
| 110 | the high-level tools in the Android SDK. At least I haven't figured |
| 111 | out how to manually construct an .apk that is properly signed so that |
| 112 | it will run in the emulator. (I don't have any Android device...) I |
| 113 | only know how to let the SDK Ant tooling do it... |
| 114 | |
| Tor Lillqvist | 05d0bdb | 2012-01-03 15:27:41 +0200 | [diff] [blame] | 115 | At this stage, the plan is that a LO Android app will work would |
| 116 | something like this: |
| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 117 | |
| Tor Lillqvist | 05d0bdb | 2012-01-03 15:27:41 +0200 | [diff] [blame] | 118 | We have a Java class org.libreoffice.android.Bootstrap that that loads |
| 119 | a small helper native library liblo-bootstrap.so that implements JNI |
| 120 | wrappers for dlopen(), dlsym(), and ELF header scanning coresponding |
| 121 | to looking for DT_NEEDED entries with readelf. |
| Tor Lillqvist | a9d167b | 2011-11-11 16:44:18 +0200 | [diff] [blame] | 122 | |
| 123 | The Java code then loads the actual native library that corresponds to |
| 124 | the LibreOffice-related "program" we want to run. For unit tests, a |
| 125 | library that corresponds to cppunittester program. Then through helper |
| 126 | functions in liblo-bootstrap it calls a named function in that |
| 127 | "program". |
| 128 | |
| Tor Lillqvist | 172b1f0 | 2011-12-01 16:08:44 +0200 | [diff] [blame] | 129 | This Android-specific native code (the lo-bootstrap library) is for |
| 130 | now in sal/android, and the Java code in the android "module" |
| 131 | (subdirectory right here). |