• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2How to cross-compile for Android.  These notes were last updated on
317 Feb 2012, for Valgrind SVN revision 12390/2257.
4
5This is known to work at least for :
6ARM:
7  Android 4.0.3 running on a (rooted, AOSP build) Nexus S.
8  Android 4.0.3 running on Motorola Xoom.
9  Android 4.0.3 running on android arm emulator.
10  Android 4.1   running on android emulator.
11  Android 2.3.4 on Nexus S worked at some time in the past.
12
13x86:
14  Android 4.0.3 running on android x86 emulator.
15
16mips32:
17  Android 4.1.2 running on android mips emulator.
18  Android 4.2.2 running on android mips emulator.
19  Android 4.3   running on android mips emulator.
20  Android 4.0.4 running on BROADCOM bcm7425
21
22On android-arm, GDBserver might insert breaks at wrong addresses.
23Feedback on this welcome.
24
25Other configurations and toolchains might work, but haven't been tested.
26Feedback is welcome.
27
28
29You need the android-ndk-r6 native development kit.  r6b and r7
30give a non-completely-working build; see
31http://code.google.com/p/android/issues/detail?id=23203
32For the android emulator, the versions needed and how to
33install them are described in README.android_emulator.
34
35You can get android-ndk-r6 from
36http://dl.google.com/android/ndk/android-ndk-r6-linux-x86.tar.bz2
37Install it somewhere.  Doesn't matter where.  Then do this:
38
39
40# Modify this (obviously).  Note, this "export" command is only done
41# so as to reduce the amount of typing required.  None of the commands
42# below read it as part of their operation.
43#
44export NDKROOT=/path/to/android-ndk-r6
45
46
47# Modify this too.  Tell the build system which Android hardware you
48# are building for.  It needs to know this so it can compile in
49# support for the right Android-hw-specific ioctls.  (sigh.)  As with
50# NDKROOT above, this is merely to avoid repeated typing; none of the
51# commands read it.
52#
53# Currently the supported values are:  nexus_s pandaboard
54# So choose one of the below:
55#
56export HWKIND=nexus_s         # Samsung Nexus S; also Xoom (for now)
57export HWKIND=generic         # A generic Android device. eg, Pandaboard
58export HWKIND=emulator        # Android emulator
59
60# Then cd to the root of your Valgrind source tree.
61#
62cd /path/to/valgrind/source/tree
63
64
65# After this point, you don't need to modify anything; just copy and
66# paste the commands below.
67
68
69# Set up toolchain paths.
70#
71# For ARM
72export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
73export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
74export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
75
76# For x86
77export AR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
78export LD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
79export CC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
80
81# For MIPS32
82export AR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar
83export LD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld
84export CC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc
85
86# Do configuration stuff.  Don't mess with the --prefix in the
87# configure command below, even if you think it's wrong.
88# You may need to set the --with-tmpdir path to something
89# different if /sdcard doesn't work on the device -- this is
90# a known cause of difficulties.
91
92# The below re-generates configure, Makefiles, ...
93# This is not needed if you start from a release tarball.
94./autogen.sh
95
96# for ARM
97CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" \
98   CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" \
99   ./configure --prefix=/data/local/Inst \
100   --host=armv7-unknown-linux --target=armv7-unknown-linux \
101   --with-tmpdir=/sdcard
102# note: on android emulator, android-14 platform was also tested and works.
103# It is not clear what this platform nr really is.
104
105# for x86
106CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -DANDROID_HARDWARE_$HWKIND" \
107   CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86 -fno-pic" \
108   ./configure --prefix=/data/local/Inst \
109   --host=i686-android-linux --target=i686-android-linux \
110   --with-tmpdir=/sdcard
111
112# for MIPS32
113CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips -DANDROID_HARDWARE_$HWKIND" \
114   CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips" \
115   ./configure --prefix=/data/local/Inst \
116   --host=mipsel-linux-android --target=mipsel-linux-android \
117   --with-tmpdir=/sdcard
118
119# At the end of the configure run, a few lines of details
120# are printed.  Make sure that you see these two lines:
121#
122# For ARM:
123#          Platform variant: android
124#     Primary -DVGPV string: -DVGPV_arm_linux_android=1
125#
126# For x86:
127#          Platform variant: android
128#     Primary -DVGPV string: -DVGPV_x86_linux_android=1
129#
130# For mips32:
131#          Platform variant: android
132#     Primary -DVGPV string: -DVGPV_mips32_linux_android=1
133#
134# If you see anything else at this point, something is wrong, and
135# either the build will fail, or will succeed but you'll get something
136# which won't work.
137
138
139# Build, and park the install tree in `pwd`/Inst
140#
141make -j2
142make -j2 install DESTDIR=`pwd`/Inst
143
144
145# To get the install tree onto the device:
146# (I don't know why it's not "adb push Inst /data/local", but this
147# formulation does appear to put the result in /data/local/Inst.)
148#
149adb push Inst /
150
151# To run (on the device)
152/data/local/Inst/bin/valgrind [the usual args etc]
153
154
155# Once you're up and running, a handy modify-V-rebuild-reinstall
156# command line (on the host, of course) is
157#
158mq -j2 && mq -j2 install DESTDIR=`pwd`/Inst && adb push Inst /
159#
160# where 'mq' is an alias for 'make --quiet'.
161
162
163# One common cause of runs failing at startup is the inability of
164# Valgrind to find a suitable temporary directory.  On the device,
165# there doesn't seem to be any one location which we always have
166# permission to write to.  The instructions above use /sdcard.  If
167# that doesn't work for you, and you're Valgrinding one specific
168# application which is already installed, you could try using its
169# temporary directory, in /data/data, for example
170# /data/data/org.mozilla.firefox_beta.
171#
172# Using /system/bin/logcat on the device is helpful for diagnosing
173# these kinds of problems.
174