2 How to cross-compile for Android. These notes were last updated on
3 27 Sept 2011, for Valgrind SVN revision 12060/2209.
5 This is known to work at least for Android 2.3.4 running on a (rooted,
6 AOSP build) Nexus S. It has also worked in the past on a
7 un-messed-with Motorola Xoom, although I haven't tested it recently.
8 Other configurations and toolchains might work, but haven't been
9 tested. Feedback is welcome.
11 You need the android-ndk-r6 native development kit. Install it
12 somewhere. Doesn't matter where. Then do this:
15 # Modify this (obviously). Note, this "export" command is only done
16 # so as to reduce the amount of typing required. None of the commands
17 # below read it as part of their operation.
19 export NDKROOT=/path/to/android-ndk-r6
22 # Modify this too. Tell the build system which Android hardware you
23 # are building for. It needs to know this so it can compile in
24 # support for the right Android-hw-specific ioctls. (sigh.) As with
25 # NDKROOT above, this is merely to avoid repeated typing; none of the
28 # Currently the only supported value is: nexus_s
30 export HWKIND=nexus_s # Samsung Nexus S
33 # Then cd to the root of your Valgrind source tree.
35 cd /path/to/valgrind/source/tree
38 # After this point, you don't need to modify anything; just copy and
39 # paste the commands below.
42 # Set up toolchain paths.
44 export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
45 export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
46 export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
49 # Do configuration stuff. Don't mess with the --prefix in the
50 # configure command below, even if you think it's wrong.
51 # You may need to set the --with-tmpdir path to something
52 # different if /sdcard doesn't works on the device -- this is
53 # a known cause of difficulties.
57 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
58 CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
59 ./configure --prefix=/data/local/Inst \
60 --host=armv7-unknown-linux --target=armv7-unknown-linux \
64 # At the end of the configure run, a few lines of details
65 # are printed. Make sure that you see these two lines:
67 # Platform variant: android
68 # Primary -DVGPV string: -DVGPV_arm_linux_android=1
70 # If you see anything else at this point, something is wrong, and
71 # either the build will fail, or will succeed but you'll get something
75 # Build, and park the install tree in `pwd`/Inst
78 make -j2 install DESTDIR=`pwd`/Inst
81 # To get the install tree onto the device:
82 # (I don't know why it's not "adb push Inst /data/local", but this
83 # formulation does appear to put the result in /data/local/Inst.)
87 # To run (on the device)
88 /data/local/Inst/bin/valgrind [the usual args etc]
91 # Once you're up and running, a handy modify-V-rebuild-reinstall
92 # command line (on the host, of course) is
94 mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
96 # where 'mq' is an alias for 'make --quiet'.
99 # One common cause of runs failing at startup is the inability of
100 # Valgrind to find a suitable temporary directory. On the device,
101 # there doesn't seem to be any one location which we always have
102 # permission to write to. The instructions above use /sdcard. If
103 # that doesn't work for you, and you're Valgrinding one specific
104 # application which is already installed, you could try using its
105 # temporary directory, in /data/data, for example
106 # /data/data/org.mozilla.firefox_beta.
108 # Using /system/bin/logcat on the device is helpful for diagnosing
109 # these kinds of problems.