How to cross-compile gperftools for android using crystax-NDK & autotools? - android

My final goal is to be able to profile native code (C++) in android environments using gperftools.
My environment/Tools:
ubuntu 14.04
crystax-ndk-10.2.1
gcc-4.8.4
gperftools-2.4
(1)
I followed through this to make a standalone toolchain for later use:
Cross compiling for arm using crystax NDK
command:
./build/tools/make-standalone-toolchain.sh --system=linux-x86_64 --toolchain=arm-linux-androideabi-4.8 --platform=android-8 --install-dir=$HOME/my-android-toolchain
(2)
Thankfully, I found a script that will simplify the ./configure work:
https://gist.github.com/nddrylliog/4688209
and just modified it a bit (put in gperftools-2.4 folder):
#!/bin/sh
export DEV_PREFIX=$HOME
export ANDROID_NDK=${DEV_PREFIX}/crystax-ndk-10.2.1/
export CROSS_COMPILE=arm-linux-androideabi
export ANDROID_PREFIX=$HOME/my-android-toolchain
export SYSROOT=${ANDROID_NDK}/platforms/android-8/arch-arm
export CROSS_PATH=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib
# export PREFIX=${DEV_PREFIX}/android/prefix
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include -I${DEV_PREFIX}/android/bionic"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"
./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} "$#"
(3)
And then I actually do the ./configure and make install:
I put this script in gperftools-2.4 folder and run it:
cd gperftools-2.4
./android_configure.sh --enable-frame-pointers --prefix=$(pwd)
sudo make && make install
cd ..
Result:
The above gives me this error:
src/static_vars.cc: In function 'void tcmalloc::SetupAtForkLocksHandler()':
src/static_vars.cc:119:39: error: 'pthread_atfork' was not declared in this scope
CentralCacheUnlockAll); // child calls after fork
I would appreciate if anyone could leave me some advice on this.
Extra:
I know there is a android-ndk-profiler but since I use CMake for the cross-compilation and I'm not quite sure how to mess with the Android.mk so at the moment I will try to use gperftools which works fine in linux build.

This is because pthread_atfork appeared in Android libc (Bionic) only from Android 5.0. In CrystaX NDK, not all API are replaced by libcrystax, in particular, all pthread_xxx API reside in libc. So the only way as of now to do what you want is either use android-21 as minimal platform, or modify gperftools sources, avoiding usage of pthread_atfork.
BTW, we're working on moving all pthread_xxx API into libcrystax, so I expect all such API will be available soon even for earlier Android versions.

Related

Cross Compiling ghostscript for android, what host should I use?

Hi Guys I am using this tutorial to build ghostscript-9.19 to be able to use in my android application to convert eps document to pdf. It fails while configure. Here are the logs
checking whether to enable maintainer-specific portions of Makefiles...
no
checking for gcc... arm-linux-androideabi-gcc --
sysroot=/<path>/android-ndk-
r11c/platforms/android-17/arch-arm/
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... configure: error: in
`/<path>/ghostscript-9.19/tiff-config':
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details
configure: error: libtiff configure script failed
This is the build file I am running
#!/bin/sh
# Compiles ghostscript for Android
# Make sure you have NDK_ROOT defined in .bashrc or .bash_profile
INSTALL_DIR="`pwd`/app/jni/gs"
SRC_DIR="`pwd`/../ghostscript-9.19"
cd $SRC_DIR
export
PATH="/<path>/android-ndk-r11c/toolchains/arm-
linux-androideabi-4.9/prebuilt/darwin-x86_64/bin:$PATH"
export SYS_ROOT="/<path>/Android/android-ndk-
r11c/platforms/android-17/arch-arm/"
export CC="arm-linux-androideabi-gcc --sysroot=$SYS_ROOT"
export LD="arm-linux-androideabi-ld"
export AR="arm-linux-androideabi-ar"
export RANLIB="arm-linux-androideabi-ranlib"
export STRIP="arm-linux-androideabi-strip"
mkdir -p $INSTALL_DIR
./configure --host=arm-linux-androideabi --build=x86_64-apple-darwin
--prefix=$INSTALL_DIR LIBS="-lc -lgcc"
make PREFIX=$INSTALL_DIR
make install DESTDIR=$INSTALL_DIR
exit 0
I am using --host=arm-linux-androideabi. What host should i use? What do I need to change in ghostScript project to make compile in successfully?
Any help is highly appreciated.
Cross compiling Ghostscript is pretty involved, partly because the Ghostscript build relies on building and running interim tools (genarch, genconf, mkromfs and echogs) which, obviously, must be built with the native compiler, rather than the cross compiler.
I think the problem you are seeing is because the call to the libtiff configure doesn't pass on the required options.
You may be better served grabbing, and tweaking the two files (a makefile and a header) from this commit:
Makefile for Android MuPDF libgs.so
and tweaking it to match your requirements.
There is a basic guide of what to do for cross compiling at the bottom of this page:
Ghostscript FAQ
I have a "project" to improve support for cross compiling, but it is slow going at the moment.

list: No such file or directory

I'm trying to cross port a big autotools project to Android, but I'm having some issues with the NDK configuration (I guess). When I run the configure script, everything goes well until I reach a point where the C++ Standard Template Library support is checked. Then configure: error: C++ Standard Template Libary unsupported shows up.
Taking a closer look into the config.log I found
/home/user/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c --sysroot=/home/user/android-ndk-r10e/platforms/android-21/arch-arm -Wall -O2 -DNDEBUG conftest.cpp >&5
conftest.cpp:30:16: fatal error: list: No such file or directory
#include <list>
These are the values for the environment variables
export ANDROID_NDK_ROOT=/home/user/android-ndk-r10e
export SYS_ROOT=/home/user/android-ndk-r10e/platforms/android-21/arch-arm
export ANDROID_EABI=arm-linux-androideabi-4.9
export ANDROID_TOOLCHAIN=${ANDROID_NDK_HOME}/toolchains/${ANDROID_EABI}/prebuilt/linux-x86_64
export CC="$ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_TOOLCHAIN/bin/arm-linux-androideabi-g++"
export CFLAGS="--sysroot=${SYS_ROOT}"
export LDFLAGS="--sysroot=${SYS_ROOT}"
export CXXFLAGS="--sysroot=${SYS_ROOT}"
I guess that I'm missing some includes or some libraries on the command (Although they should be in the sysroot folder).
Thanks for your help
According to http://developer.android.com/intl/es/ndk/guides/standalone_toolchain.html
The C++ Standard Template Library is not included in the pre-built toolchain. You need to install a standalone toolchain so a stl implementation is copied into the platform. See the Advanced Method section of the link above to solve it.

Error while Including third party module in kivy app

I am trying to import some third party module like pygoogle in my app when i run app in computer using kivy it works fine but when i make apk using buildozer it crashes every time then i find that i have to go in python-for-android and run this command to include module ./distribute.sh -m "pil ffmpeg kivy" but i still get error that
root#kali:~# cd ~/.buildozer/android/platform/python-for-android
root#kali:~/.buildozer/android/platform/python-for-android# ls
COPYING dist docs README.rst src
cythonizer.py distribute.sh LICENSE recipes tools
root#kali:~/.buildozer/android/platform/python-for-android# ./distribute.sh -m "pil ffmpeg kivy"
Check build dependencies for Kali
Avoid check build dependencies, unknow platform Kali
Check environment
No ANDROIDSDK environment set, abort
root#kali:~/.buildozer/android/platform/python-for-android#
I am using KAli Linux and please solve this someone ...it will be very helpfull to me
Try pasting the pygoogle folder in your app's directory, at the same level as main.py. Also, from the error, it looks like you need to set the ANDROIDSDK environment variable. See the docs.
I had a similar problem, and simply setting the ANDROIDSDK environment variable didn't sort it, but the following did.
Try the following and then run the ./distribute.sh -m "pil ffmpeg kivy" command from the same terminal(as the environment vars will only have been set for that terminal and any child processes), or alternatively, add these lines to your ~/.bashrc file for them to be permanent:
export ANDROIDSDK=/path/to/android-sdk
export ANDROIDNDK=/path/to/android-ndk
export ANDROIDNDKVER=rX
export ANDROIDAPI=X
# example
export ANDROIDSDK="/home/tito/code/android/android-sdk-linux_86"
export ANDROIDNDK="/home/tito/code/android/android-ndk-r7"
export ANDROIDNDKVER=r7
export ANDROIDAPI=14
Examples taken from here. I recommend having a look.

Building Valgrind for Android

Building valgrind-3.8.1 on ubuntu 12.04 with ndk-r6 or ndk-r8d failed with following error:
...
cc1: Error: not rekognized option "-marm"
priv/main_globals.c:1:0: Error: wrong Value (cortex-a8) for -mtune=switch
...
My build-script:
export NDKROOT=/home/stefan/android-ndk-r6-crystax-2
export HWKIND=generic
PATH=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin:$PATH
PATH=$PATH:$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/libexec/gcc/arm-linux-androideabi/4.4.3
export CROSS_COMPILE=arm-linux-androideabi-
export AR=${CROSS_COMPLIE}ar
export LD=${CROSS_COMPLIE}ld
export CC=${CROSS_COMPLIE}gcc
export CXX=${CROSS_COMPLIE}g++
export CPP=${CROSS_COMPLIE}cpp
./autogen.sh CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm"
./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/tmp
And finally
make
:)
Any ideas? THANKS
Also i would accept builded binaries ;))
For how to build Valgrind for Android (ARM) see: https://stackoverflow.com/a/19255251/313113
For how to run your app through Valgrind see: https://stackoverflow.com/a/19235439/313113
Follow the instructions on this page :
http://valgrind.org/docs/manual/dist.readme-android.html
You don't compile valgrind as embbeded for your application, but you compile a arm-compatible valgrind binary on your computer, linked with the android-ndk library, and then you can ship valgrind on some folder on your device or simulator. That's around 130 Mb of data.
Note that the device must be rooted.
Then, whenever you want to run valgrind with your android app, you will have to attach valgrind to the app. For that, look here : How to start an android app with valgrind

Building FIPS module for android

I am working on an android project that requires the cryptographic libraries that are present in the application to be FIPS certified. To my knowledge there are no FIPS validated JAVA security libraries. Boucy Castle is good but its not validated. After reading some forum posts, I found out that OpenSSL's FIPS module can be used with the help of NDK.
Right now I am trying to build the fips-openssl module for Android, to do that I have created a script for the environment variables for cross compiling.
I am using openssl-fips, and ndk-r8 for this project. I followed the fips guideline I found on google. I hope this gives a clear picture of what I am trying to do.
#! /bin/sh
export ANDROID_NDK="~/Android/android-ndk-r8"
export FIPS_SIG="${ANDROID_NDK}/incore"
export GCC_C1="/usr/lib/gcc/i686-pc-linux-gnu/4.7.0/"
export PATH=$PATH:"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin";
export MACHINE=armv71
export ARCH=arm.
export CROSS_COMPILE="arm-linux-androideabi-"
export SYSTEM=android
#export RELEASE=2.6.32.GMU
export ANDROID_DEV="$ANDROID_NDK/platforms/android-14/arch-arm/usr"
export HOSTCC=/usr/bin/gcc
when doing the make this is the error that i get.
arm-linux-androideabi-gcc: error trying to exec 'cc1': execvp: No such file or directory
make[1]: *** [cryptlib.o] Error 1
make[1]: Leaving directory `/home/abhiram/fips/openssl-fips-1.2.3/crypto'
make: *** [build_crypto] Error 1
When i do a "find", the cc1 executable is present in this specific directory.
find . -name cc1
./toolchains/mipsel-linux-android-4.4.3/prebuilt/linux-x86/libexec/gcc/mipsel-linux-android/4.4.3/cc1
./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/libexec/gcc/arm-linux-androideabi/4.4.3/cc1
./toolchains/x86-4.4.3/prebuilt/linux-x86/libexec/gcc/i686-android-linux/4.4.3/cc1
Looks like the problem is in the export statement, there is a blank space where a dash should be in the PATH line. Change this:
export PATH=$PATH:"${ANDROID_NDK}/toolchains/arm-linux-androideabi 4.4.3/prebuilt/linux-x86/bin";
to this:
export PATH=$PATH:"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin";
Also, your find shows that the cc1 executable is not in the path, so add its location to the path export as well:
export PATH=$PATH:"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin":"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/libexec/gcc/arm-linux-androideabi/4.4.3/";
Right now I am trying to build the fips-openssl module for Android, to do that I have created a script for the environment variables for cross compiling.
OpenSSL provides a script for Android, if you are interested. You can find it on the OpenSSL wiki: FIPS Library and Android.
when doing the make this is the error that i get:
arm-linux-androideabi-gcc: error trying to exec 'cc1'
It looks like your PATH does not include the cross-compile toolchain.
How are you invoking the script? You need to include a leading dot (".") to ensure the changes are applied to the current shell (and not the sub-shell that executes the script (which simply exits)).
Here' the first step of OpenSSL's build procedures for Android located at FIPS Library and Android. Notice the leading dot:
$ . .setenv-android.sh
The results of running the script set a bunch of variables used by the OpenSSL build system:
$ . ./setenv-android.sh
ANDROID_NDK_ROOT: /opt/android-ndk-r9
ANDROID_EABI: arm-linux-androideabi-4.6
ANDROID_API: android-14
ANDROID_SYSROOT: /opt/android-ndk-r9/platforms/android-14/arch-arm
ANDROID_TOOLCHAIN: /opt/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin
FIPS_SIG:
CROSS_COMPILE: arm-linux-androideabi-
ANDROID_DEV: /opt/android-ndk-r9/platforms/android-14/arch-arm/usr
"${ANDROID_NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/libexec/gcc/arm-linux-androideabi/4.4.3/"
I don't believe this is needed.
export ANDROID_NDK="~/Android/android-ndk-r8"
According to the folks on the Android NDK user list, you should set both ANDROID_NDK_ROOT and ANDROID_SDK_ROOT. The various NDK and SDK tools use those environmental variables. I suppose the SDK value would be "~/Android/android-sdk" for your installation.
See Recommended NDK Directory? for details.
I also think you should be using ANDROID_SYSROOT. Its not used by the NDK or SDK tools; rather, its used by OpenSSL and passed as sysroot during compile.

Categories

Resources