ekke / android-openssl-qt

scripts to generate openssl .so to be used from Qt Android Projects
50 stars 18 forks source link

How to build OpenSSL on macOS for Android Arm / x86 ? ( removing '-mandroid' from Makefile helps ) #8

Open esutton opened 6 years ago

esutton commented 6 years ago

Building OpenSSL on macOS is a challenge!! One day wasted and counting...

What I have tried so far:

Qt 5.9 Adding OpenSSL Support for Android

Follow this first: Qt 5.9 Adding OpenSSL Support for Android

File: Setenv-android.sh

_ANDROID_NDK="android-ndk-r9"
_ANDROID_EABI="arm-linux-androideabi-4.9"
# _ANDROID_ARCH=arch-x86
_ANDROID_ARCH=arch-arm

Attempt to build OpenSSL

1) Edit Makefile.shared to remove -Bsymbolic 2) Edit Makefile.shared to replace -soname with -install_name

Example:

#DO_GNU_SO=$(CALC_VERSIONS); \
#   SHLIB=lib$(LIBNAME).so; \
#   SHLIB_SUFFIX=; \
#   ALLSYMSFLAGS='-Wl,--whole-archive'; \
#   NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
#   SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-Bsymbolic -Wl,-soname=$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"
# https://stackoverflow.com/questions/4580789/ld-unknown-option-soname-on-os-x

O_GNU_SO=$(CALC_VERSIONS); \
    SHLIB=lib$(LIBNAME).so; \
    SHLIB_SUFFIX=; \
    ALLSYMSFLAGS='-Wl,--whole-archive'; \
    NOALLSYMSFLAGS='-Wl,--no-whole-archive'; \
    SHAREDFLAGS="$(CFLAGS) $(SHARED_LDFLAGS) -shared -Wl,-install_name,$$SHLIB$$SHLIB_SOVER$$SHLIB_SUFFIX"

3) Create Makefile

./Configure shared android

4) Remove '''CFLAG''' option '''-mandroid''' from Makefile

5) Build make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER="

Resulting error: syntax error near unexpected token `;'

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../libcrypto.a(v3_asid.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../libcrypto.a(v3_addr.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: ../../libcrypto.a(cms_cd.o) has no symbols
if [ -n "libcrypto.so.1.0.0 libssl.so.1.0.0" ]; then \
        (cd ..; /Applications/Xcode.app/Contents/Developer/usr/bin/make libcrypto.so.1.0.0); \
    fi
[ -z "" ] || gcc -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H  -I/include -B/lib -O3 -fomit-frame-pointer -Wall -Iinclude \
        -DFINGERPRINT_PREMAIN_DSO_LOAD -o fips_premain_dso  \
        fips_premain.c fipscanister.o \
        libcrypto.a -ldl
/bin/sh: -c: line 0: syntax error near unexpected token `;'
/bin/sh: -c: line 0: `; SHOBJECTS="libcrypto.a "; ( :; LIBDEPS="${LIBDEPS:--L.  -ldl}"; SHAREDCMD="${SHAREDCMD:-gcc}"; SHAREDFLAGS="${SHAREDFLAGS:--fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H  -I/include -B/lib -O3 -fomit-frame-pointer -Wall }"; LIBPATH=`for x in $LIBDEPS; do echo $x; done | sed -e 's/^ *-L//;t' -e d | uniq`; LIBPATH=`echo $LIBPATH | sed -e 's/ /:/g'`; LD_LIBRARY_PATH=$LIBPATH:$LD_LIBRARY_PATH ${SHAREDCMD} ${SHAREDFLAGS} -o $SHLIB$SHLIB_SOVER$SHLIB_SUFFIX $ALLSYMSFLAGS $SHOBJECTS $NOALLSYMSFLAGS $LIBDEPS ) && if [ -n "$INHIBIT_SYMLINKS" ]; then :; else prev=$SHLIB$SHLIB_SOVER$SHLIB_SUFFIX; if [ -n "$SHLIB_COMPAT" ]; then for x in $SHLIB_COMPAT; do ( :; rm -f $SHLIB$x$SHLIB_SUFFIX; ln -s $prev $SHLIB$x$SHLIB_SUFFIX ); prev=$SHLIB$x$SHLIB_SUFFIX; done; fi; if [ -n "$SHLIB_SOVER" ]; then ( :; rm -f $SHLIB$SHLIB_SUFFIX; ln -s $prev $SHLIB$SHLIB_SUFFIX ); fi; fi'

I think there is something still wrong with my -install_name syntax? How do you build OpenSSL on macOS?

I need to build boih arm7 and x86 so I can test in Genymotion emulator.

@ekke @mabedMRD @alexgarret @machinekoder Qt guys? Any tips or suggestions are greatly appreciated.

esutton commented 6 years ago

I found a solution that works for building OpenSSL on Arm, Arm7, x86, on macOS. You just have to use Android NDK r10e or earlier.

https://github.com/esutton/android-openssl

ekke commented 6 years ago

good to hear that you found a solution. BTW: I'm only developing on macOS, allways using NDK r10e. Never tried x86.

esutton commented 6 years ago

I am developing Android and iOS on macOS using Qt C++ and React Native. React Native requires r10 e. I plan to stick with r10e. Until I have reason to not use it.

x86 build make it quick and easy to debug using Android x86 emulators such as Genymotion. I only tried Ubuntu because I was desperate and suspected the OpenSSL build could have been failing on macOS because of a clang issue. I do not know cause. But r10e just works.