Workarounds to build for Android under Mac OS X

Jan 10, 2015 at 2:48 AM
Edited Jan 10, 2015 at 10:51 AM
There were a few issues I came across when compiling Casablanca for Android under Mac OS X and here are some workarounds that seems to get the library to build. I haven't tested the binary in a project yet and this is the first time I have actually played around with a C++ build system so forgive if any/all of these changes are wrong/unnecessary.
  • Download and extract the Android NDK r10. Doesn't work with newer revisions, e.g. r10d.
    https://dl.google.com/android/ndk/android-ndk32-r10-darwin-x86_64.tar.bz2
    
  • Install wget and gnu-sed(some regex ops seems to require different flags for the OS X version).
    brew install wget
    brew install gnu-sed --default-names
    
  • Clone the source (N.B. git not git01).
    git clone https://git.codeplex.com/casablanca
    
  • Change the paths in the Boost for Android patches to point to the darwin toolchain instead of linux. I suppose this could be done with whatever host platform identification features/variables CMake has.
    Build_android/boost-for-android-x86.patch Lines 53, 56 and 92
    Build_android/boost-for-android.patch Lines 53, 56 and 136
    
  • Change Line 42 in Release/src/CMakeLists.txt. This might actually be a typo as curly braces are used in the rest of the script.
    - set(SOURCES $(SOURCES) http/client/x509_cert_utilities_android.cpp)
    + set(SOURCES ${SOURCES} http/client/x509_cert_utilities_android.cpp)
    
Hopefully you should now be able build using the given instructions. The build took a very long time to complete.
Jan 12, 2015 at 7:00 PM
Thanks a bunch for compiling these instructions!
Jan 12, 2015 at 8:44 PM
Yes thanks opsimath for sharing out these instructions. I'm sure others will benefit. I've changed to curly braces in that location in the development branch.

Steve
Feb 24, 2015 at 8:33 AM
So any idea when this will be fixed? I can't really used the 32bit versions of the libraries.

Heisenberg
Feb 24, 2015 at 8:51 AM

Well there is still a probe;em: I get this error now:

Since you've disabled or enabled at least one algorithm, you need to do
the following before building:
make depend
Configured for android-x86.
making depend in crypto...
../util/domd: line 25: i686-linux-android-gcc: command not found
make[2]: *** [depend] Error 1
make[1]: *** [depend] Error 1

make: *** [x86/lib/libssl.a] Error 2

Also the sed lines in the Makefile for openssl fail on Mac

setenv-android-x86.sh: setenv-android.sh
    cp setenv-android.sh setenv-android-x86.sh.tmp
    sed -i 's/_ANDROID_EABI="arm-linux-androideabi-4.8"/_ANDROID_EABI="x86-4.8"/g' setenv-android-x86.sh.tmp
    sed -i 's/_ANDROID_ARCH=arch-arm/_ANDROID_ARCH=arch-x86/g' setenv-android-x86.sh.tmp
    mv setenv-android-x86.sh.tmp setenv-android-x86.sh
With this error:
sed: 1: "setenv-android-x86.sh.tmp": unterminated substitute in regular expression


Heisenberg
Nov 27, 2015 at 8:18 PM
I'm having the same issue. Please help.
sed -i 's/_ANDROID_EABI="arm-linux-androideabi-4.8"/_ANDROID_EABI="x86-4.8"/g' setenv-android-x86.sh.tmp
sed: 1: "setenv-android-x86.sh.tmp": unterminated substitute in regular expression
make: *** [setenv-android-x86.sh] Error 1
Nov 27, 2015 at 10:07 PM
Edited Nov 27, 2015 at 10:08 PM
I've managed to make it work.

You can try with replacing the content of the Makefile in /casablanca/Build_android/openssl/

with the following

SHELL := /bin/bash
OPENSSL_VER = openssl-1.0.1h

all: armeabi-v7a/lib/libssl.a x86/lib/libssl.a

clean:
    rm -rf $(OPENSSL_VER)
    rm -rf $(OPENSSL_VER)-armeabi-v7a
    rm -rf armeabi-v7a
    rm -rf setenv-android-x86.sh

setenv-android.sh:
    wget https://wiki.openssl.org/images/7/70/Setenv-android.sh
    mv Setenv-android.sh setenv-android.sh
    chmod a+x setenv-android.sh

setenv-android-x86.sh: setenv-android.sh
    cp setenv-android.sh setenv-android-x86.sh.tmp
    sed -i '' 's/_ANDROID_EABI="arm-linux-androideabi-4.8"/_ANDROID_EABI="x86-4.8"/g' setenv-android-x86.sh.tmp
    sed -i '' 's/_ANDROID_ARCH=arch-arm/_ANDROID_ARCH=arch-x86/g' setenv-android-x86.sh.tmp
    mv setenv-android-x86.sh.tmp setenv-android-x86.sh

$(OPENSSL_VER).tar.gz:
    wget http://www.openssl.org/source/$(OPENSSL_VER).tar.gz

armeabi-v7a/lib/libssl.a: setenv-android.sh $(OPENSSL_VER).tar.gz
    [ -d "$(ANDROID_NDK_ROOT)" ]
    export ANDROID_NDK_ROOT="$(ANDROID_NDK_ROOT)"; \
    . ./setenv-android.sh; \
    ( \
        set -e; \
        rm -rf $(OPENSSL_VER)/; \
        tar xzf $(OPENSSL_VER).tar.gz; \
        rm -rf $(OPENSSL_VER)-armeabi-v7a/ \
    ) && \
    mv $(OPENSSL_VER) $(OPENSSL_VER)-armeabi-v7a && \
    cd $(OPENSSL_VER)-armeabi-v7a && \
    perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org && \
    ./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir="`pwd`/../armeabi-v7a" && \
    make depend && \
    make all && \
    make install CC=$${ANDROID_TOOLCHAIN}/arm-linux-androideabi-gcc RANLIB=$${ANDROID_TOOLCHAIN}/arm-linux-androideabi-ranlib

x86/lib/libssl.a: setenv-android-x86.sh $(OPENSSL_VER).tar.gz
    [ -d "$(ANDROID_NDK_ROOT)" ]
    export ANDROID_NDK_ROOT="$(ANDROID_NDK_ROOT)"; \
    . ./setenv-android-x86.sh; \
    ( \
        set -e; \
        rm -rf $(OPENSSL_VER)/; \
        tar xzf $(OPENSSL_VER).tar.gz; \
        rm -rf $(OPENSSL_VER)-x86/ \
    ) && \
    mv $(OPENSSL_VER) $(OPENSSL_VER)-x86 && \
    cd $(OPENSSL_VER)-x86 && \
    perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org && \
    ./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir="`pwd`/../x86" && \
    make depend && \
    make all && \
    make install CC=$${ANDROID_TOOLCHAIN}/i686-linux-android-gcc RANLIB=$${ANDROID_TOOLCHAIN}/i686-linux-android-ranlib