Android build PJSIP with openssl - android

I'm trying to build PJSIP on Android with SSL/TLS support.
I successfully built OpenSSL following this answer (without fips, as shared-.so libraries) and installed it in ~/android (which created the ~/android/ssl directory).
Now, when i do
./configure-android --with-ssl=/home/andrea/android/ssl
and look at the config.log, the first error states
<ndk-directories-and-stuff>/arm-linux-androideabi/bin/ld: warning: libdl.so, needed by /home/andrea/android/ssl/lib/libcrypto.so, not found (try using -rpath or -rpath-link)
a lot of undefined references follow.
As consequence SSL support is disabled:
aconfigure:7012: result: ** OpenSSL libraries not found, disabling SSL support **
ac_cv_header_openssl_ssl_h=yes
ac_cv_lib_ssl_SSL_library_init=no
CFLAGS=' -I/home/andrea/android/android-ndk-r8e/platforms/android-14/arch-arm/usr/include -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I/home/andrea/android/ssl/include'
LDFLAGS=' -nostdlib -L/home/andrea/android/android-ndk-r8e/platforms/android-14/arch-arm/usr/lib/ -L/home/andrea/android/ssl/lib'
ac_no_ssl=''
libssl_present=''
openssl_h_present='1'
but libdl.so exists in the ndk's directory:
<ndk-dir>/platforms/android-14/arch-arm/usr/lib/
I guess I have to tell ld where the other libraries are,
what does ld's suggestion mean?
try using -rpath or -rpath-link
I can't understand what -rpath or rpath-link are or where to apply them .
any ideas?

I successfully built PJSIP with OpenSSL. please follow the following steps:
First download openssl-android and compile it by reading ReadMe File. (Put your android-ndk to PATH and execute command ndk-build in openssl-android root) then just copy libcrypto.so and libssl.so from libs/armeabi/ folder to lib/ folder in root of openssl-android (you can create this folder). your directory structure now should be like:
openssl-android/
->apps
->crypto
->include
->jni
->lib
->libs
->...
now just execute in root directory of pjsip:
./configure-android --with-ssl=/home/your-user-name/path-to-openssl-android-dir
for confirmation that openssl is included just pipe this command to grep like:
./configure-android --with-ssl=/home/your-user-name/path-to-openssl-android-dir | grep -wi ssl
then you will see this line result: OpenSSL library found, SSL support enabled. This means, OpenSSL is now enabled for your PJSIP. Now you can continue normal.
hope this helps.

Related

Issue OpenSSL library not found building PJSIP project for android ABIs

I'm working on build PJSIP project for Android ABIs(armeabi, x86_64, x86) using OpenSSL on Ubuntu. I tired to build OpenSSL Android ABIs(armeabi, x86_64, x86) by the given steps on PJSIP Documentation, Here and Github repo.
I have successfully build OpenSSL for Android ABIs and created static libraries (*.a). Now, with the created static libraries (libCrypto.a and libssl.a) I've started to build PJSIP project for Android ABIs and set OpenSSL directory path in ./Configure Android as mentioned in their document for corresponded ABI.
When I'm looking generated logs in terminal I found the message "OpenSSL library not found. OpenSSL disabled".
One thing I noticed that I'm working with (.a) library whereas I saw many suggestions are using (libcrypto.so and libssl.so), if this is the issue then, I'd like to know the steps to generate .so library to build OpenSSL project.
I had this same exact issue [on Mac OS building for Android] and what I did to fix it is copy the outputs for the specific android arch I was doing to the lib folder of the openssl directory and it seems to have worked.
the files I copied were: libcrypto.a, libssl.a [not sure if I needed all of them, maybe someone knows??]
it is mentioned here as well:
pjsip
I only got all 4 of my architectures to build when I changed to no-shared on the openssl build
./Configure $SSL_TARGET $OPTIONS -fuse-ld="$TOOLCHAIN/$TRIBLE/bin/ld" no-shared no-ssl2 no-ssl3 no-comp no-hw no-engine
make depend && make all && \
make install DESTDIR=$DESTDIR || exit 128
I also found a link that I think explained why I was getting the error when the shared option was used:
openssl RPATHs

executable binary cannot run on android marshmallow

I built ffmpeg executable binary with shared libraries on Android. But when I run it on Marshmallow, I got the following error, the executable can't run.
$ LD_LIBRARY_PATH=./lib ./bin/ffmpeg
CANNOT LINK EXECUTABLE: cannot find "libavformat.so" from verneed[0] in DT_NEEDED list for "./bin/ffmpeg"
page record for 0xb6eee00c was not found (block_size=16)
I already added --extra-ldexeflags="-pie" when compiled the binary.
The executable binary run properly on pre Marshmallow device.
I didn't encounter such problem before, did I miss something important? How can I make this binary work on Marshmallow?
More information about my environment.
I used android-ndk-r10e with
SYSROOT=$ANDROID_NDK_ROOT/platforms/android-19/arch-arm and toolchains version is
arm-linux-androideabi-gcc (GCC) 4.9 20140827 (prerelease)
If I built ffmpeg into a single executable binary (build the static libraries and then build into binary), it run properly.
After a lot of searching, I found a similar issue from here. There is a problem with my share libraries.
FFmpeg build script disable SONAME for android build, so there is no SONAME found when reading library by command
arm-linux-androideabi-readelf -d libavutil.so |grep soname
Change the configuration script like following, it will work.
android)
disable symver
enable section_data_rel_ro
SLIB_INSTALL_NAME='$(SLIBNAME)'
SLIB_INSTALL_LINKS=
# soname not set on purpose
# soname should set for new version Android
SHFLAGS='-shared -Wl,-soname,$$(word 1,$$(subst ., ,$$(#F))).so'
# SHFLAGS=-shared
After then, recompile ffmpeg to generate share libraries, and I got the result I want,
$ arm-linux-androideabi-readelf -d libavutil.so |grep soname
0x0000000e (SONAME) Library soname: [libavutil.so]
Then, the executable binary run properly.

Openh264 compiling using PJSIP

I am trying to build pjsip project with openh264 lib. Everything works fine except openh264 is not being detected by pjsip ./configure-android
this is my config_site.h
/* Activate Android specific settings in the 'config_site_sample.h' */
#define PJ_CONFIG_ANDROID 1
#include <pj/config_site_sample.h>
#define PJMEDIA_HAS_VIDEO 1
#define PJMEDIA_HAS_OPENH264_CODEC 1
I am getting following log
Using OpenH264 prefix... /home/user_name/PJSIPTOOLS/openh264-1.0.0/openlib/
checking OpenH264 usability... no
As it is not detected by ./configure-android my app is crashing at runtime saying lib not found for openh264.
I am on ubuntu 14.04 32 bit.
Any suggestions.
I just encountered a similar issue. In the following, I refer to the directory, I downloaded and extracted OpenH264 to, as path-to-openh264. I created a subdirectory android within that folder and modified OpenH264's Makefile by setting PREFIX=android. Afterwards running the following commands to build OpenH264 solved the issue for me:
make OS=android NDKROOT=<path-to-ndk> TARGET=android-14 APP_ABI=armeabi ARCH=arm
make OS=android NDKROOT=<path-to-ndk> TARGET=android-14 APP_ABI=armeabi ARCH=arm clean
make install OS=android NDKROOT=<path-to-ndk> TARGET=android-14 APP_ABI=armeabi ARCH=arm
The resulting libopenh264.so file should end up in the directory path-to-openh264/android/lib/. In order to configure pjsip I used the following command:
APP_PLATFORM=android-14 ./configure-android --with-openh264=<path-to-openh264>/android
The following StackOverflow thread lead me to the right direction:
building openh264 for android platform in x86
The reason for this issue was, that I ran the make install command without the command line parameters at first. This caused the native library file to be created for the wrong ABI (the default one, which is armeabi-v7a). When building pjsip for the armeabi ABI, it didn't recognize the library, because it was built for a different ABI. At least this is what I suppose.
Actually i faced that problem too.
Solution:
step 1:go to your openh264 directory and create a folder named "android"
step 2: open makefile and set prefix
PREFIX=/your_path/openh264-1.0.0/android
step3:then build openh264 using this command
make OS=android NDKROOT=/your_path/android-ndk-r10d TARGET=android-17 APP_ABI=armeabi
step4: now build pjsip using this command
TARGET_ABI=armeabi APP_PLATFORM=android-12 ./configure-android --use-ndk-cflags --with-openh264=/your_path/openh264-1.0.0/android
hope this time you will see
Using OpenH264 prefix...
/home/user_name/PJSIPTOOLS/openh264-1.0.0/openlib/
checking OpenH264 usability... ok
http://trac.pjsip.org/repos/ticket/1758
modify the "prefix" in Makefile
run "make install ARCH=armeabi"
run "./configure-android --with_openh264=/path/to/prefix/folder"

Building FIPS module for android

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

Unable to build external OpenSSL library for Android NDK on Windows/Cygwin

I need to build the latest OpenSSL (1.0.0g) for an Android application. I am trying to follow the example given by https://github.com/fries/android-external-openssl, but I just can't get it built.
I am running Windows 7 Professional (64-bit) with a complete and recent Cygwin. I have installed the Android SDK and NDK, and I can successfully build and run the NDK's hello-jni sample application.
I created a new sample NDK app called hello-openssl. In its jni directory, I created an openssl directory. There, I unzipped https://github.com/fries/android-external-openssl/zipball/master, which gave me this tree structure under c:\android\android-ndk\samples\hello-openssl:
jni
+- openssl
+- apps
+- crypto
+- include
+- openssl
+- ssl
I then modified the Android.mk file in the jni directory in an attempt to include the OpenSSL files:
subdirs := $(addprefix $(LOCAL_PATH)/,$(addsuffix /Android.mk, \
openssl \
))
include $(subdirs)
Now when I execute ndk-build, it compiles several .c files, but then quickly fails:
Compile thumb : crypto <= cryptlib.c
In file included from jni/openssl/crypto/cryptlib.c:117:
jni/openssl/crypto/cryptlib.h:65:18: error: e_os.h: No such file or directory
jni/openssl/crypto/cryptlib.h:72:28: error: openssl/crypto.h: No such file or directory
I found http://osdir.com/ml/android-ndk/2010-07/msg00424.html, which tells me to "add
jni and jni/include to the above LOCAL_C_INCLUDES" in crypto/Android.mk, but I can't figure out the syntax I should use to achieve this.
I also can't figure out of I have the correct directory structure.
I sincerely appreciate any help that can be offered.
Thanks!
I solved this problem by abandoning https://github.com/fries/android-external-openssl and instead using https://github.com/guardianproject/openssl-android.
It is based on a more recent OpenSSL (1.0.0a), and it builds in the NDK without any modifications.
Note that in order to use these libraries in an Android app, you must rename them. If you simply include the resulting libssl.so and libcrypto.so in your app, then call System.LoadLibrary ("crypto") and System.LoadLibrary ("ssl"), you will get the OpenSSL libraries included in the Android system, not your custom libraries.
To do this, just do a full-word search and replace ("libssl" -> "libsslx", and "libcrypto" -> "libcryptox") in each Android.mk (i.e, in /crypto, /ssl, and /apps).
Then in your Android app, call SystemLoadLibrary ("cryptox") and System.LoadLibrary ("sslx")

Categories

Resources