Howtocross-compileandrunonAndroid.Pleasereadtotheend,
sincethereareimportantdetailsfurtherdownregardingcrash
avoidanceandGPUsupport.
Thesenoteswerelastupdatedon4Nov2014,forValgrindSVN
revision14689/2987.
Theseinstructionsareknowntowork,orhaveworkedatsometimein
thepast,for:
arm:
Android4.0.3runningona(rooted,AOSPbuild)NexusS.
Android4.0.3runningonMotorolaXoom.
Android4.0.3runningonandroidarmemulator.
Android4.1runningonandroidemulator.
Android2.3.4onNexusSworkedatsometimeinthepast.
x86:
Android4.0.3runningonandroidx86emulator.
mips32:
Android4.1.2runningonandroidmipsemulator.
Android4.2.2runningonandroidmipsemulator.
Android4.3runningonandroidmipsemulator.
Android4.0.4runningonBROADCOMbcm7425
arm64:
Android4.5(?)runningonARMJuno
Onandroid-arm,GDBservermightinsertbreaksatwrongaddresses.
Feedbackonthiswelcome.
Otherconfigurationsandtoolchainsmightwork,buthaven'tbeentested.
Feedbackiswelcome.
Toolchain:
Forarm32,x86andmips32youneedtheandroid-ndk-r6native
developmentkit.r6bandr7giveanon-completely-workingbuild;
seehttp://code.google.com/p/android/issues/detail?id=23203
Fortheandroidemulator,theversionsneededandhowtoinstall
themaredescribedinREADME.android_emulator.
Youcangetandroid-ndk-r6from
http://dl.google.com/android/ndk/android-ndk-r6-linux-x86.tar.bz2
Forarm64(aarch64)youneedtheandroid-ndk-r10cNDK,from
http://dl.google.com/android/ndk/android-ndk-r10c-linux-x86_64.bin
InstalltheNDKsomewhere.Doesn'tmatterwhere.Then:
#Modifythis(obviously).Note,this"export"commandisonlydone
#soastoreducetheamountoftypingrequired.Noneofthecommands
#belowreaditaspartoftheiroperation.
#
exportNDKROOT=/path/to/android-ndk-r<version>
#ThencdtotherootofyourValgrindsourcetree.
#
cd/path/to/valgrind/source/tree
#Afterthispoint,youdon'tneedtomodifyanything.Justcopyand
#pastethecommandsbelow.
#Setuptoolchainpaths.
#
#ForARM
exportAR=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ar
exportLD=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-ld
exportCC=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
#Forx86
exportAR=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ar
exportLD=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-ld
exportCC=$NDKROOT/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc
#ForMIPS32
exportAR=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ar
exportLD=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-ld
exportCC=$NDKROOT/toolchains/mipsel-linux-android-4.8/prebuilt/linux-x86_64/bin/mipsel-linux-android-gcc
#ForARM64(AArch64)
exportAR=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar
exportLD=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-ld
exportCC=$NDKROOT/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc
#Doconfigurationstuff.Don'tmesswiththe--prefixinthe
#configurecommandbelow,evenifyouthinkit'swrong.
#Youmayneedtosetthe--with-tmpdirpathtosomething
#differentif/sdcarddoesn'tworkonthedevice--thisis
#aknowncauseofdifficulties.
#Thebelowre-generatesconfigure,Makefiles,...
#Thisisnotneededifyoustartfromareleasetarball.
./autogen.sh
#forARM
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm"\
CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm"\
./configure--prefix=/data/local/Inst\
--host=armv7-unknown-linux--target=armv7-unknown-linux\
--with-tmpdir=/sdcard
#note:onandroidemulator,android-14platformwasalsotestedandworks.
#Itisnotclearwhatthisplatformnrreallyis.
#forx86
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86"\
CFLAGS="--sysroot=$NDKROOT/platforms/android-9/arch-x86-fno-pic"\
./configure--prefix=/data/local/Inst\
--host=i686-android-linux--target=i686-android-linux\
--with-tmpdir=/sdcard
#forMIPS32
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips"\
CFLAGS="--sysroot=$NDKROOT/platforms/android-18/arch-mips"\
./configure--prefix=/data/local/Inst\
--host=mipsel-linux-android--target=mipsel-linux-android\
--with-tmpdir=/sdcard
#forARM64(AArch64)
CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64"\
CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm64"\
./configure--prefix=/data/local/Inst\
--host=aarch64-unknown-linux--target=aarch64-unknown-linux\
--with-tmpdir=/sdcard
#Attheendoftheconfigurerun,afewlinesofdetails
#areprinted.Makesurethatyouseethesetwolines:
#
#ForARM:
#Platformvariant:android
#Primary-DVGPVstring:-DVGPV_arm_linux_android=1
#
#Forx86:
#Platformvariant:android
#Primary-DVGPVstring:-DVGPV_x86_linux_android=1
#
#Formips32:
#Platformvariant:android
#Primary-DVGPVstring:-DVGPV_mips32_linux_android=1
#
#ForARM64(AArch64):
#Platformvariant:android
#Primary-DVGPVstring:-DVGPV_arm64_linux_android=1
#
#Ifyouseeanythingelseatthispoint,somethingiswrong,and
#eitherthebuildwillfail,orwillsucceedbutyou'llgetsomething
#whichwon'twork.
#Build,andparktheinstalltreein`pwd`/Inst
#
make-j4
make-j4installDESTDIR=`pwd`/Inst
#Togettheinstalltreeontothedevice:
#(Idon'tknowwhyit'snot"adbpushInst/data/local",butthis
#formulationdoesappeartoputtheresultin/data/local/Inst.)
#
adbpushInst/
#Torun(onthedevice).Therearetwothingsyouneedtoconsider:
#
#(1)ifyouarerunningontheAndroidemulator,Valgrindmaycrash
#atstartup.Thisisbecausetheemulator(forARM)maynotbe
#simulatingahardwareTLSregister.Togetaroundthis,run
#Valgrindwith:
#--kernel-variant=android-no-hw-tls
#
#(2)ifyouarerunningarealdevice,youneedtotellValgrind
#whatGPUithas,soValgrindknowshowtohandlecustomGPU
#ioctls.Youcanchooseoneofthefollowing:
#--kernel-variant=android-gpu-sgx5xx#PowerVRSGX5XXseries
#--kernel-variant=android-gpu-adreno3xx#QualcommAdreno3XXseries
#Ifyoudon'tchooseone,theprogramwillstillrun,butMemcheck
#mayreportfalseerrorsaftertheprogramperformsGPU-specificioctls.
#
#Anyway:torunonthedevice:
#
/data/local/Inst/bin/valgrind[kernelvariantargs][theusualargsetc]
#Onceyou'reupandrunning,ahandymodify-V-rebuild-reinstall
#commandline(onthehost,ofcourse)is
#
mq-j2&&mq-j2installDESTDIR=`pwd`/Inst&&adbpushInst/
#
#where'mq'isanaliasfor'make--quiet'.
#Onecommoncauseofrunsfailingatstartupistheinabilityof
#Valgrindtofindasuitabletemporarydirectory.Onthedevice,
#theredoesn'tseemtobeanyonelocationwhichwealwayshave
#permissiontowriteto.Theinstructionsaboveuse/sdcard.If
#thatdoesn'tworkforyou,andyou'reValgrindingonespecific
#applicationwhichisalreadyinstalled,youcouldtryusingits
#temporarydirectory,in/data/data,forexample
#/data/data/org.mozilla.firefox_beta.
#
#Using/system/bin/logcatonthedeviceishelpfulfordiagnosing
#thesekindsofproblems.