Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
esutton opened this issue Jul 18, 2018 · 3 comments

Comments

@esutton
Copy link

esutton commented Jul 18, 2018

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

  • Qt 5.9 Android app works fine on Android Kit Kat 4.4.
  • On Android 7.0 I get run time messages:
qt.network.ssl: QSslSocket: cannot call unresolved function SSL_CTX_ctrl

I got past the '-mandroid' issue by removing it from the Makefile

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"
  1. Create Makefile
./Configure shared android
  1. Remove '''CFLAG''' option '''-mandroid''' from Makefile

  2. 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 esutton changed the title [ MacOS unknown argument: '-mandroid' ] ( Remove it from Makefile ) How to build OpenSSL for Android Arm and x86 on macOS? ( removing '-mandroid' from Makefile helps ) Jul 18, 2018
@esutton esutton changed the title How to build OpenSSL for Android Arm and x86 on macOS? ( removing '-mandroid' from Makefile helps ) How to build OpenSSL on macOS for Android Arm / x86 ? ( removing '-mandroid' from Makefile helps ) Jul 18, 2018
@esutton
Copy link
Author

esutton commented Jul 21, 2018

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
Copy link
Owner

ekke commented Jul 22, 2018

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

@esutton
Copy link
Author

esutton commented Jul 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants