Compile command-line C application with Android NDK - android

I am trying to compile Frotz to run in a terminal emulator so it will execute on my Android Ice Cream Sandwich smartphone. Frotz is an open source Z-Machine interpreter for playing interactive fiction and is basically just a command-line application. I have done the following:
Downloaded Android NDK (android-ndk-r8d) and extracted it on my Windows 7 laptop. (Extracted to c:\android\android-ndk-r8d)
Downloaded and installed Cygwin, including all development packages. (So make is installed)
Using Cygwin, navigate to the folder containing the extracted Frotz makefile and source folder and try to execute make.
When I try run make, I encounter issues relating to curses.h not being found (but this issue is not the focus of this question; maybe a point for a followup question). When I do make dumb (which compiles a simplified version of Frotz), the compile succeeds and I am able to run it within Cygwin. But if I copy the compiled command-line application to the phone and try execute it, I get the following error:
not executable: magic 4D5A
I suspect the problem here is that the executable is now not compiled for the Arm architecture. The make file has the following line in it:
CC = gcc
which I have tried changing to:
CC = /cygdrive/c/android/android-ndk-r8d/toolchains/arm-linux-androideabi-4.7/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe
But now when I execute make, I get the following error message:
fatal error: signal.h: No such file or directory
I am very new to C development (and Android) and struggling to figure out how to change the makefile so that it will compile correctly for Android. I will include the complete makefile below and will appreciate whatever help anyone can offer in getting this to correctly compile for Android.
The complete Frotz makefile:
# Define your C compiler. I recommend gcc if you have it.
# MacOS users should use "cc" even though it's really "gcc".
#
CC = gcc
#CC = cc
# Define your optimization flags. Most compilers understand -O and -O2,
# Standard (note: Solaris on UltraSparc using gcc 2.8.x might not like this.)
#
OPTS = -O2
# Pentium with gcc 2.7.0 or better
#OPTS = -O2 -fomit-frame-pointer -malign-functions=2 -malign-loops=2 \
#-malign-jumps=2
# Define where you want Frotz installed. Usually this is /usr/local
PREFIX = /usr/local
MAN_PREFIX = $(PREFIX)
#MAN_PREFIX = /usr/local/share
CONFIG_DIR = $(PREFIX)/etc
#CONFIG_DIR = /etc
# Define where you want Frotz to look for frotz.conf.
#
CONFIG_DIR = /usr/local/etc
#CONFIG_DIR = /etc
#CONFIG_DIR = /usr/pkg/etc
#CONFIG_DIR =
# Uncomment this if you want color support. Most, but not all curses
# libraries that work with Frotz will support color.
#
COLOR_DEFS = -DCOLOR_SUPPORT
# Uncomment this if you have an OSS soundcard driver and want classical
# Infocom sound support.
#
#SOUND_DEFS = -DOSS_SOUND
# Uncomment this too if you're running BSD of some sort and are using
# the OSS sound driver.
#
#SOUND_LIB = -lossaudio
# Define your sound device
# This should probably be a command-line/config-file option.
#
#SOUND_DEV = /dev/dsp
#SOUND_DEV = /dev/sound
#SOUND_DEV = /dev/audio
# If your vendor-supplied curses library won't work, uncomment the
# location where ncurses.h is.
#
#INCL = -I/usr/local/include
#INCL = -I/usr/pkg/include
#INCL = -I/usr/freeware/include
#INCL = -I/5usr/include
#INCL = -I/path/to/ncurses.h
# If your vendor-supplied curses library won't work, uncomment the
# location where the ncurses library is.
#
#LIB = -L/usr/local/lib
#LIB = -L/usr/pkg/lib
#LIB = -L/usr/freeware/lib
#LIB = -L/5usr/lib
#LIB = -L/path/to/libncurses.so
# One of these must always be uncommented. If your vendor-supplied
# curses library won't work, comment out the first option and uncomment
# the second.
#
CURSES = -lcurses
#CURSES = -lncurses
# Uncomment this if your need to use ncurses instead of the
# vendor-supplied curses library. This just tells the compile process
# which header to include, so don't worry if ncurses is all you have
# (like on Linux). You'll be fine.
#
#CURSES_DEF = -DUSE_NCURSES_H
# Uncomment this if you're compiling Unix Frotz on a machine that lacks
# the memmove(3) system call. If you don't know what this means, leave it
# alone.
#
#MEMMOVE_DEF = -DNO_MEMMOVE
# Uncomment this if for some wacky reason you want to compile Unix Frotz
# under Cygwin under Windoze. This sort of thing is not reccomended.
#
#EXTENSION = .exe
#####################################################
# Nothing under this line should need to be changed.
#####################################################
SRCDIR = src
VERSION = 2.43d
NAME = frotz
BINNAME = $(NAME)
DISTFILES = bugtest
DISTNAME = $(BINNAME)-$(VERSION)
distdir = $(DISTNAME)
COMMON_DIR = $(SRCDIR)/common
COMMON_TARGET = $(SRCDIR)/frotz_common.a
COMMON_OBJECT = $(COMMON_DIR)/buffer.o \
$(COMMON_DIR)/err.o \
$(COMMON_DIR)/fastmem.o \
$(COMMON_DIR)/files.o \
$(COMMON_DIR)/hotkey.o \
$(COMMON_DIR)/input.o \
$(COMMON_DIR)/main.o \
$(COMMON_DIR)/math.o \
$(COMMON_DIR)/object.o \
$(COMMON_DIR)/process.o \
$(COMMON_DIR)/quetzal.o \
$(COMMON_DIR)/random.o \
$(COMMON_DIR)/redirect.o \
$(COMMON_DIR)/screen.o \
$(COMMON_DIR)/sound.o \
$(COMMON_DIR)/stream.o \
$(COMMON_DIR)/table.o \
$(COMMON_DIR)/text.o \
$(COMMON_DIR)/variable.o
CURSES_DIR = $(SRCDIR)/curses
CURSES_TARGET = $(SRCDIR)/frotz_curses.a
CURSES_OBJECT = $(CURSES_DIR)/ux_init.o \
$(CURSES_DIR)/ux_input.o \
$(CURSES_DIR)/ux_pic.o \
$(CURSES_DIR)/ux_screen.o \
$(CURSES_DIR)/ux_text.o \
$(CURSES_DIR)/ux_audio_none.o \
$(CURSES_DIR)/ux_audio_oss.o
DUMB_DIR = $(SRCDIR)/dumb
DUMB_TARGET = $(SRCDIR)/frotz_dumb.a
DUMB_OBJECT = $(DUMB_DIR)/dumb_init.o \
$(DUMB_DIR)/dumb_input.o \
$(DUMB_DIR)/dumb_output.o \
$(DUMB_DIR)/dumb_pic.o
TARGETS = $(COMMON_TARGET) $(CURSES_TARGET)
OPT_DEFS = -DCONFIG_DIR="\"$(CONFIG_DIR)\"" $(CURSES_DEF) \
-DVERSION="\"$(VERSION)\"" -DSOUND_DEV="\"$(SOUND_DEV)\""
COMP_DEFS = $(OPT_DEFS) $(COLOR_DEFS) $(SOUND_DEFS) $(SOUNDCARD) \
$(MEMMOVE_DEF)
FLAGS = $(OPTS) $(COMP_DEFS) $(INCL)
$(NAME): $(NAME)-curses
$(NAME)-curses: soundcard.h $(COMMON_TARGET) $(CURSES_TARGET)
$(CC) -o $(BINNAME)$(EXTENSION) $(TARGETS) $(LIB) $(CURSES) \
$(SOUND_LIB)
all: $(NAME) d$(NAME)
dumb: $(NAME)-dumb
d$(NAME): $(NAME)-dumb
$(NAME)-dumb: $(COMMON_TARGET) $(DUMB_TARGET)
$(CC) -o d$(BINNAME)$(EXTENSION) $(COMMON_TARGET) \
$(DUMB_TARGET) $(LIB)
.SUFFIXES:
.SUFFIXES: .c .o .h
.c.o:
$(CC) $(FLAGS) $(CFLAGS) -o $# -c $<
# If you're going to make this target manually, you'd better know which
# config target to make first.
#
common_lib: $(COMMON_TARGET)
$(COMMON_TARGET): $(COMMON_OBJECT)
#echo
#echo "Archiving common code..."
ar rc $(COMMON_TARGET) $(COMMON_OBJECT)
ranlib $(COMMON_TARGET)
#echo
curses_lib: config_curses $(CURSES_TARGET)
$(CURSES_TARGET): $(CURSES_OBJECT)
#echo
#echo "Archiving curses interface code..."
ar rc $(CURSES_TARGET) $(CURSES_OBJECT)
ranlib $(CURSES_TARGET)
#echo
dumb_lib: $(DUMB_TARGET)
$(DUMB_TARGET): $(DUMB_OBJECT)
#echo
#echo "Archiving dumb interface code..."
ar rc $(DUMB_TARGET) $(DUMB_OBJECT)
ranlib $(DUMB_TARGET)
#echo
soundcard.h:
#if [ ! -f $(SRCDIR)/soundcard.h ] ; then \
sh $(SRCDIR)/misc/findsound.sh $(SRCDIR); \
fi
install: $(NAME)
strip $(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 $(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall:
rm -f $(PREFIX)/bin/$(NAME)
rm -f $(MAN_PREFIX)/man/man6/$(NAME).6
deinstall: uninstall
install_dumb: d$(NAME)
strip d$(BINNAME)$(EXTENSION)
install -d $(PREFIX)/bin
install -d $(MAN_PREFIX)/man/man6
install -c -m 755 d$(BINNAME)$(EXTENSION) $(PREFIX)/bin
install -c -m 644 doc/d$(NAME).6 $(MAN_PREFIX)/man/man6
uninstall_dumb:
rm -f $(PREFIX)/bin/d$(NAME)
rm -f $(MAN_PREFIX)/man/man6/d$(NAME).6
deinstall_dumb: uninstall_dumb
distro: dist
dist: distclean
mkdir $(distdir)
#for file in `ls`; do \
if test $$file != $(distdir); then \
cp -Rp $$file $(distdir)/$$file; \
fi; \
done
find $(distdir) -type l -exec rm -f {} \;
tar chof $(distdir).tar $(distdir)
gzip -f --best $(distdir).tar
rm -rf $(distdir)
#echo
#echo "$(distdir).tar.gz created"
#echo
clean:
rm -f $(SRCDIR)/*.h $(SRCDIR)/*.a
rm -f $(COMMON_DIR)/*.o $(CURSES_DIR)/*.o $(DUMB_DIR)/*.o
distclean: clean
rm -f $(BINNAME)$(EXTENSION) d$(BINNAME)$(EXTENSION)
rm -f $(BINNAME).exe $(BINNAME).bak $(BINNAME).lib
rm -f *core $(SRCDIR)/*core
-rm -rf $(distdir)
-rm -f $(distdir).tar $(distdir).tar.gz
realclean: distclean
clobber: distclean
help:
#echo
#echo "Targets:"
#echo " frotz"
#echo " dfrotz"
#echo " install"
#echo " uninstall"
#echo " clean"
#echo " distclean"
#echo

With android-ndk-r8d, you don't need cygwin: make can be found in c:\android\android-ndk-r8d\prebuilt\windows32\bin.
Anyways, to use a makefile, you should follow the instructions in c:\android\android-ndk-r8d\STANDALONE-TOOLCHAIN.html

Related

Compiling AOSP Kernel with KASAN

I'm struggling to compile the Linux kernel for usage in AOSP with KASAN & KCOV enabled. I then intend to flash it to a Pixel 2 XL (taimen) and use Syzkaller to fuzz it.
This is what I did:
1. Build unmodified kernel (works)
My reference: https://source.android.com/setup/build/building-kernels
Determine branch... android-msm-wahoo-4.4-pie-qpr2
$ repo init -u https://android.googlesource.com/kernel/manifest -b android-msm-wahoo-4.4-pie-qpr2
$ repo sync -j8 -c
$ build/build.sh -j8
Connect phone via USB
$ adb reboot bootloader
$ fastboot boot out/android-msm-wahoo-4.4/dist/Image.lz4-dtb
(Works fine)
2. Build kernel with KASAN & KCOV (fails)
To change kernel config symbols, edit POST_DEFCONFIG_CMDS in build/build.config
Copy from https://source.android.com/setup/build/building-kernels#customize-config
Modify as needed, use -d to disable, -e to enable a config option
Result:
POST_DEFCONFIG_CMDS="check_defconfig && update_debug_config"
function update_debug_config() {
${KERNEL_DIR}/scripts/config --file ${OUT_DIR}/.config \
-d CONFIG_KERNEL_LZ4 \
-e CONFIG_KASAN \
-e CONFIG_KASAN_INLINE \
-e CONFIG_KCOV \
-e CONFIG_SLUB \
-e CONFIG_SLUB_DEBUG \
--set-val FRAME_WARN 0
(cd ${OUT_DIR} && \
make O=${OUT_DIR} $archsubarch CC=${CC} CROSS_COMPILE=${CROSS_COMPILE} olddefconfig)
}
$ build/build.sh -j8
But after
CHK include/generated/compile.h
I get many undefined reference errors to various asan-symbols, e.g.
undefined reference to __asan_alloca_poison.
I did some research and read about adding -fsantitize=address and -shared-libasan (or -shared-libsan) to CFLAGS AND LDFLAGS. I did that (for which I had to hard-code it into build/build.sh, isn't there a more convenient way?), but to no avail:
I ended up with
aarch64-linux-android-ld: -f may not be used without -shared.
So I tried reading up on ld's -shared flag and adding it to LDFLAGS (more like a guess really). Resulted in
aarch64-linux-android-ld: -r and -shared may not be used together.
Really don't know where to go from here and what's going wrong in general?
Any help really appreciated!
Update: At first it seemed that using gcc instead of clang seemed to resolve the issue. The phone boots up fine, buttons work, but the touchscreen does not respond. I am looking into the reasons...
Regarding the touchscreen you need to manually copy required drivers to the AOSP folder. You can obtain fresh drivers from the kernel source code.
cd ${CONTAINER_GIT_REPO} && \
cp arch/arm64/boot/Image.lz4-dtb \$AOSP/device/google/wahoo-kernel/Image.lz4-dtb && \
cp arch/arm64/boot/dtbo.img $AOSP/device/google/wahoo-kernel/dtbo.img && \
cp drivers/input/touchscreen/stm/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/power/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/synaptics_dsx_htc/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/lge/*.ko $AOSP/device/google/wahoo-kernel && \
cp drivers/input/touchscreen/lge/lgsic/*.ko $AOSP/device/google/wahoo-kernel && \
# Building final image for Pixel 2
cd \$AOSP && . build/envsetup.sh && lunch aosp_walleye-userdebug && make bootimage -j4
&& mkdir -p ${CONTAINER_GIT_REPO}/builded_images && \
cp out/target/product/walleye/*.img ${CONTAINER_GIT_REPO}/builded_images"
To obtain kernel source code:
git clone -b android-msm-wahoo-4.4-oreo-m2 --single-branch https://android.googlesource.com/kernel/msm
I have only Pixel 2 to check, but this should be applicable for both of them.
Update: You can check this repo for additional details https://gitlab.com/textor/build-pixel-2-in-docker
Maybe you can try to use the config file: ./private/msm-google/build.config.kasan
I used to use this config file and succeeded.
But the touchscreen didn't work, too.

Compile external module for Android

I am trying to compile a driver as a loadable module but whenever I adb shell into my phone and do an insmod test.ko I get the error message insmod: failed to load /data/local/tmp/test.ko: Exec format error. Grep'ing dmesg I find the following log: test: no symbol version for module_layout.
I've done quite a bit of googling [Ref] [Ref] [Ref] [Ref] [Ref] and reading the linux kbuild documentation txt files [Ref] [Ref] to no avail, so if someone knows the answer it'd be fab :) (I've only referenced the most helpful links I found).
What I've done so far is this:
I have an Qualcomm Aurora checkout and in the kernel directory I type the following
cp arch/arm64/configs/gemini_user_defconfig .config [B]# Has CONFIG_MODVERSIONS enabled and MODULE_SIG*=n[/B]
yes "" | make oldconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make prepare ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make scripts ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
make modules ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- V=1
I have my PATH set to point to /MyAOSBDir/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin so I pick up the correct toolchain.
At this point appears to be well. In my kernel directory I have Module.symvers, so I appear to be set.
Now to the directory I have set up outside of this build tree with a dummy test... The Makefile looks like this:
KERNEL_DIR:=/solomon-build/MiNote2AOSB/kernel/
obj-m += test.o
PWD := $(shell pwd)
.PHONY: all
all:
$(MAKE) M=$(PWD) ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -C $(KERNEL_DIR) modules V=1
clean:
$(MAKE) M=$(PWD) -C $(KERNEL_DIR) clean
The driver is just a dummy:
#include <linux/module.h> /* Needed by all modules */
#include <linux/kernel.h> /* Needed for KERN_INFO */
#include <linux/init.h> /* Needed for the macros */
static int __init hello_start(void)
{
printk(KERN_INFO "Hello world\n");
return 0;
}
static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye world\n");
}
module_init(hello_start);
module_exit(hello_end);
I do make make all at the comment line and get this output:
make M=/solomon-build/build_mxt_kmod ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- -C /solomon-build/MiNote2AOSB/kernel/ modules V=1
make[1]: Entering directory `/solomon-build/MiNote2AOSB/kernel'
test -e include/generated/autoconf.h -a -e include/config/auto.conf || ( \
echo >&2; \
echo >&2 " ERROR: Kernel configuration is invalid."; \
echo >&2 " include/generated/autoconf.h or include/config/auto.conf are missing.";\
echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
echo >&2 ; \
/bin/false)
mkdir -p /solomon-build/build_mxt_kmod/.tmp_versions ; rm -f /solomon-build/build_mxt_kmod/.tmp_versions/*
make -f ./scripts/Makefile.build obj=/solomon-build/build_mxt_kmod
./scripts/gcc-wrapper.py aarch64-linux-android-gcc -Wp,-MD,/solomon-build/build_mxt_kmod/.test.o.d -nostdinc -isystem /solomon-build/MiNote2AOSB/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I./arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -fno-pic -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(test)" -D"KBUILD_MODNAME=KBUILD_STR(test)" -c -o /solomon-build/build_mxt_kmod/.tmp_test.o /solomon-build/build_mxt_kmod/test.c
(cat /dev/null; echo kernel//solomon-build/build_mxt_kmod/test.ko;) > /solomon-build/build_mxt_kmod/modules.order
make -f ./scripts/Makefile.modpost
find /solomon-build/build_mxt_kmod/.tmp_versions -name '*.mod' | xargs -r grep -h '\.ko$' | sort -u | sed 's/\.ko$/.o/' | scripts/mod/modpost -m -i ./Module.symvers -I /solomon-build/build_mxt_kmod/Module.symvers -o /solomon-build/build_mxt_kmod/Module.symvers -S -E -w -s -T -
./scripts/gcc-wrapper.py aarch64-linux-android-gcc -Wp,-MD,/solomon-build/build_mxt_kmod/.test.mod.o.d -nostdinc -isystem /solomon-build/MiNote2AOSB/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin/../lib/gcc/aarch64-linux-android/4.9.x-google/include -I./arch/arm64/include -Iarch/arm64/include/generated -Iinclude -I./arch/arm64/include/uapi -Iarch/arm64/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -std=gnu89 -mgeneral-regs-only -fno-pic -fno-delete-null-pointer-checks -Os -Wno-maybe-uninitialized --param=allow-store-data-races=0 -Wframe-larger-than=2048 -fstack-protector -Wno-unused-but-set-variable -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(test.mod)" -D"KBUILD_MODNAME=KBUILD_STR(test)" -DMODULE -c -o /solomon-build/build_mxt_kmod/test.mod.o /solomon-build/build_mxt_kmod/test.mod.c
aarch64-linux-android-ld -EL -r -T ./scripts/module-common.lds --build-id --fix-cortex-a53-843419 -o /solomon-build/build_mxt_kmod/test.ko /solomon-build/build_mxt_kmod/test.o /solomon-build/build_mxt_kmod/test.mod.o
make[1]: Leaving directory `/solomon-build/MiNote2AOSB/kernel'
So, there are no messages saying there is a missing Module.symvers, so that's good, and I do get a built .ko file.
What I don't understand is the message ERROR: Kernel configuration is invalid. The files it is talking about exist, so I know they have been created in my kernel build.
Anyway, trying to insmod this onto the phone gives the message I mentioned previously. If I cat Module.symvers I see:
0xff924338 backlight_force_update drivers/video/backlight/backlight EXPORT_SYMBOL
0x30254daf test_iosched_register block/test-iosched EXPORT_SYMBOL
<snip>
0xdd502540 backlight_device_unregister drivers/video/backlight/backlight EXPORT_SYMBOL
0x9939eba0 backlight_unregister_notifier drivers/video/backlight/backlight EXPORT_SYMBOL
So no symbol module_layout in the file, and thus no CRC, which is what I presume is creating the error message?
Any clues would be much appreciated, thank you.
Oh I should also mention that the module and kernel vermagic match:
# modinfo /data/local/tmp/test.ko
filename: /data/local/tmp/test.ko
depends:
vermagic: 3.18.20-mytestkernel-perf-g671c431-dirty SMP preempt mod_unload modversions aarch64
# uname -a
Linux localhost 3.18.20-mytestkernel-perf-g671c431-dirty #1 SMP PREEMPT Mon Jun 5 15:46:13 BST 2017 aarch64
*EDIT - FOUND SOLUTION - NEW QUESTON *:
I've gotten much further since posting. What I realised was, was that the compilation of the kernel using the Android build system is producing a radically different Module.symvers one from my method above (for some reason it took a while for the penny to drop and for me to check the Andoird build output - duh!). In fact, I've realised I always had the Module.symvers file, it was just located in ../out/target/product/msm8996/obj/KERNEL_OBJ/Module.symvers relative to the kernel dir. Copying this file into kernel and re-running my module build now produces a module that loads correctly :)
So, I guess the question becomes, why do the two files differ? What is Android doing differently? I assume it is setting up some more detailed config, but how/what/why?
So, the answer was relatively simple in the end...
I just use the normal Android build process of sourcing envsetup.sh, running lunch and then building the kernel:
. build/envsetup.sh
lunch msm8996-userdebug
make kernel -j16
(Remember to make sure in your .config file to set CONFIG_MODULES=y and set any kernel drivers to =m if you want them as modules).
In the separate directory, not in the Android build tree I now have my new module and the following Makefile, which now looks like this:
MY_ANDROID_ROOT_DIR :=/path/to/my/android/checkout
KERNEL_DIR:=$(MY_ANDROID_ROOT_DIR)/kernel
obj-m += my_driver.o
PWD := $(shell pwd)
.PHONY: all
all:
$(MAKE) \
M=$(PWD) \
ARCH=arm64 \
CROSS_COMPILE=aarch64-linux-android- \
-C $(KERNEL_DIR) \
modules \
V=1 \
O=$(MY_ANDROID_ROOT_DIR)/out/target/product/msm8996/obj/KERNEL_OBJ
clean:
$(MAKE) M=$(PWD) -C $(KERNEL_DIR) clean
The make all output will still be in your modules directory (not the Android output dir).
This is basically identical to all of the examples relating to pure Linux builds. The only extra bit of information I needed to provide was where the Android build system output its build files, which is O=$(MY_ANDROID_ROOT_DIR)/out/target/product/<your-product>/obj/KERNEL_OBJ.
The O= define tells Make where to find the output of the kernel build.
The 'V=1` define tells Make to output verbose build information.
modules is a kernel target that will build you module defined in the Makefile variable obj-m. This variable "specifies the object files which are built as loadable kernel modules".
Now my modules build fine and I don't need to worry about independently compiling the kernel or anything like that to fix missing file messages (although it will still output about autoconf.h, which I don't understand because it exists in my tree and doesn't seem to stop my modules working).
PS If you module includes more than one file define obj-m += my_driver.o and then my_driver-m:= <extra objects>.

Compilation error using buildozer. NDK location issue

I have buildozer installed but I can't compile an apk. I am on windows so I have an Ubuntu 64 bits VM with oracle VM.
I donwload and install again cython, and configure several previous errors to be able to use python_for_android.
When I try to run the buildozer android debug command I get the next result
Welcome to the Buildozer Virtual Machine.
Please see ~/Desktop/README.txt for more information
kivy#kivy-VirtualBox:~/Desktop/Kivy_apps/HelloKivy$ buildozer android debug
# Check configuration tokens
# Ensure build layout
# Check configuration tokens
# Preparing build
# Check requirements for android
# Run 'dpkg --version'
# Cwd None
Debian `dpkg' package management program version 1.17.5 (amd64).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
# Search for Git (git)
# -> found at /usr/bin/git
# Search for Cython (cython)
# -> found at /usr/local/bin/cython
# Search for Java compiler (javac)
# -> found at /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
# Search for Java keytool (keytool)
# -> found at /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/keytool
# Install platform
# Run 'ln -sf /usr/local/lib/python2.7/dist-packages/python-for-android ./python-for-android'
# Cwd /home/kivy/Desktop/Kivy_apps/HelloKivy/.buildozer/android/platform
# Apache ANT found at /home/kivy/.buildozer/android/platform/apache-ant-1.9.4
# Android SDK found at /home/kivy/.buildozer/android/platform/android-sdk-21
# Android NDK found at /home/kivy/.buildozer/android/platform/android-ndk-r9c
# Check application requirements
# Run './distribute.sh -l'
# Cwd /home/kivy/Desktop/Kivy_apps/HelloKivy/.buildozer/android/platform/python-for-android
Available modules: android apsw audiostream bidi boost cherrypy c_igraph cprotobuf cymunk django docutils ecdsa enum34 evdev ffmpeg ffmpeg2 ffpyplayer freetype gevent greenlet harfbuzz hostpython igraph jpeg kivent_core kivent_cymunk kivy leveldb libevent libpq libsodium libswift libtorrent libxml2 libxslt libyaml lxml m2crypto midistream msgpack mysql_connector netifaces numpy opencv openssl paramiko pil plyer plyvel png polygon protobuf psutil psycopg2 pyasn1 pycrypto pygame pyjnius pylibpd pyopenssl pyparsing pyqrcode python pyyaml sdl setuptools six sqlalchemy sqlite3 storm swift thrift twisted txws wokkel zeroconf zope
# Application requirements already installed, pass
# Check garden requirements
# Compile platform
# Run './distribute.sh -l'
# Cwd /home/kivy/Desktop/Kivy_apps/HelloKivy/.buildozer/android/platform/python-for-android
Available modules: android apsw audiostream bidi boost cherrypy c_igraph cprotobuf cymunk django docutils ecdsa enum34 evdev ffmpeg ffmpeg2 ffpyplayer freetype gevent greenlet harfbuzz hostpython igraph jpeg kivent_core kivent_cymunk kivy leveldb libevent libpq libsodium libswift libtorrent libxml2 libxslt libyaml lxml m2crypto midistream msgpack mysql_connector netifaces numpy opencv openssl paramiko pil plyer plyvel png polygon protobuf psutil psycopg2 pyasn1 pycrypto pygame pyjnius pylibpd pyopenssl pyparsing pyqrcode python pyyaml sdl setuptools six sqlalchemy sqlite3 storm swift thrift twisted txws wokkel zeroconf zope
# Clean and build python-for-android
# Run './distribute.sh -m "kivy" -d "myapp"'
# Cwd /home/kivy/Desktop/Kivy_apps/HelloKivy/.buildozer/android/platform/python-for-android
Check build dependencies for Ubuntu
Check environment
SDK located at /home/kivy/.buildozer/android/platform/android-sdk-21
NDK located at /home/kivy/.buildozer/android/platform/android-ndk-r9c
NDK version is r9c
API level set to 14
Check NDK location
Check mandatory tools
Distribution will be located at /usr/local/lib/python2.7/dist-packages/python-for-android/dist/myapp
Entering in ARM environment
Compiler found at /home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin//arm-linux-androideabi-gcc
PATH is /home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/:/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/:/home/kivy/.buildozer/android/platform/android-ndk-r9c:/home/kivy/.buildozer/android/platform/android-sdk-21/tools:/home/kivy/.buildozer/android/platform/apache-ant-1.9.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Leaving ARM environment
Read kivy recipe
Module kivy depend on pygame pyjnius android
Read pygame recipe
Module pygame depend on python sdl
Read pyjnius recipe
Module pyjnius depend on python sdl
Read android recipe
Module android depend on pygame
Read python recipe
Module python depend on hostpython
Read sdl recipe
Module sdl depend on python
Ignored python, already processed
Ignored sdl, already processed
Ignored pygame, already processed
Read hostpython recipe
Ignored python, already processed
Modules changed to hostpython python sdl pygame pyjnius android kivy
Pure-Python modules changed to
Run get packages
Download package for hostpython
Module hostpython already downloaded
Download package for python
Module python already downloaded
Download package for sdl
No package for sdl
Download package for pygame
Module pygame already downloaded
Download package for pyjnius
Module pyjnius already downloaded
Download package for android
No package for android
Download package for kivy
Module kivy already downloaded
Run prebuild
Call prebuild_hostpython
Call prebuild_python
Call prebuild_sdl
Call prebuild_pygame
Call prebuild_pyjnius
Call prebuild_android
Call prebuild_kivy
Run build
Skipped build_hostpython
Call build_python
Entering in ARM environment
Compiler found at /home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin//arm-linux-androideabi-gcc
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux3
checking EXTRAPLATDIR...
[...]
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
./configure --host=arm-eabi --build=x86_64-linux-gnu OPT= --prefix=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install --enable-shared --disable-toolbox-glue --disable-framework
[...]
cp: cannot stat ‘HOSTPYTHON=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython’: No such file or directory
First install (failing..)
arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -c -fno-strict-aliasing -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -DNDEBUG -I. -IInclude -I./Include -fPIC -DPy_BUILD_CORE -DPYTHONPATH='":plat-linux3:lib-tk:lib-old"' \
-DPREFIX='"/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install"' \
-DEXEC_PREFIX='"/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install"' \
-DVERSION='"2.7"' \
-DVPATH='""' \
-o Modules/getpath.o ./Modules/getpath.c
# Substitution happens here, as the completely-expanded BINDIR
# is not available in configure
/usr/bin/install -c -m 644 ./Include/Python-ast.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
sed -e "s,#EXENAME#,/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python2.7," < ./Misc/python-config.in >python-config
/usr/bin/install -c -m 644 ./Misc/python.man \
/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/share/man/man1/python2.7.1
/usr/bin/install -c -m 644 ./Include/Python.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/
[...]
/usr/bin/install -c -m 644 ./Include/osdefs.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
rm -f libpython2.7.a
if test libpython2.7.so != libpython2.7.so; then \
arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -shared -lm -Wl,-hlibpython2.7.so -o libpython2.7.so Modules/getbuildinfo.
[...]
Modules/xmltok.o Modules/pyexpat.o Modules/xxsubtype.o -L/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib -lz -ldl -lm ; \
ln -f libpython2.7.so libpython2.7.so; \
else \
arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -shared -lm -o libpython2.7.so Modules/getbuildinfo.o Parser/acceler.o P
[...]
cStringIO.o Modules/cPickle.o Modules/zlibmodule.o Modules/xmlparse.o Modules/xmlrole.o Modules/xmltok.o Modules/pyexpat.o Modules/xxsubtype.o -L/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib -lz -ldl -lm ; \
fi
/usr/bin/install -c -m 644 ./Include/parsetok.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
arm-linux-androideabi-ar rc libpython2.7.a Modules/getbuildinfo.o
/usr/bin/install -c -m 644 ./Include/patchlevel.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install
[...]
/usr/bin/install -c -m 644 ./Include/weakrefobject.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
/usr/bin/install -c -m 644 pyconfig.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/
[...]
Modules/xmlparse.o Modules/xmlrole.o Modules/xmltok.o Modules/pyexpat.o Modules/xxsubtype.o
arm-linux-androideabi-ranlib libpython2.7.a
arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -lm -Xlinker -export-dynamic -o python \
Modules/python.o \
-L. -lpython2.7 -ldl -L/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib -lz -lm
/usr/bin/install -c python /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python2.7
if test -f libpython2.7.so; then \
if test -n "" ; then \
/usr/bin/install -c -m 555 /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin; \
else \
/usr/bin/install -c -m 555 libpython2.7.so /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/libpython2.7.so; \
if test libpython2.7.so != libpython2.7.so; then \
(cd /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib; ln -sf libpython2.7.so libpython2.7.so) \
fi \
fi; \
else true; \
fi
if test -f /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python -o -h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python; \
then rm -f /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python; \
else true; \
fi
(cd /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin; ln python2.7 python)
rm -f /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python-config
(cd /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin; ln -s python2.7-config python-config)
test -d /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/pkgconfig || /usr/bin/install -c -d -m 755 /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/pkgconfig
rm -f /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/pkgconfig/python.pc
(cd /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/pkgconfig; ln -s python-2.7.pc python.pc)
running build
running build_ext
INFO: Can't locate Tcl/Tk libs and/or headers
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _curses _curses_panel
_sqlite3 _ssl _tkinter
bsddb185 bz2 dbm
dl gdbm imageop
linuxaudiodev nis ossaudiodev
readline spwd sunaudiodev
zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
running build_scripts
CC='arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm' LDSHARED='arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -shared -lm' OPT='-DNDEBUG ' \
LD_LIBRARY_PATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2: /usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython -E ./setup.py install \
--skip-build \
--prefix=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install \
--install-scripts=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin \
--install-platlib=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/lib-dynload \
--root=/
Creating directory /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/lib-tk/test/test_tkinter
[...]
/usr/bin/install -c -m 644 ./Lib/BaseHTTPServer.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
copying build/scripts-2.7/2to3 -> /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin
/usr/bin/install -c -m 644 ./Lib/Bastion.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
changing mode of /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/pydoc to 775
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/lib-dynload/Python-2.7.2-py2.7.egg-info
Writing /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/lib-dynload/Python-2.7.2-py2.7.egg-info
/usr/bin/install -c -m 644 ./Lib/ConfigParser.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/Cookie.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/DocXMLRPCServer.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/compileall.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
[...]
/usr/bin/install -c ./Lib/plat-linux3/regen /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/plat-linux3
/usr/bin/install -c -m 644 ./LICENSE /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/LICENSE.txt
PYTHONPATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2: \
/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython -Wi -tt /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/compileall.py \
-d /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7 -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
Listing /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7 ...
Compiling /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/CGIHTTPServer.py ...
[...]
Compiling /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/xml/sax/expatreader.py ...
[...]
PYTHONPATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2: \
/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython -Wi -t /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/compileall.py \
-d /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/site-packages -f \
-x badsyntax /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/site-packages
make: [libinstall] Error 1 (ignored)
Listing /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/site-packages ...
Second install.
/usr/bin/install -c python /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/python2.7
if test -f libpython2.7.so; then \
if test -n "" ; then \
/usr/bin/install -c -m 555 /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin; \
else \
/usr/bin/install -c -m 555 libpython2.7.so /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/libpython2.7.so; \
if test libpython2.7.so != libpython2.7.so; then \
(cd /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib; ln -sf libpython2.7.so libpython2.7.so) \
fi \
fi; \
else true; \
fi
# Substitution happens here, as the completely-expanded BINDIR
/usr/bin/install -c -m 644 ./Include/Python-ast.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
/usr/bin/install -c -m 644 ./Include/Python.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
# is not available in configure
/usr/bin/install -c -m 644 ./Include/abstract.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
[...]
running build
running build_ext
/usr/bin/install -c -m 644 ./Include/descrobject.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
/usr/bin/install -c -m 644 ./Include/dictobject.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
/usr/bin/install -c -m 644 ./Include/dtoa.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
[...]
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _curses _curses_panel
_sqlite3 _ssl _tkinter
bsddb185 bz2 dbm
dl gdbm imageop
linuxaudiodev nis ossaudiodev
readline spwd sunaudiodev
zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
running build_scripts
/usr/bin/install -c -m 644 ./Include/funcobject.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
/usr/bin/install -c -m 644 ./Include/genobject.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
/usr/bin/install -c -m 644 ./Include/intrcheck.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
CC='arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm' LDSHARED='arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm -shared -lm' OPT='-DNDEBUG ' \
LD_LIBRARY_PATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2: /usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython -E ./setup.py install \
--skip-build \
--prefix=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install \
--install-scripts=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin \
--install-platlib=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/lib-dynload \
--root=/
[...]
running install_scripts
copying build/scripts-2.7/2to3 -> /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin
/usr/bin/install -c -m 644 ./Include/stringobject.h /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/include/python2.7
copying build/scripts-2.7/idle -> /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin
/usr/bin/install -c -m 644 ./Lib/calendar.py /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7
changing mode of /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/bin/pydoc to 775
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/lib-dynload/Python-2.7.2-py2.7.egg-info
[...]
/usr/bin/install -c -m 644 ./LICENSE /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/LICENSE.txt
Compiling /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/BaseHTTPServer.py ...
Compiling /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/Bastion.py ...
[...]
Compiling /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/zipfile.py ...
PYTHONPATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2: \
/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython -Wi -t /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/compileall.py \
-d /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/site-packages -f \
-x badsyntax /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/site-packages
make: [libinstall] Error 1 (ignored)
Listing /usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7/site-packages ...
PYTHONPATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python-install/lib/python2.7 LD_LIBRARY_PATH=/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2: \
/usr/local/lib/python2.7/dist-packages/python-for-android/build/python/Python-2.7.2/hostpython -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
Leaving ARM environment
Call build_sdl
Entering in ARM environment
Compiler found at /home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin//arm-linux-androideabi-gcc
find: `/usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/application/src/': No such file or directory
Android NDK: WARNING:/usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/application/Android.mk:application: non-system libraries in linker flags: -lpython2.7
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:/usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/png/Android.mk:png: LOCAL_LDLIBS is always ignored for static libraries
rm -f /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/armeabi/lib*.so /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/armeabi-v7a/lib*.so /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/mips/lib*.so /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/x86/lib*.so
rm -f /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/armeabi/gdbserver /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/armeabi-v7a/gdbserver /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/mips/gdbserver /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/x86/gdbserver
rm -f /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/armeabi/gdb.setup /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/armeabi-v7a/gdb.setup /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/mips/gdb.setup /usr/local/lib/python2.7/dist-packages/python-for-android/src/libs/x86/gdb.setup
[armeabi] Compile thumb : sdl <= SDL_pixels.c
/home/kivy/.buildozer/android/platform/android-ndk-r9c/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -MMD -MP -MF /usr/local/lib/python2.7/dist-packages/python-for-android/src/obj/local/armeabi/objs/sdl/src/video/android/SDL_pixels.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -I/usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/sdl -DANDROID -I/usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/sdl/include -DSDL_JAVA_PACKAGE_PATH=org_renpy_android -DSDL_CURDIR_PATH=\"org.renpy.android\" -DSDL_TRACKBALL_KEYUP_DELAY=1 -DSDL_VIDEO_RENDER_RESIZE=0 -DSDL_ANDROID_KEYCODE_MOUSE=UNKNOWN -DSDL_ANDROID_KEYCODE_0=SPACE -DSDL_ANDROID_KEYCODE_1=RETURN -DSDL_ANDROID_KEYCODE_2=LCTRL -DSDL_ANDROID_KEYCODE_3=LALT -DSDL_ANDROID_KEYCODE_4=RETURN -Wa,--noexecstack -Wformat -Werror=format-security -I/home/kivy/.buildozer/android/platform/android-ndk-r9c/platforms/android-14/arch-arm/usr/include -c /usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/sdl/src/video/android/SDL_pixels.c -o /usr/local/lib/python2.7/dist-packages/python-for-android/src/obj/local/armeabi/objs/sdl/src/video/android/SDL_pixels.o
/usr/local/lib/python2.7/dist-packages/python-for-android/src/jni/../jni/sdl/src/video/android/SDL_pixels.c:35:22: fatal error: SDL_blit.h: No such file or directory
compilation terminated.
make: *** [/usr/local/lib/python2.7/dist-packages/python-for-android/src/obj/local/armeabi/objs/sdl/src/video/android/SDL_pixels.o] Error 1
# Command failed: ./distribute.sh -m "kivy" -d "myapp"
#
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2
I have installed the ndk and the sdk but seems to be unreachable by the command on compilation. I try to change and export the PATH to the NDK and the SDK but didn't work. May be I have a wrong config on the Android.mk or in other place.
I am try to use the default API level 14.

Android valgrind build fails

Hello I'm trying to build valgrind for android-arm. On Linux Mint 13 it fails with:
$ make
echo "# This is a generated file, composed of the following suppression rules:" > default.supp
echo "# " exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
cat exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp >> default.supp
make all-recursive
make[1]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
Making all in include
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/include'
Making all in VEX
make[2]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make all-am
make[3]: Entering directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../include -I../VEX/pub -DVGA_arm=1 -DVGO_linux=1 -DVGP_arm_linux=1 -DVGPV_arm_linux_vanilla=1 -Ipriv -m32 -O2 -g -Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-declarations -Wno-format-zero-length -fno-strict-aliasing -fno-builtin -marm -mcpu=cortex-a8 -Wbad-function-cast -Wcast-qual -Wcast-align -fstrict-aliasing -Wno-long-long -Wno-pointer-sign -fno-stack-protector -MT libvex_arm_linux_a-main_globals.o -MD -MP -MF .deps/libvex_arm_linux_a-main_globals.Tpo -c -o libvex_arm_linux_a-main_globals.o `test -f 'priv/main_globals.c' || echo './'`priv/main_globals.c
gcc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
cc1: error: unrecognised command line option ‘-marm’
priv/main_globals.c:1:0: error: bad value (cortex-a8) for -mtune= switch
make[3]: *** [libvex_arm_linux_a-main_globals.o] Error 1
make[3]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1/VEX'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/matt/Desktop/valgrind/valgrind-3.8.1'
make: *** [all] Error 2
I am using ndk-r8e and valgrind 3.8.1. The configure ends with:
Maximum build arch: arm
Primary build arch: arm
Secondary build arch:
Build OS: linux
Primary build target: ARM_LINUX
Secondary build target:
Platform variant: vanilla
Primary -DVGPV string: -DVGPV_arm_linux_vanilla=1
Default supp files: exp-sgcheck.supp xfree-3.supp xfree-4.supp glibc-2.X-drd.supp glibc-2.34567-NPTL-helgrind.supp glibc-2.X.supp
What can I do to fix this? Alternatively, are there any pre-built android-arm valgrind binaries that I can use?
For building and installing Valgrind for Android use the bash script below, which I prefer to call build_valgrind.sh
To run with RUN_HELLO_JNI_THROUGH_VALGRIND=true you need two additional scripts (bootstrap_valgrind.sh, start_valgrind.sh) in the directory you run the script below from.
Running the script with the RUN_HELLO_JNI_THROUGH_VALGRIND=true flag will build the hello-jni application from the samples directory inside the Android NDK HOME, deploy it to the phone and run it through Valgrind, using either callgrind or memcheck tool, which you can specify in the start_valgrind.sh script.
The other two scripts are described here: https://stackoverflow.com/a/19235439/313113
Here's my directory structure:
|-- build_valgrind.sh (the script below)
|-- bootstrap_valgrind.sh (second script from https://stackoverflow.com/a/19235439/313113)
|-- start_valgrind.sh (first script from https://stackoverflow.com/a/19235439/313113)
|-- valgrind-3.10.0 (will be extracted by build_valgrind.sh)
`-- valgrind-3.10.0.tar.bz2 (will be downloaded by build_valgrind.sh)
I've tested that its working (memcheck and callgrind tools) on a Samsung Galaxy Nexus device with CyanogenMod 10.2.1 and Android 4.3.1 and CyanogenMod 11 20140804 snapshot, Android 4.4.4
You can see the file size of the generated output with: adb shell ls -lR "/sdcard/*grind*"
The build_valgrind.sh script:
#!/usr/bin/env bash
#set -x
function extract()
{
if [ -f "$1" ] ; then
case "$1" in
*.tar.bz2) tar xvjf "$1" ;;
*.tar.gz) tar xvzf "$1" ;;
*.bz2) bunzip2 "$1" ;;
*.rar) unrar x "$1" ;;
*.gz) gunzip "$1" ;;
*.tar) tar xvf "$1" ;;
*.tbz2) tar xvjf "$1" ;;
*.tgz) tar xvzf "$1" ;;
*.zip) unzip "$1" ;;
*.Z) uncompress "$1" ;;
*.7z) 7z x "$1" ;;
*) echo "$1 cannot be extracted via >extract<" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
RUN_HELLO_JNI_THROUGH_VALGRIND=true
VALGRIND_VERSION="3.10.0"
VALGRIND_EXTENSION=".tar.bz2"
VALGRIND_DIRECTORY="valgrind-${VALGRIND_VERSION}"
VALGRIND_TARBALL="valgrind-${VALGRIND_VERSION}${VALGRIND_EXTENSION}"
# Only download Valgrind tarball again if not already downloaded
if [[ ! -f "${VALGRIND_TARBALL}" ]]; then
wget -v -nc "http://valgrind.org/downloads/${VALGRIND_TARBALL}"
fi
# Only extract Valgrind tarball again if not already extracted
if [[ ! -d "$VALGRIND_DIRECTORY" ]]; then
extract "$VALGRIND_TARBALL"
fi
# Ensure ANDROID_NDK_HOME is set
if [[ ! -z "$ANDROID_NDK_HOME" ]]; then
export ANDROID_NDK_HOME="$HOME/Software/Android/android-ndk-r10c"
fi
# Ensure ANDOID_SDK_HOME is set
if [[ ! -z "$ANDROID_SDK_HOME" ]]; then
export ANDROID_SDK_HOME="$HOME/Software/Android/android-sdk/"
fi
if [[ ! -d "$VALGRIND_DIRECTORY" ]];
then
echo "Problem with extracting Valgrind from $VALGRIND_TARBALL into $VALGRIND_DIRECTORY!!!"
exit -1
fi
# Move to extracted directory
cd "$VALGRIND_DIRECTORY"
# ARM Toolchain
ARCH_ABI="arm-linux-androideabi-4.9"
export AR="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar"
export LD="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld"
export CC="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
export CXX="$ANDROID_NDK_HOME/toolchains/${ARCH_ABI}/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++"
[[ ! -d "$ANDROID_NDK_HOME" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure ANDROID_NDK_HOME is defined also" && exit -1
# Configure build
export HWKIND="nexus_s"
ANDROID_PLATFORM=android-18
export CPPFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_NDK_HOME/platforms/${ANDROID_PLATFORM}/arch-arm"
# BUG: For some reason file command is unable to detect if the file does not exist with ! -f , it says it doesn't exist even when it does!!!
BUILD=false
if [[ "${VALGRIND_DIRECTORY}/Inst/data/local/Inst/bin/valgrind" = *"No such file or directory"* ]]; then
BUILD=true
fi
if [[ "$BUILD" = true ]];
then
./configure --prefix="/data/local/Inst" \
--host="armv7-unknown-linux" \
--target="armv7-unknown-linux" \
--with-tmpdir="/sdcard "
[[ $? -ne 0 ]] && echo "Can't configure!" && exit -1
# Determine the number of jobs (commands) to be run simultaneously by GNU Make
NO_CPU_CORES=$(grep -c ^processor /proc/cpuinfo)
if [ $NO_CPU_CORES -le 8 ]; then
JOBS=$(($NO_CPU_CORES+1))
else
JOBS=${NO_CPU_CORES}
fi
# Compile Valgrind
make -j "${JOBS}"
[[ $? -ne 0 ]] && echo "Can't compile!" && exit -1
# Install Valgrind locally
make -j "${JOBS}" install DESTDIR="$(pwd)/Inst"
[[ $? -ne 0 ]] && echo "Can't install!" && exit -1
fi
# Push local Valgrind installtion to the phone
if [[ $(adb shell ls -ld /data/local/Inst/bin/valgrind) = *"No such file or directory"* ]];
then
adb root
adb remount
adb shell "[ ! -d /data/local/Inst ] && mkdir /data/local/Inst"
adb push Inst /
adb shell "ls -l /data/local/Inst"
# Ensure Valgrind on the phone is running
adb shell "/data/local/Inst/bin/valgrind --version"
# Add Valgrind executable to PATH (this might fail)
adb shell "export PATH=$PATH:/data/local/Inst/bin/"
fi
if [ $RUN_HELLO_JNI_THROUGH_VALGRIND = true ]; then
PACKAGE="com.example.hellojni"
# The location of the Hello JNI sample application
HELLO_JNI_PATH="$ANDROID_NDK_HOME/samples/hello-jni"
pushd "$HELLO_JNI_PATH"
# Update build target to the desired Android SDK version
ANDROID_PROJECT_TARGET="android-18"
android update project --target "$ANDROID_PROJECT_TARGET" --path . --name hello-jni --subprojects
# Enable Android NDK build with Ant
echo '<?xml version="1.0" encoding="utf-8"?>
<project name="HelloJni" basedir="." default="debug">
<target name="-pre-build">
<exec executable="${ndk.dir}/ndk-build" failonerror="true"/>
</target>
<target name="clean" depends="android_rules.clean">
<exec executable="${ndk.dir}/ndk-build" failonerror="true">
<arg value="clean"/>
</exec>
</target>
</project>
' > "custom_rules.xml"
# Set NDK HOME for Ant (only if not already set)
if ! grep -P -q "ndk.dir=.+" "local.properties" ; then
echo -e "\nndk.dir=$ANDROID_NDK_HOME" >> "local.properties"
fi
# Fix for Java 8 warning (warning: [options] source value 1.5 is obsolete and will be removed in a future release)
echo "java.compilerargs=-Xlint:-options" >> "ant.properties"
# Workaround INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES error
adb uninstall "$PACKAGE"
# Build Hello JNI project in debug mode and install it on the device
ant clean && ant debug && ant installd
popd
cd ..
# Start HelloJNI app
adb shell am start -a android.intent.action.MAIN -n $PACKAGE/.HelloJni
# Make the script executable
chmod a+x bootstrap_valgrind.sh
# Run application through Valgrind on the phone
/usr/bin/env bash bootstrap_valgrind.sh
adb shell ls -lR "/sdcard/*grind*"
adb shell ls -lR "/storage/sdcard0/*grind*"
adb shell ls -lR "/storage/sdcard1/*grind*"
fi
exit 0
This gets valgrind to compile for me on linux. (using android-ndk-r8e and valgrind-3.8.1)
There was no need to run autogen.sh since I downloaded the tar ball from the website.
Also make sure the TOOLCHAIN= line points to a valid toolchain.
export NDK_HOME=$HOME/Downloads/android-ndk-r8e
export HWKIND=generic
export TOOLCHAIN=$NDK_HOME/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/arm-linux-androideabi
export AR=$TOOLCHAIN-ar
export LD=$TOOLCHAIN-ld
export CC=$TOOLCHAIN-gcc
CPPFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm -DANDROID_HARDWARE_$HWKIND" \
CFLAGS="--sysroot=$NDK_HOME/platforms/android-14/arch-arm" \
./configure --prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
make
It eventually came up with a compile error saying
$NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h:58:3: error: unknown type name 'uint32_t'
It seem like someone forgot to add #include <stdint.h> somewhere. To fix this I edited $NDK_HOME/platforms/android-14/arch-arm/usr/include/elf.h and added #include <stdint.h> to the include section of this header. NOTE: This is probably not the best fix but it is the one that I came up with that fixed the compilation errors.
On mac I was able to get it to compile up until the unknown type uint32_t part by changing how the configure script checks the kernel version.
Inside the configure script search of a line kernel=`uname -r` and change it to kernel=3.9.2. (There are two kernel=`uname -r` lines replace the first one or both if you feel like it)
This stops the configure script from looking at the host kernel when deciding how it should build valgrind. (uname -r grabs the host kernel)
I believe adding the #include <stdint.h> to elf.h should work on mac to but I have not tested it.
in android tutorial one option is missed
RANLIB, after I set it - I finally compiled valgrind-3.11.0 on osx for android
#/bin/sh
echo "NKDROOT: " $NDKROOT
export ANRDOID_TOOLCHAIN="arm-linux-androideabi-4.9"
# Set up toolchain paths.
#
# For ARM
export AR=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar
export LD=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ld
export CC=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc
export CXX=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-g++
export RANLIB=$NDKROOT/toolchains/$ANRDOID_TOOLCHAIN/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ranlib
echo "AR: " $AR
echo "LD: " $LD
echo "CC: " $CC
echo "CXX: " $CXX
[[ ! -d "$NDKROOT" || ! -f "$AR" || ! -f "$LD" || ! -f "$CC" || ! -f "$CXX" ]] && echo "Make sure AR, LD, CC, CXX variables are defined correctly. Ensure NDKROOT is defined also" && exit -1
./autogen.sh
#if [ $? -ne 0 ]
#then
# exit 1
#else
# echo "autogen success!"
#fi
# for ARM
ANDROID_PLATFORM=android-3
ANDROID_SYSROOT="$NDKROOT/platforms/${ANDROID_PLATFORM}/arch-arm"
echo "SYSROOT: " $ANDROID_SYSROOT
export HWKIND=generic
export CPPFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export CFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export LDFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
export ARFLAGS="--sysroot=$ANDROID_SYSROOT -DANDROID_HARDWARE_$HWKIND"
./configure \
--prefix=/data/local/Inst \
--host=armv7-unknown-linux --target=armv7-unknown-linux \
--with-tmpdir=/sdcard
if [ $? -ne 0 ]
then
exit 1
else
echo "configure success!"
fi
# note: on android emulator, android-14 platform was also tested and works.
# It is not clear what this platform nr really is.
make -j7
if [ $? -ne 0 ]
then
exit 1
else
echo "build success!"
fi
make -j7 install DESTDIR=`pwd`/Inst
The problem I had was that the configure script was ignoring the environment variables. To configure the make file I instead did this:
sudo ./configure --prefix=/data/local/Inst --host=armv7-unknown-linux --target=armv7-unknown-linux --with-tmpdir=/sdcard0 CPPFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm -DANDROID_HARDWARE_$HWKIND" CFLAGS="--sysroot=$NDKROOT/platforms/android-3/arch-arm" CC=$CC LD=$LD AR=$AR
This ensures the variables are set properly and works with Linux Mint 13. It does not work on OSX Mountain Lion however. I'd advise anyone using OSX without access to a linux installation to try using linux on a virtual machine.

How to stream to ffserver from android

I need to stream from an android camera/ file to a remote ffserver which will broadcast my video. I can do this on the desktop in ubuntu by issuing a command like:
ffmpeg -f video4linux2 -s 640x480 -r 25 -i /dev/video0 http://192.168.0.20:8090/cam1.ffm
or stream a file like this:
ffmpeg -i /home/kev/share/movie.mp4 http://192.168.0.20:8090/cam1.ffm
So basically i want to be able to do the above from android. After several searches this is what i've done so far - i came across this link http://bambuser.com/opensource from which i downloaded the ffmpeg source and built it. The build outputs several things:
1. shared libs [libavcodec, libavcore, libavdevice, libavfilter,libavformat,libavutil,libswscale]
2. executables [ffmpeg,ffprobe]
Not sure how to plug my functionality with these resources this is what i've tried so far:
1. loaded the libs in my Activity using System.loadLibrary() then copied the ffmpeg executable to the assets folder which at runtime i copied to my application's "files" directory i then set permissions for the executable using Runtime.getRuntime().exec(). then the last step was to execute it in java with the following statement:
Runtime.getRuntime().exec("ffmpeg -i file:///android_asset/movie.mp4http://<server>:8090/cam1.ffm");
2. copied ffmpeg.c,the shared libraries and the "include" folder that was generated by the build to my jni folder and added a jni function that wraps around the main() function in ffmpeg.c. With this approach i've found myself having to copy several header files from the ffmpeg source for the ndk-build to succeed and i highly doubt if this is the way to go.
The above two approaches havnt worked for me, i'm not sure where i'm going wrong, so any help on how to do a simple ffmpeg streaming like an mp4 file from android would be highly appreciated.
I got it working by using apporach 2, this is what i did.
1. copied ffmpeg.c,the "include" folder and the shared libraries to my project's jni folder.
modified ffmpeg.c with reference to this blog post http://demo860.blogspot.com/2010/07/android-ffmpeg-dynamic-module-jni.html
there were several errors while building with ndk so i just added the missing dependencies until finally the build succeeded.
At first the app would start and then immediately exit, this was due to a couple of things i forgot to do so make sure you've done the following to save yourself some hours and hair loss:
- set internet permission on manifest(if media file is in sdcard, set write external storage permission and make sure the sdcard is mounted)
- make sure the remote ffserver is running and configured correctly. you can confirm by streaming from a desktop
- make sure you have the correct params passed
Now i can stream from an mp4 file in my sdcard to a remote ffserver, havnt tried streaming from the device camera yet.
It seems to be a bit late to answer this question, but if you need a solution, here's one...
Well, I had devised a workaround to the same problem but through the first approach that is using a compiled FFmpeg Binary rather than JNI...
First, as far as it seems to me, the builds provided by Bambuser are way too old and FFmpeg has a vicious development cycle...
So I'd rather suggest to custom build your own binary from the latest FFmpeg Source...
Here's a script that could be used to generate one :
#!/bin/bash
echo ""
echo " ********** FFmpeg Android Build ********** "
echo ""
NDK=$HOME/android-ndk-r8d
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
PLATFORM=$NDK/platforms/android-14/arch-arm
PREFIX=$HOME/FFmpeg.Binaries.Android
FFMPEG_BASE=$HOME/FFmpeg.Build
if [ -d "$FFMPEG_BASE" ]; then
rm -v -r -f $FFMPEG_BASE
fi
if [ -d "$PREFIX" ]; then
rm -v -r -f $PREFIX
fi
mkdir $FFMPEG_BASE
mkdir $PREFIX
# x264 Installation
echo ""
echo " ********** libx264 Installation ********** "
echo ""
cd $FFMPEG_BASE
git clone --depth 1 git://git.videolan.org/x264
cd $FFMPEG_BASE/x264
./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM
make
sudo make install
sudo ldconfig
#FFmpeg Installation
echo ""
echo " ********** FFmpeg (Android) Installation ********** "
echo ""
cd $FFMPEG_BASE
# git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd $FFMPEG_BASE/ffmpeg
./configure --target-os=linux --prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-nonfree \
--enable-version3 \
--enable-gpl \
--disable-doc \
--enable-avresample \
--enable-demuxer=rtsp \
--enable-muxer=rtsp \
--disable-ffserver \
--disable-ffprobe \
--enable-ffmpeg \
--enable-ffplay \
--enable-libx264 \
--enable-encoder=libx264 \
--enable-decoder=h264 \
--enable-protocol=rtp \
--enable-hwaccels \
--enable-zlib \
--extra-cflags="-I$PREFIX/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
--extra-ldflags="-L$PREFIX/lib"
make -j4 install
$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L$PREFIX/lib -soname libffmpeg.so -shared -nostdlib -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavfilter/libavfilter.a libavresample/libavresample.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog -lx264 --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
# rm -v -r -f $FFMPEG_BASE
clear
echo ""
echo "FFmpeg Android Build Successful..."
echo ""
ls -l -R $PREFIX
exit
For the above script to work, Android NDK is required and could be downloaded from here. Download the NDK and extract to your /home/<username> directory or else customize the script as per your needs...
And also avoid using the file:// protocol in the command line, just specify the absolute path of the input file. And try to log the output from the FFmpeg process by gettin' instances of its stdout and stderr streams...
You don't have to copy shared libraries and include folder. You can use the "PREBUILD_SHARED_LIBRARY" feature of Andriod.mk instead.

Categories

Resources