cross compile protobuf 2.5.0 for Android on Centos 7 - android

I would like to run a Qt Console Application written in C++ that includes the use of protobuf on a android phone.
Therefore, I need to crosscompile protobuf for a arm architecture. I have been following this script.
https://gist.github.com/helayzhang/9034454
This is my configure command:
sudo ./configure --prefix=/home/staff/Desktop/proto_arm --build=armv7- android-linux-android --host=armv7-android-linux-android --target=armv7-android-linux-android --enable-cross-compile --with-protoc=/home/staff/Desktop/proto_arm/protoc CXXFLAGS="$(pkg-config --cflags protobuf)" LIBS="$(pkg-config --libs protobuf)"
My problems are cross-compilation option is ignored
checking whether we are cross compiling... no
and I am not sure whether I am building for the right architecture. My phone supports ABIs arm64-v8a, armeabi-v7a and armeabi, the OS is android 6 marshmallow
I am grateful for every advice!
Here is a link to my config.log file
enter link description here

I was able to compile protobuf with this scipt:
#!/bin/bash
export NDK=/media/qt5-qwt6/ndk10/android-ndk-r10e
export SYSROOT=$NDK/platforms/android-21/arch-arm
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export PATH=$PATH:$TOOLCHAIN/bin
export CC="$TOOLCHAIN/bin/arm-linux-androideabi-gcc --sysroot $SYSROOT"
export CXX="$TOOLCHAIN/bin/arm-linux-androideabi-g++ --sysroot $SYSROOT"
export CXXSTL=$NDK/sources/cxx-stl/gnu-libstdc++/4.9
function build_one
{
mkdir build
./configure --prefix=$(pwd)/build \
--host=arm-linux-androideabi \
--with-sysroot=$SYSROOT \
--enable-static \
--disable-shared \
--enable-cross-compile \
--with-protoc=protoc \
CFLAGS="-march=armv7-a" \
CXXFLAGS="-march=armv7-a -I$CXXSTL/include -I$CXXSTL/libs/armeabi-v7a/include -L$CXXSTL/libs/armeabi-v7a/ -lgnustl_static"
make clean
make
make install
}
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"
build_one
# Inspect the library architecture specific information
# arm-linux-androideabi-readelf -A build/lib/libprotobuf-lite.a

Related

Libgmp NDK Build issue with x86_64

I am trying to build libgmp with NDK as static (shared also doesn't work), I need this to link with nettle and gnutls. The versions I am using below:
GMP: 6.1.2
NDK: r16b
Target: x86_64
API: android-27
Env: Ubuntu 16.04 (Windows shell)
So I download a tar of libgmp from their website and then the android standalong toolchain:
$NDK/build/tools/make_standalone_toolchain.py --arch "x86_64" --api 27 \
--stl=libc++ --install-dir /tmp/android-toolchain --force
Set the environment to link with NDK
# Prefix is out the output folder location
PREBUILT=/tmp/android-toolchain
CROSS_COMPILE=$PREBUILT/bin/x86_64-
CFLAGS="-isystem /tmp/android-toolchain/sysroot/usr/include/x86_64/ -D__ANDROID_API__=27-I$PREFIX/include"
export LDFLAGS="-Wl,-rpath-link=/tmp/android-toolchain/sysroot/usr/lib -L$/tmp/android-toolchain/sysroot/usr/lib -lc -lm -ldl -llog -nostdlib -lgcc -L$PREFIX/lib"
export CPPFLAGS="$CFLAGS"
export CFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export CXX="clang++"
export AS="clang"
export CC="clang"
export NM="${CROSS_COMPILE}nm"
export STRIP="${CROSS_COMPILE}strip"
export RANLIB="${CROSS_COMPILE}ranlib"
export AR="${CROSS_COMPILE}ar"
export LD="${CROSS_COMPILE}ld"
then ran configure
./configure
--prefix=$PREFIX \
--host="x86_64-linux" \
--build=x86_64-unknown-linux-gnu \
--disable-dependency-tracking \
--enable-static \
--disable-shared \
|| exit 1
make -j4 || exit 1
Prefix points to output directory, (also tried host x86_64-linux-android). It configures but then after that when running make, it will try to compile a bunch of binaries that auto create a bunch of files such as gen-fib.c -> gen-fib binary.
Makefile then runs that binary to create the header file (fib_table.h) and the source fib_table.c. When Makefile runs (I believe something like)
gen-fib header <number> <number> > fib_table.h
It outputs nothing, so fib_table.h is empty (0 bytes). I tried to run it from command line and nothing appears. Tried to create a file in gen-fib.c and have it compiled to create a dummy file and nothing happens. The binary executes nothing, does not run at all!
Now I have compiled this successfully with arm64 (aarch64 or arm64-v8a) and x86 (and of course ran make distclean between different hosts). I tried to compare the config.log with x86 and x86_64 which the only difference being the host argument in the configure and x86 android toolchain. For my x86_64 log file you can read that here:
https://pastebin.com/LLEbDz11
If anyone knows why the binaries (like gen-fibs) do not run after compiling them for x86_64 (but other abi like x86 and arm64) please let me know.
Thanks in advance!!
I figured out that the binaries were not building because it was using the toolchain's clang. Using
export CC_FOR_BUILD=/usr/bin/gcc
Uses the gcc from linux to compile it correctly.

Compiling ffmpeg for Android on OSX

I'm trying to compile ffmpeg for Android, on OSX 10.12.4 .
Here are the steps I followed:
1°) Compile pkg-config
Download the sources from here . Extract && cd in the pkg-config folder.
export DST=/a/path/on/my/computer
./configure --with-internal-glib --prefix=$DST --exec-prefix=$DST
make -j2
make install
export PATH=$PATH:$DST/bin
2°) Compile ffmpeg
Download the sources from here. Extract && cd in the ffmpeg folder.
export NDK=/path/to/android-ndk-r15c
export PLATFORM_VERSION=android-26
export ARCH=arm
export PLATFORM=$NDK/platforms/$PLATFORM_VERSION/arch-$ARCH
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
export PREFIX=$(pwd)/android/$ARCH
export ADDI_CFLAGS="-Os -fpic -marm"
export ADDI_CONFIGURE_FLAG=""
export ADDI_LDFLAGS=""
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-symver \
--disable-avdevice \
\
--pkg-config=pkg-config \
\
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=$ARCH \
--enable-cross-compile \
--sysroot=$PLATFORM \
--extra-cflags="$ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
\
$ADDI_CONFIGURE_FLAG
make -j2
Make fails with the following error:
AR libavfilter/libavfilter.a
AR libavformat/libavformat.a
CC libavcodec/aaccoder.o
In file included from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/asm/termbits.h:19:0,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/asm-generic/termios.h:21,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/asm/termios.h:19,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/linux/termios.h:22,
from /Users/Tim/Library/Android/android-ndk-r15c/platforms/android-26/arch-arm/usr/include/sys/ioctl.h:37,
from ./libavutil/timer.h:36,
from ./libavutil/internal.h:42,
from ./libavutil/common.h:467,
from libavcodec/mathops.h:27,
from libavcodec/aaccoder.c:38:
libavcodec/aaccoder.c: In function 'search_for_ms':
libavcodec/aaccoder.c:803:25: error: expected identifier or '(' before numeric constant
int B0 = 0, B1 = 0;
^
libavcodec/aaccoder.c:865:28: error: lvalue required as left operand of assignment
B0 += b1+b2;
^
libavcodec/aaccoder.c:866:25: error: 'B1' undeclared (first use in this function)
B1 += b3+b4;
^
libavcodec/aaccoder.c:866:25: note: each undeclared identifier is reported only once for each function it appears in
make: *** [libavcodec/aaccoder.o] Error 1
make: *** Waiting for unfinished jobs....
I'm able to fix that error by renaming B0 & B1 variables in the source to A0 & A1 (don't know why it fixes the problem), but then it fails somewhere else. I guess something is wrong in my config, and I'd prefer to avoid having to patch the source.
So the questions are:
does someone know what's wrong here? Do I need to give some args to gcc?
is the --target-os=linux correct, or should it be --target-os=darwin? Is target-os the OS where the compilation is done, or where ffmpeg will be executed? By using darwin, I can compile using --enable-static, but not --enable-shared (which I want).
Note: I need to compile it myself as I want only an arm version, with HTTPS support. Thus I can't use the existing built versions.
I also met this problem when I tried to build the ffmpeg 3.4 the latest version.I wish you could try the 3.3 version.I built it successfully.
I doubt that latest version is unstable and with some bug.
By the way,You can take some answer By this article:
http://alientechlab.com/how-to-build-ffmpeg-for-android/
Issue closed by FFmpeg team
--target-os=android solves it
./configure \
...
--target-os=android

Compiling x264 on a Mac: "No working C compiler found" and "arm-linux-androideabi-gcc: command not found"

I am trying to compile the x264 library for Android, following this post.
I have cloned the x264 project git clone git://git.videolan.org/x264.git and tried to compile with the following configuration:
NDK=~/development/android-ndk-r10c
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64
PLATFORM=$NDK/platforms/android-21/arch-arm
./configure \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM \
--host=arm-linux \
--enable-pic \
--enable-static \
--disable-cli
The problem is that I get a No working C compiler found. error.
The conftest.log output:
$ cat conftest.log
./configure: line 153: arm-linux-androideabi-gcc: command not found
But the arm-linux-androideabi-gcc is the toolchain's bin folder!!
Looking at this other question it looks like for some reason, even though the file exists, since it is a 64bit Mac, it won't execute the arm-linux-androideabi-gcc file and will return this weird error and log.
I am in a Mac OS X 10.10 and I have installed the XCode Command Line Tools:
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
GCC version:
$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
Can anyone tell me how to fix this please?
You shouldn't set --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi-, you should add that directory to your path first, using export PATH=$TOOLCHAIN/bin:$PATH, and only specify --cross-prefix=arm-linux-androideabi- (just as in the post you linked to).

Cannot create shared object of protobuf with android g++ standalone compiler

I'm trying to compile protobuf with the android arm g++ as a shared object, however the compiler is only outputting static objects. Here's the error in the configure step:
checking whether the
/opt/build-android-linux/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-g++
linker
(/opt/build-android-linux/arm-linux-androideabi-4.4.3/arm-linux-androideabi/bin/ld)
supports shared libraries... no
Here's my environment for executing the configure step
export NDK="/home/john/Development/android-ndk-r8e/"
export SYSROOT=$NDK/platforms/android-8/arch-arm
export CFLAGS="-march=armv7-a -mfloat-abi=softfp -DGOOGLE_PROTOBUF_NO_RTTI --sysroot=$SYSROOT"
export CPPFLAGS="-march=armv7-a -mfloat-abi=softfp -DGOOGLE_PROTOBUF_NO_RTTI --sysroot=$SYSROOT"
androideabi/lib/ -lgnustl_shared"
export CC="/opt/build-android-linux/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-gcc"
export CXX="/opt/build-android-linux/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-g++"
export AR="/opt/build-android-linux/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-ar"
./configure --host=arm-eabi --with-sysroot=$SYSROOT CC=$CC --enable-cross-compile --with-protoc=protoc --enable-static=false
Thanks in advance

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