Getting cygwin to recognise my updated awk for the android ndk? - android

This starts off as an Android question but I think becomes a linux/cygwin question.
The Android ndk is shipped with an unsuitable version of awk - definitive report here - so I'm trying to get cygwin to accept that I don't want to use the ndk awk, but to use nawk or gawk instead.
Bearing in mind I know nothing about linux/cygwin, these are my discoveries:
The first part of the question has already been answered here so I know I need to rename the existing awk as awk_ so it isn't picked up (done). And I need to set the cygwin environment variable HOST_AWk to gawk (or nawk - both of which are supplied with cygwin). The easy way to do this (for me) is to set that environment variable in Windows - then when cygwin runs it imports all the environment stuff from Windows.
So I think I know what to do, but the value of HOST_AWK doesn't seem to be picked up when I try to do a build either directly in eclipse (build all) or in cygwin from bash:
Barry#BARRY /cygdrive/c/data/eclipse/camfeeda/jni
$ ndk-build
make: awk: Command not found
Android NDK: Host 'awk' tool is outdated. Please define HOST_AWK to point to Gawk or Nawk !
/cygdrive/c/DATA/eclipse/android/android-ndk-r7/build/core/init.mk:258: *** Android NDK: Aborting. . Stop.
Barry#BARRY /cygdrive/c/data/eclipse/camfeeda/jni
$ printenv HOST_AWK
c:\cygwin\bin\gawk.exe
As you see I have set HOST_AWK to gawk.exe in the correct location, but I've tried:
HOST_AWK=c:\cygwin\bin\gawk.exe
HOST_AWK=c:\cygwin\bin\gawk
HOST_AWK=c:\cygwin\bin\nawk.exe
HOST_AWK=c:\cygwin\bin\nawk
And I've tried using forward slashes in case that was the problem, but I still get the same error :(
I feel as if I am so close, but I can't make the last step. Why won't ndk-build read the environment variable HOST_AWK and do the dratted job?! Can anyone put me out of my misery?
Many thanks
Barry
Edit: I also tried:
HOST_AWK=/cygdrive/c/cygwin/bin/gawk.exe
etc, but no joy.
B.

For me it's just deleting/renaming awk.exe that is shipped with ndk-r7. And they everything works. No need for setting HOST_AWK env variable.

Related

cargo ndk fails due to pkg-config issue

I think I've read every suggestion on the internet at this point to no avail, so I'm hoping I can get some help here.
Repro
git clone https://github.com/banool/aclip.git
cd aclip/frontend/native
cargo ndk -t armeabi-v7a -o ../android/app/src/main/jniLibs build
The code in question: https://github.com/banool/aclip.
Relevant env:
PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig/
LDFLAGS=-L/opt/homebrew/opt/openssl#1.1/lib
CPPFLAGS=-I/usr/local/opt/openssl#1.1/include
CFLAGS=-I/opt/homebrew/opt/openssl#1.1/include
ANDROID_NDK_HOME=/Users/dport/Library/Android/sdk/ndk
Output
Running the above gives me this: https://gist.github.com/d2564965bbd5e4d8bf72c3132c87255f.
Some thoughts on what's going on here:
I see it says NDK API level: 21. Is this level not the same as the NDK level, which as you can see in the previous line is 24?
I have tried setting PKG_CONFIG_SYSROOT_DIR to the NDK directory. That gives me instead this rather cryptic error: https://gist.github.com/b28eae5f666fccaffe80278a5a8a80e1. I wonder if there is a better directory to use.
I did everything here relevant to the second part, where I'm trying to use a newer NDK: http://cjycode.com/flutter_rust_bridge/template/setup_android.html.
I have set the libunwind stuff suggested here: http://cjycode.com/flutter_rust_bridge/template/setup_android.html. That helped with the gcc error in the second gist here, but I've still got the ssl and crypto errors.
Any tips on how to proceed would be very much appreciated.
Thanks!
For me I was able to skirt around the issue by doing this.
First, figure out what openssl crate version we're relying on:
$ cargo tree --target=x86_64-unknown-linux-musl -i openssl-sys | grep openssel
openssl-sys v0.9.74
└── openssl v0.10.40
Then add something like this to your Cargo.toml:
openssl = { version = "0.10.40", features = ["vendored"] }
This avoids the need for the system openssl.

/usr/bin/as: unrecognized option '-EL'

So while compiling android kernel for my 1plus phone, after multiples attempts over 3 days, I gave up and give a try to ask here if anyone had this problem before.
The bug is a bit obscure to me, but I feel like the problem comes from my recent change to a GNU/Linux distribution (Gentoo), which is somehow overriding the AS environment variable when it shouldn't; it fails at assembling VDSO, but I've no idea sadly from where the overriding comes. (maybe they did a modify the make command in order to allow supporting flags overriding etc..)
EDIT, Small version:
make RANLIB=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-ranlib CC='/media/sda2/git/linux-x86/clang-bootstrap/bin/clang -fintegrated-as' LD=/media/sda2/git/linux-x86/clang-bootstrap/bin/ld.lld AR=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-ar AS=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-as NM=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-nm OBJCOPY=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-objcopy OBJDUMP=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-objdump READELF=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-readelf OBJSIZE=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-size STRIP=/media/sda2/git/linux-x86/clang-bootstrap/bin/llvm-strip
CC kernel/bounds.s
CC arch/arm64/kernel/asm-offsets.s
In file included from arch/arm64/kernel/asm-offsets.c:25:
In file included from ./include/linux/kvm_host.h:39:
In file included from ./arch/arm64/include/asm/kvm_host.h:42:
In file included from ./include/kvm/arm_pmu.h:21:
In file included from ./include/linux/perf_event.h:57:
In file included from ./include/linux/cgroup.h:28:
./include/linux/cgroup-defs.h:475:16: warning: field 'cgrp' with variable sized type 'struct cgroup' not at the end of a struct or class is a GNU extension [-Wgnu-variable-sized-type-not-at-end]
struct cgroup cgrp;
^
1 warning generated.
CALL scripts/checksyscalls.sh
LDS arch/arm64/kernel/vdso/vdso.lds
VDSOA arch/arm64/kernel/vdso/gettimeofday.o
/usr/bin/as: unrecognized option '-EL'
clang-12: error: assembler command failed with exit code 1 (use -v to see invocation)
make[1]: *** [arch/arm64/kernel/vdso/Makefile:57: arch/arm64/kernel/vdso/gettimeofday.o] Error 1
make: *** [arch/arm64/Makefile:201: vdso_prepare] Error 2
Environment variables:
# https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/
export PATH='/media/sda2/git/aarch64-linux-android-4.9/bin':${PATH}
export LD_LIBRARY_PATH='/media/sda2/git/aarch64-linux-android-4.9/lib':${LD_LIBRARY_PATH}
# git clone https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86
export PATH='/media/sda2/git/linux-x86/clang-bootstrap/bin':${PATH}
export LD_LIBRARY_PATH='/media/sda2/git/linux-x86/clang-bootstrap/lib':${LD_LIBRARY_PATH}
export ARCH=arm64
export SUBARCH=arm64
export CROSS_COMPILE='aarch64-linux-android-'
export CROSS_COMPILER=$PATH
export CLANG_TRIPLE='aarch64-linux-gnu-'
export KCFLAGS='-pipe -O3'
export KCPPFLAGS='-pipe -O3'
Kernel used:
https://github.com/LineageOS/android_kernel_oneplus_sm8250
Any ideas?
I use Google's clang prebuilt compiler (could build it myself but in order to gain time) in order to use polly for compiling android kernels since Gentoo LLVM team doesn't apparently have yet a use flag for it.
At worse I'm thinking to use Ubuntu binutils/automake etc / creating a docker environment in order to compile this kernel but this just doesn't make many sense to me since I should be able to do it on my own host system.
Thank you for your help and your care.
I got it solved.
After removing LD=/media/sda2/git/linux-x86/clang-bootstrap/bin/ld.lld for the linker, it worked, I suppose the clang linker was using /usr/bin/as by default and not aarch64-linux-android-as which is google's prebuilt. I'll need to investigate about it further. I'll edit this post once I found more.
I have met the same problem.
The root cause is that the CLANG_PATH should add before the PATH.
// have chance to use /usr/bin/as
export PATH=$PATH:$CLANG_PATH // wrong
export PATH=${CLANG_PATH}:${PATH} // correct
IGNORE
set the cross-compile tool patch correctly
The reason is that you do not set the CROSS_COMPILE and the CROSS_COMPILE_ARM32 correctly.
The aarch64-linux-android-as can not find in PATH. So it uses /usr/bin/as.
You should put the cross compile tools into patch or just set the absolute patch like this:
export CROSS_COMPILE=$CROSS/aarch64/aarch64-linux-android-4.9/bin/aarch64-linux-android-
export CROSS_COMPILE_ARM32=$CROSS/arm/arm-linux-androideabi-4.9/bin/arm-linux-androideabi-
do not set LD when make deconfig
- make CC=clang LD=ld.lld HOSTCC=clang AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip O=out floral_defconfig
+ make CC=clang HOSTCC=clang AR=llvm-ar NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump STRIP=llvm-strip O=out floral_defconfig
I have changes to this problem in one script but never meet it in another build script. By diffing the two files, I find the correct one does not set LD=ld.lld in make defconfig.

Android NDK path variable for "strip" command in CMake build tool chain

I am trying to add a strip debug symbols step for my Android library which includes native shared libraries for different ABIs, e.g. x86/native-lib.so, x86_64/native-lib.so, arm64-v8a/native-lib.so, etc.
I understand that the strip command must be respective to each ABI. So, I need to invoke the correct strip command, for which I need to know its correct path during build time.
For example, for ABI x86_64, I need to have below path setting:
set(STRIP ~/Library/Android/android-ndk-r16b/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/bin/x86_64-linux-android-strip)
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND ${STRIP}
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
The path I need is illustrated like below:
So, my questions are:
Is there an existing CMake variable to point at this path, i.e. /android-ndk-r16b/toolchains/???/prebuilt/???/bin/???-???-???-strip?
If not, is there a way to form this path utilising other known Android CMake variable, e.g. ANDROID_NDK, ANDROID_ABI, etc?
Thanks #Alex Cohn a lot for pointing out the file android.toolchain.cmake which usually exists at directory ~/Library/Android/sdk/cmake/cmake_version_xxx/android.toolchain.cmake on macOS.
There are many useful Android CMake variables already configured inside, e.g.
ANDROID_NDK
ANDROID_TOOLCHAIN
ANDROID_ABI
ANDROID_PLATFORM
ANDROID_STL
ANDROID_PIE
ANDROID_CPP_FEATURES
ANDROID_ALLOW_UNDEFINED_SYMBOLS
ANDROID_ARM_MODE
ANDROID_ARM_NEON
ANDROID_DISABLE_NO_EXECUTE
ANDROID_DISABLE_RELRO
ANDROID_DISABLE_FORMAT_STRING_CHECKS
ANDROID_CCACHE
And the one ANDROID_TOOLCHAIN_PREFIX is exactly what I looked for, so my final CMake script comes into below:
add_custom_command(TARGET ${SHARED_LIBRARY_NAME} POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -g -S -d --strip-debug --verbose
"${DIST_LIBS_DIR}/${LIB_BUILD_TYPE}/${ANDROID_ABI}/lib${SHARED_LIBRARY_NAME}.so"
COMMENT "Strip debug symbols done on final binary.")
And I don't need to explicitly pass any additional arguments, i.e. DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake, from command line to the build process. Because, this file, i.e. android.toolchain.cmake, was already taken into account automatically by Android native build system.
You can use ${CMAKE_STRIP}. It is set appropriately when you use -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake. I hope it is OK also if you work with 'built-in' Android support with supported NDK version.

You need the NDKr9 or later

I tried to build android-vlc and ijkPlayer using Git, and after following the steps and making the required sdk and ndk exports for each one, both lead me to the same error message through Git-Bash which is:
You need NDKr9 or later
I have NDKr9b and NDKr10d and I got this error message with both of them, and after having a look at android-vlc sdk source code I found that it just checking the /RELEASE.TXT file in the ndk provided path:
# try to detect NDK version
REL=$(grep -o '^r[0-9]*.*' $ANDROID_NDK/RELEASE.TXT 2>/dev/null|cut -b2-)
case "$REL" in
9*|10*)
GCCVER=4.8
CXXSTL="/"${GCCVER}
;;
7|8|*)
echo "You need the NDKv9 or later"
exit 1
;;
esac
and when checking it my self for NDK10, I found that it only contains one line which is:
r10d (64-bit)
and in NDK9 it is:
r9b
which supposed to make the code run without problems in both cases, so what am I missing here?
p.s. I came across this question which provides the same problem but it's answer doesn't work with me.

Trying to compile JNI (native) parts of the NDK's San Angeles example (Windows)

I'm trying to do what the question says -- using a Cygwin shell. I've set it up according to 2 essentially equivalent tutorials I've Googled but yet I can not get the shell/make process to work properly. Unix/Cygwin skills lack, obviously.
So, my Cygwin is installed to it's default location and I've got the Android SDK and NDK set up right as well (normal Java apps work fine building/debugging from Eclipse).
This is how my modified Cygwin.bat looks:
#echo off
set IS_UNIX=
set DEV_ROOT=c:/PROGRA~1/Android/android-ndk-r6/samples/san-angeles
set JAVA_HOME=c:/PROGRA~1/Java/jdk1.6.0_26
set CLASSPATH=c:/PROGRA~1/Android/android-ndk-r6/samples/san-angeles/obj
set PATH=c:/PROGRA~1/Android/android-sdk/tools;c:/PROGRA~1/Android/android-ndk-r6
set ANDROID_NDK_ROOT=c:/PROGRA~1/Android/android-ndk-r6
set NDK_PROJECT_PATH=c:/PROGRA~1/Android/android-ndk-r6/samples/san-angeles
C:
chdir C:\cygwin\bin
bash --login -i
These paths are correct. When I change path to the NDK root and type ./ndk-build, this is the result:
nova#edwmini ~
$ cd c:/progra~1/android/android-ndk-r6
nova#edwmini /cygdrive/c/progra~1/android/android-ndk-r6
$ ./ndk-build
/cygdrive/c/progra~1/android/android-ndk-r6/build/core/build-binary.mk:37: *** t
arget pattern contains no `%'. Stop.
nova#edwmini /cygdrive/c/progra~1/android/android-ndk-r6
$
A kick in my ass in the right direction would be greatly appreciated.
I've fixed the problem using the comments.
Firstly I had to go to the project path in order to build, secondly it helped when I replaced all the DOS paths for posix/Cygwin paths! Here is the new batch file:
#echo off
set DEV_ROOT=/cygdrive/c/PROGRA~1/Android/android-ndk-r6/samples/hello-gl2
set IS_UNIX=
set JAVA_HOME=/cygdrive/c/PROGRA~1/Java/jdk1.6.0_26
set ANDROID_NDK_ROOT=/cygdrive/c/PROGRA~1/Android/android-ndk-r6
set PATH=/cygdrive/c/PROGRA~1/Android/android-sdk/tools:%ANDROID_NDK_ROOT%:$PATH
set CLASSPATH=%DEV_ROOT%/obj
set NDK_PROJECT_PATH=%DEV_ROOT%
C:
chdir C:\cygwin\bin
bash --login -i
The sample has changed but you'll get it. Also, #startup, do: cd $DEV_ROOT

Categories

Resources