Building pjsip for x86 - android

I want to build pjsip for x86 architecture. I am following this link. In the instructions,
Building PJSIP
Just run:
$ cd /path/to/your/pjsip/dir
$ export ANDROID_NDK_ROOT=/path_to_android_ndk_dir
$ ./configure-android
$ make dep && make clean && make
Notes:
It will build armeabi target, to build for other targets such as arm64-v8a, armeabi-v7a, x86, instead of just './configure-android', specify the target arch in TARGET_ABI and run it with --use-ndk-cflags, for example:
TARGET_ABI=armeabi-v7a ./configure-android --use-ndk-cflags
Also you should adjust ​Application.mk and ​library packaging path (see also #1803).
Are they referring Application.mk in pjsua application?

Yes. There is link in ticket #1803 on changeset 5056:
https://trac.pjsip.org/repos/changeset/5056
Android.mk and Application.mk you can find here: your-pjsip-root-dir/pjsip-apps/src/pjsua/android/jni/Application.mk

Related

Build CMake library without Android-Studio (by command-line or GUI)

It seems, Android-Studio sets specific CMake options,
And I can not build with command-line (outside of Android-Studio) no matter what I tried!!
Is there any way to build an Android project's CMake library without even opening Android-Studio?
Note: I already found solution and will share answer to this shortly.
Yes there were some options and/or variables that need to be set for CMake command-line build to work (without even opening Android-Studio).
1. Firstly, create the my-toolchain.cmake file (beside your project, maybe in config dir), with content below:
#
# Allows compiling outside of Android-Studio.
#
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_TOOLCHAIN_DIRECTORY "$ENV{ANDROID_HOME}/ndk-bundle/build/cmake")
if(NOT CMAKE_TOOLCHAIN_FILE)
if(NOT ANDROID_ABI)
# Default to 32 Bit ARMv7 CPU.
set(ANDROID_ABI "armeabi-v7a")
endif()
if(NOT ANDROID_PLATFORM)
set(ANDROID_PLATFORM "android-15")
endif()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_DIRECTORY}/android.toolchain.cmake")
endif()
if(WIN32 AND NOT CMAKE_MAKE_PROGRAM)
set(CMAKE_MAKE_PROGRAM "$ENV{ANDROID_HOME}/ndk-bundle/prebuilt/windows/bin/make.exe" CACHE INTERNAL "" FORCE)
endif()
2. Secondly, Add the file created in last step into your project, for example:
cmake_minimum_required(VERSION 3.2)
# Detect toolchain.
include(config/my-toolchain.cmake)
project(MyProject C CXX)
# ... and so on ...
3. Finally, in console cd where your CMakeLists.txt file is, and build with commands like:
cmake -H. -B .build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DANDROID_PLATFORM=android-14 -D ANDROID_ABI=armeabi-v7a
cd .build
"%ANDROID_HOME%\ndk-bundle\prebuilt\windows\bin\make.exe" install INSTALL_ROOT="%CD%\.build"
Note that last command of Step-3 changes based on your operating-system, but above should work for Windows if you have ANDROID_HOME environment-variable set to Android-SDK root directory (which of course, needs NDK extracted in ndk-bundle sub-dir).
All done!
Just repeat Step-3 for each CPU architecture, i.e. change ANDROID_ABI to one of possible options:
armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64
Although, mips and mips64 are deprecated by now (and Android NDK r16b was last version supporting them).

How to generate libpjsua2.so for x86 abi in jnilibs

I want to test the app with android 10 in emulator.So for that I only have "armeabi", "armeabi-v7a","arm64-v8a" in jnilibs. But running app with android 10 device(Emulator), requires x86 abi. So for that first I have downloaded ndk for x86.And the second thing is I want to generate libpjsua2.so for x86 abi.
I am using pjsip library.
I have referred to https://trac.pjsip.org/repos/wiki/Getting-Started/Android. What I have tried is,
1) Downloaded latest pjsip version and extracted in folder.
2) Followed the steps given in pjsip website as below,
$ cd /path/to/your/pjsip/dir
$ export ANDROID_NDK_ROOT=/path_to_android_ndk_dir
$ ./configure-android
$ make dep && make clean && make
$ cd /path/to/your/pjsip/dir
$ make clean
# cleanup pjsua sample app
$ cd pjsip-apps/src/pjsua/android/jni
$ make clean
# also cleanup pjsua2 sample app (SWIG)
$ cd /path/to/your/pjsip/dir
$ cd pjsip-apps/src/swig
$ make clean
$ cd pjsip-apps/src/swig
$ make clean
TARGET_ABI=x86 ./configure-android --use-ndk-cflags
Got error when reached above code,
LDFLAGS = --sysroot= -L/libs/x86/
LIBS = -lgnustl_static -lc -lgcc -ldl
AR = /home/Android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
RANLIB = /home/Android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
TARGET_HOST = llvm-linux-android
TARGET_ABI = x86
checking build system type... x86_64-unknown-linux-gnu
checking host system type... Invalid configuration `llvm-linux-android': machine `llvm' not recognized
aconfigure: error: /bin/sh ./config.sub llvm-linux-android failed
In my pjsip2.7 folder I found a folder named llvm but that is a empty folder. I doesn't know What is that. I am using cent os 7. Why I am getting this error? What do I need to do to overcome this.
Try compile with this builder
replace in ./config.cong you are using 2.10
# PJSIP Version to download
PJSIP_VERSION=2.10
./prepare-build-system
and then
./build

build llvm clang4.0 for android armeabi

I am trying to build llvm and clang4.0 for android armeabi.
Currently I have done these:
1. from:
http://hardenedlinux.org/toolchains/2016/04/01/How_to_build_Clang_toolchains_for_Android.html
I have checkout source code :
repo init -u https://android.googlesource.com/platform/manifest -b llvm
repo sync
python external/clang/build.py
The build is going successful, but it will consume over 100G diskspace and about 8 hours. what's more, it is not clang 4.0.
2.
from http://llvm.org/docs/GettingStarted.html
I checked out the source code:
git clone http://llvm.org/git/llvm.git
cd llvm/tools
git clone http://llvm.org/git/clang.git
cd llvm/projects
git clone http://llvm.org/git/compiler-rt.git
finally I build it with llvm/cmake/platforms/android.cmake
this android.cmake can be shown below:
# Toolchain config for Android NDK.
# This is expected to be used with a standalone Android toolchain (see
# docs/STANDALONE-TOOLCHAIN.html in the NDK on how to get one).
#
# Usage:
# mkdir build; cd build
# cmake ..; make
# mkdir android; cd android
# cmake -DLLVM_ANDROID_TOOLCHAIN_DIR=/path/to/android/ndk \
# -DCMAKE_TOOLCHAIN_FILE=../../cmake/platforms/Android.cmake ../..
# make <target>
SET(CMAKE_SYSTEM_NAME Linux)
IF(NOT CMAKE_C_COMPILER)
SET(CMAKE_C_COMPILER ${CMAKE_BINARY_DIR}/../bin/clang)
ENDIF()
IF(NOT CMAKE_CXX_COMPILER)
SET(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/../bin/clang++)
ENDIF()
SET(ANDROID "1" CACHE STRING "ANDROID" FORCE)
SET(ANDROID_COMMON_FLAGS "-target arm-linux-androideabi -- sysroot=${LLVM_ANDROID_TOOLCHAIN_DIR}/sysroot -B${LLVM_ANDROID_TOOLCHAIN_DIR}")
SET(CMAKE_C_FLAGS "${ANDROID_COMMON_FLAGS}" CACHE STRING "toolchain_cflags" FORCE)
SET(CMAKE_CXX_FLAGS "${ANDROID_COMMON_FLAGS}" CACHE STRING "toolchain_cxxflags" FORCE)
SET(CMAKE_EXE_LINKER_FLAGS "-pie" CACHE STRING "toolchain_exelinkflags" FORCE)
But it always build x86 target, it does not build armeabi target.
My building host OS is Ubuntu 16.04 LTS 64 bits.
Please How can I build llvm and clang 4.0 for armeabi targeting android ?
I believe you're interested in cross-compiler targeting android. In this case llvm/cmake/platforms/android.cmake is of no use (it's used for building via compiler, not building the compiler itself).
Please refer to http://llvm.org/docs/CMake.html for generic LLVM build instructions. But in your case I believe you'd need to set LLVM_TARGETS_TO_BUILD to "ARM;AArch64" and LLVM_DEFAULT_TARGET_TRIPLE to "arm-linux-androideabi" in LLVM's cmake invocation.

How to compile Boost 1.61 for Android NDK 11

I want to install compile Boost 1.61 with clang 3.6 for android with the NDK 11 but this software : https://github.com/moritz-wundke/Boost-for-Android isn't updated and doesn't support this versions.
I want to know if anyone has managed to this !
Thank you !
Build boost_1_62_0 for Android-21 under Windows64.
Assuming NDK installed to C:\Programs\Android\sdk\ndk-bundle and boost in c:\boost_1_62_0.
Install mingw: using msys2-x86_64 from MSYS2
Install build tools from mingw prompt (something like this):
$ pacman -S gcc binutils
Create android.clang.jam file in C:\boost_1_62_0\ with such text content:
import os ;
local AndroidNDKRoot = C:/Programs/Android/sdk/ndk-bundle ;
using clang : android
:
C:/Programs/Android/toolchain21/bin/clang++
:
<compileflags>-fexceptions
<compileflags>-frtti
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-Wno-psabi
<compileflags>-march=armv7-a
<compileflags>-mfloat-abi=softfp
<compileflags>-mfpu=vfpv3-d16
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-finline-limit=64
<compileflags>-I$(AndroidNDKRoot)/platforms/android-21/arch-arm/usr/include
<compileflags>-Wa,--noexecstack
<compileflags>-DANDROID
<compileflags>-D__ANDROID__
<compileflags>-DNDEBUG
<compileflags>-O2
#<compileflags>-g
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.9/include
<compileflags>-I$(AndroidNDKRoot)/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/include
<architecture>arm
<compileflags>-fvisibility=hidden
<compileflags>-fvisibility-inlines-hidden
<compileflags>-fdata-sections
<cxxflags>-D__arm__
<cxxflags>-D_REENTRANT
<cxxflags>-D_GLIBCXX__PTHREADS
;
Setup boost from mingw prompt:
$ export NDK=/c/Programs/Android/sdk/ndk-bundle
$ echo ensure msi-installed Python is on path (not msys version):
$ export PATH=/c/Python27:$PATH
$ $NDK/build/tools/make_standalone_toolchain.py --arch arm --api 21 --install-dir /c/Programs/Android/toolchain21
$ ./bootstrap.sh --with-toolset=gcc
$ ./b2 --user-config=android.clang.jam threading=multi link=static \
runtime-link=static toolset=clang-android target-os=linux \
threadapi=pthread --stagedir=android --with-chrono \
--with-program_options --with-system --with-thread --with-random \
--with-regex
Yes, the repository you mentioned is apparently not maintained anymore. The author also seems not to answer any mails on the subject. If you look you'll see that each new boost version supported there required a lot of work (many special flags in the config files). That's presumably why he doesn't have time to maintain it any longer.
I also tried to update to 1.64 using a fork but gave up after countless error messages and instead used a different method based on a crystax script. Its simple and should work for pretty much any version. You can find the details and the script (simple and painless to execute) here: http://silverglint.com/boost-for-android/
Works with clang and gcc.
Also included is a sample app that shows you how to use the boost binaries thus built.

PJSIP Library Build Error for Android

Please help me. I try to build PJSIP library in Windows for Android by using Cygwin terminal. I follow steps exactly, but when I write $ ./configre-android I get this error - >
$ ./configure-android
./configure-android: line 3: $'\r': command not found
./configure-android: line 5: $'\r': command not found
./configure-android: line 71: syntax error near unexpected token `$'do\r''
'/configure-android: line 71: ` for i in `$NDK_OUT`; do
I used this steps to build sources are
Download sources from PJSIP site. Pay attention if you will compile
on Windows machine download .zip file, if on Unix machine (including
OS X) then download .bz2 file.
Go to pjlib/include/pj/ from the downloaded sources. Create (or
overwrite) a file called config_site.h. Copy the following code
snippet
#define PJ_CONFIG_ANDROID 1
#include <pj/config_site_sample.h>
Open Cmd or Terminal
Go to pjsip root folder (the downloaded sources)
$ cd /path/to/your/pjsip/dir
Export bash var ANDROID_NDK_ROOT as a environment variable.
Variable value should be the path of android ndk directory.
$ export ANDROID_NDK_ROOT=/path_to_android_ndk_dir
Perform build for target armeabi
$ ./configure-android
If you need to perform build for target arm64-v8a do $
TARGET_ABI=armeabi-v8a ./configure-android --use-ndk-cflags
target armeabi-v7a do $
TARGET_ABI=armeabi-v7a ./configure-android --use-ndk-cflags
target x86 do $ TARGET_ABI=x86 ./configure-android --use-ndk-cflags
Compile sources
$ make dep && make clean && make
This fixed problem for me:
tr -d '\015' < configure-android > configure-android2
After this launch configure-android2, not configure-android

Categories

Resources