kuri65536 / python-for-android

Automatically exported from code.google.com/p/python-for-android
Apache License 2.0
249 stars 104 forks source link

failed to build with NDK 11 or higher (failed to build openssl) #123

Closed hollychen503 closed 6 years ago

hollychen503 commented 7 years ago

The pre-build version got a negative number for os.path.getsize() with 4GB file. So I try to build my version to test. ( http://stackoverflow.com/questions/5167120/why-does-os-path-getsize-return-a-negative-number-for-a-10gb-file )

But I got a fatal error when building openssl

ubuntu 16.04 android-ndk-r13b

build command:

CFLAGS='-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64' OPT="-g -O2 $CFLAGS" NDK_PATH=/home/ubuntu/source/android-ndk-r13b make build 
make[2]: Leaving directory '/home/ubuntu/source/py4a/python-for-android-master/python-build/openssl/.build_armeabi'

Since you've disabled or enabled at least one algorithm, you need to do
the following before building:

        make depend

Configured for android.
# make -C .build_armeabi/ depend
make -C .build_armeabi/ all
make[2]: Entering directory '/home/ubuntu/source/py4a/python-for-android-master/python-build/openssl/.build_armeabi'
making all in crypto...
make[3]: Entering directory '/home/ubuntu/source/py4a/python-for-android-master/python-build/openssl/.build_armeabi/crypto'
/usr/bin/perl ../util/mkbuildinf.pl ""arm-linux-androideabi-"gcc -mtune=xscale -march=armv5te -msoft-float --sysroot=/home/ubuntu/source/android-ndk-r13b/platforms/android-4/arch-arm -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -fvisibility=default -fPIE -mandroid -I/home/ubuntu/source/android-ndk-r13b/platforms/android-4/arch-arm/usr/include -B/home/ubuntu/source/android-ndk-r13b/platforms/android-4/arch-arm/usr/lib -O3 -fomit-frame-pointer -Wall" "android" >buildinf.h
"arm-linux-androideabi-"gcc -mtune=xscale -march=armv5te -msoft-float --sysroot=/home/ubuntu/source/android-ndk-r13b/platforms/android-4/arch-arm -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -fvisibility=default -fPIE -mandroid -I/home/ubuntu/source/android-ndk-r13b/platforms/android-4/arch-arm/usr/include -B/home/ubuntu/source/android-ndk-r13b/platforms/android-4/arch-arm/usr/lib -O3 -fomit-frame-pointer -Wall   -c -o cryptlib.o cryptlib.c
In file included from cryptlib.c:117:0:
cryptlib.h:62:21: fatal error: stdlib.h: No such file or directory
 # include <stdlib.h>
                     ^
compilation terminated.
<builtin>: recipe for target 'cryptlib.o' failed
make[3]: *** [cryptlib.o] Error 1
make[3]: Leaving directory '/home/ubuntu/source/py4a/python-for-android-master/python-build/openssl/.build_armeabi/crypto'
Makefile:284: recipe for target 'build_crypto' failed
make[2]: *** [build_crypto] Error 1
make[2]: Leaving directory '/home/ubuntu/source/py4a/python-for-android-master/python-build/openssl/.build_armeabi'
Makefile:78: recipe for target '.build_armeabi/libcrypto.so' failed
make[1]: *** [.build_armeabi/libcrypto.so] Error 2
make[1]: Leaving directory '/home/ubuntu/source/py4a/python-for-android-master/python-build/openssl'
Makefile:75: recipe for target '.build_openssl' failed
make: *** [.build_openssl] Error 2
hollychen503 commented 7 years ago

Aha, I known how to fix it.

Modify the /path/to/python-for-android/python-build/openssl/Makefile

Change the ANDROID_API to your NDK platform version. The default is android-4. It may not in your NDK anymore.

for example:

  # setup arch depended variables: arm
  $(OPENSSL_BIN_arm): export ANDROID_API := android-19
phiresky commented 7 years ago

Same issue for me. Shouldn't that API version be pulled from some outside variable?

kuri65536 commented 7 years ago

Please use NDK 10e. I try to build with NDK 13 and then 11, some problem with these NDK and can not solve it (I have no much time to solve them...)

DarkXDroid commented 7 years ago

I got a similar problem but in my case I got an error about "i686-linux-android-gcc" not being found.

On the first run: NDK_PATH=$HOME/Downloads/android-ndk-r10e make build

PYBINR=python CWD=/home/darkxdroid/Downloads/python-for-android/python-build make -C openssl build make[1]: Entering directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl' if ! wget \ wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz; \ then \ https://www.openssl.org/source/old/1.0.2/openssl-1.0.2j.tar.gz; \ fi --2017-03-15 15:30:59-- http://wget/ Resolving wget (wget)... failed: Name or service not known. wget: unable to resolve host address ‘wget’ --2017-03-15 15:30:59-- https://www.openssl.org/source/openssl-1.0.2j.tar.gz Resolving www.openssl.org (www.openssl.org)... 23.40.185.130, 2600:1403:1:286::c1e, 2600:1403:1:28d::c1e Connecting to www.openssl.org (www.openssl.org)|23.40.185.130|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 5307912 (5.1M) [application/x-gzip] Saving to: ‘openssl-1.0.2j.tar.gz’

openssl-1.0.2j.tar.gz 100%[=====================================================>] 5.06M 1.21MB/s in 4.7s

2017-03-15 15:31:05 (1.08 MB/s) - ‘openssl-1.0.2j.tar.gz’ saved [5307912/5307912]

FINISHED --2017-03-15 15:31:05-- Total wall clock time: 5.8s Downloaded: 1 files, 5.1M in 4.7s (1.08 MB/s) /bin/sh: 4: https://www.openssl.org/source/old/1.0.2/openssl-1.0.2j.tar.gz: not found Makefile:59: recipe for target 'openssl-1.0.2j.tar.gz' failed make[1]: [openssl-1.0.2j.tar.gz] Error 127 make[1]: Leaving directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl' Makefile:78: recipe for target '.build_openssl' failed make: [.build_openssl] Error 2

After fail I ran it again and get a different error:

Configured for android-x86.

Because of configuration changes, you MUST do the following before building:

make depend

make -C .build_x86/ depend make[2]: Entering directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl/.build_x86' making depend in crypto... make[3]: Entering directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl/.build_x86/crypto' ../util/domd: 26: ../util/domd: i686-linux-android-gcc: not found Makefile:136: recipe for target 'local_depend' failed make[3]: [local_depend] Error 1 make[3]: Leaving directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl/.build_x86/crypto' Makefile:475: recipe for target 'depend' failed make[2]: [depend] Error 1 make[2]: Leaving directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl/.build_x86' Makefile:106: recipe for target '.build_x86/libcrypto.so' failed make[1]: [.build_x86/libcrypto.so] Error 2 make[1]: Leaving directory '/home/darkxdroid/Downloads/python-for-android/python-build/openssl' Makefile:78: recipe for target '.build_openssl' failed make: [.build_openssl] Error 2

kuri65536 commented 7 years ago

Thank you for your report. I success to build the openssl with a latest Makefile script.

  1. download error: I fixed download errors in the past.
  2. compiler error: Did you use latest version of python-build/openssl/Makefile or python3-alpha/openssl/Makefile ?

Below are core code of compile for android-x86.

$(OPENSSL_BIN_x86): export ANDROID_API := android-9
$(OPENSSL_BIN_x86): \
    export ANDROID_TOOLCHAIN=$(NDK_PATH)/toolchains/$(eabi_x86)/prebuilt/$(host)/bin
$(OPENSSL_BIN_x86): export PATH:=$(ANDROID_TOOLCHAIN):$(PATH)
$(OPENSSL_BIN_x86): export _ANDROID_ARCH=arch-x86
$(OPENSSL_BIN_x86): export _ANDROID_EABI=$(eabi_x86)
$(OPENSSL_BIN_x86): export MACHINE=i686
$(OPENSSL_BIN_x86): export ARCH=x86
$(OPENSSL_BIN_x86): PREFIX=$(CWD)/$(PYBINR)_$(ARCH)/$(PYBINR)
$(OPENSSL_BIN_x86): export CROSS_COMPILE="i686-linux-android-"
$(OPENSSL_BIN_x86): export PATH:=$(ANDROID_TOOLCHAIN):$(PATH)
$(OPENSSL_BIN_x86): \
    export ANDROID_TOOLS="i686-linux-android-gcc arm-linux-androideabi-ranlib arm-linux-androideabi-ld"

$(OPENSSL_BIN_x86): .build_x86/Makefile
    ./showenv.sh
    cd $(dir $<); perl $(perlopt) Makefile.org
    cd $(dir $<); ./config $(__PIE_CFLAGS) shared no-ssl2 no-ssl3 no-comp no-hw no-engine \
      --openssldir=$(PREFIX)/share --prefix=$(PREFIX)
    make -C $(dir $<) depend
    make -C $(dir $<) all
    make -C $(dir $<) install_sw
DarkXDroid commented 7 years ago

I cloned the git repo! So i Suppose it's the last one and I did install the package. I used the ndkr10e... I managed to to build the first part involving the sdk but I stumble with that problem on the ndk part as you can see.

Using Linux Mint 18

The output of "showenv.sh" are empty variables

Sorry but can you tell me the path to the logs?

kuri65536 commented 7 years ago
  1. Download script: I plan to reduce the warnings and errors, but no problems. (Sorry I did not check it)
  2. Build log: console output is all. please see my logs. >>> log.txt.zip

    If you want to save the log, type the command to start build (in python3-alpha directory)::

$ NDK_PATH=~/install/android-ndk-r10e make .build_openssl 2>&1 | tee log.txt