9

NOTE: I went through most of the other posts, they all use an older version of the NDK which would not be ideal for my usecase.

I want to build OpenSSH 8.2 for Android. Here is the script I made to build zlib, OpenSSL and finally OpenSSH. Which unfortunately seems to fail at the final make.

#!/bin/bash

# set ANDROID_NDK_HOME
export ANDROID_NDK_HOME="/opt/android-ndk-r21b"

# add the toolchain to our path
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"

# nb. for x86 set CHOST="i686-linux-android"
export CHOST="arm-linux-androideabi"
export CHOST2="armv7a-linux-androideabi29"
export CC="${CHOST2}-clang"
export CXX="${CHOST2}-clang++"
export RANLIB="${CHOST}-ranlib"
export LD="${CHOST}-ld"
export AR="${CHOST}-ar"
export ARFLAGS="cr"
export CHOST="${CHOST}"

# Build zlib
wget http://zlib.net/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
cd ..

# Build OpenSSL
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar zxf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
./Configure android-arm -D__ANDROID_API__=29
make
cd ..

# Build OpenSSH
#wget https://mirror.csclub.uwaterloo.ca/pub/OpenBSD/OpenSSH/portable/openssh-8.2p1.tar.gz
tar zxf openssh-8.2p1.tar.gz
cd openssh-8.2p1

./configure --host=arm-linux-androideabi --target=arm-linux-androideabi --with-libs --with-zlib=../zlib-1.2.11 --with-ssl-dir=../openssl-1.1.1g --disable-etc-default-login

make ssh

On the make ssh command, the build fails with:

make[1]: Entering directory '/home/edouard/ki4a_deps/openssh-8.2p1/openbsd-compat'
armv7a-linux-androideabi29-clang -g -O2 -pipe -Wunknown-warning-option -Qunused-arguments -Wall -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-result -Wimplicit-fallthrough -fno-strict-aliasing -mretpoline -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong   -fPIC -I. -I.. -I. -I./.. -I/home/edouard/ki4a_deps/openssh-8.2p1/../openssl-1.1.1g/include -I../zlib-1.2.11  -DHAVE_CONFIG_H -c arc4random.c
In file included from arc4random.c:34:
/opt/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/unistd.h:107:20: error: expected ')'
    __attribute__((__sentinel__(1)));

Which is weird because as far as I can tell from Googling around, clang does support __sentinel__. What did I do wrong?

Belval
  • 1,236
  • 10
  • 17
  • 2
    https://github.com/android/ndk/issues/1362 This seems to be a bug report about the same issue. I was able to squash this issue by exporting CFLAGS and CXXFLAGS to "-DHAVE_ATTRIBUTE__SENTINEL__=1" There are further build problems though – Harry Mallon Feb 24 '21 at 13:51
  • @HarryMallon or anyone else – has anyone found a resolution, or at least a workaround to this? On 9.3p, the extra flags resolve the issue described above, but there are still further compile issues. Any pointers? – user149408 May 31 '23 at 20:02
  • I’ve opened https://stackoverflow.com/questions/76376942/openssh-9-3p-fails-to-build-for-android for the next build issue. If anyone has a clue, feel free to contribute. – user149408 May 31 '23 at 20:13

1 Answers1

0

Build openssh command line binaries for Android. Upstreams:

https://github.com/CyanogenMod/android_external_zlib.git -b cm-11.0
https://github.com/CyanogenMod/android_external_openssl.git -b cm-11.0
https://github.com/CyanogenMod/android_external_openssh.git -b cm-11.0

More info in: https://github.com/shmilee/android-cli-openssh

MexiCano
  • 271
  • 1
  • 11