Android Studio 3.0.1 Ignoring APP_ABI in Application.mk? - android-studio

Is Android Studio supposed to ignore values in Application.mk when building NDK applications?
I have changed my Application.mk as follows yet my project keeps building x86, mips etc. It should only be building armeabi-v7a
#APP_ABI := all
APP_ABI := armeabi-v7a
Build output - see the x86
I have noticed references to NDK_APP_ABI and NDK_DEFAULT_ABIS inside the setup-app.mk file. Are these supposed to override what is contained in Application.mk?
Are there variables that can be specified inside the build.gradle files that will propagate into the setup-app.mk file?
Where is the best place to find documentation on this? - Google documentation is very sparse at the moment.

Yes, the technical reason is that gradle specifies APP_ABI on the command line of ndk-build that it generates. And for gnu make, command line parameters override whatever is written in the Makefile.
Make has the override keyword which could help... Only that this will destroy the delicate structure of externalNativeBuild. If you want your ndkBuild to cooperate with Android Studio, keep your scripts as simple and clean as possible.
The gradle plugin uses abiFilters to tune the build. Actually, the official docs describe it pretty well.

Related

Input/output error using Android ndk-build

Using Android NDK R10E, I am trying to build a shared library for all supported ABI's and I am getting the following error for some but not all ABI's:
[armeabi] SharedLibrary : libMyLib.so /home/user/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld:
fatal error: /home/user/source/MyLib/obj/local/armeabi/libMyLib.so: Input/output error
The project successfully builds for arm64-v8a, mips and mips64 but fails with the above error for armeabi, armeabi-v7a, x86 and x86_64.
I have a static library project and another shared library project and they both build successfully for all 7 ABI's.
If I compare the contents of obj/local/ for an ABI that builds and one that does not, they both contain all the same files except for libMyLib.so.
The difference between those two sets of ABIs is that the failing ones link using ld.gold and the working ones use ld.bfd.
Two things to try:
Use the 4.9 toolchain. It hopefully has the bug fix.
If that doesn't work, you can add -fuse-ld=bfd to your ldflags to use bfd even on the architectures that default to gold.
Same issue happened to me in r15c.
The fix was to copy
android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/ld.bfd over ld.
I had to copy it because I could not easily find a way to specify this flag to CMake to use it while detecting the compiler features.

Is it posible to make the NDK compiler ignore specific cpp files through code inside them?

First of all I must say I'm new to Android NDK development.
I'm trying to compile a working engine (openGL and openCL based) with the NDK to use it in Android.
I have variables in the headers and cpp files defined to separate the OpenGL 3.0 code and the OpenGLES 2.0 one.
Anyways, in the Android.mk file I recursively add all the .cpp files in the folders and subfolders when compiling so no code differentiation is performed and the compilation fails.
How can I work around this?
(I'm using Eclipse Luna CDT + ADT in MAC OSX)
Ok, this is done via the Android.mk file adding the flags:
LOCAL_CFLAGS := -DANDROID_NDK
This defines the MACRO "ANDROID_NDK"
Then in the code use:
#ifdef ANDROID_NDK
...
and so on.

Android NDK - Where to put the .so file which specified in LOCAL_SHARED_LIBRARIES?

I have successfully build libcurl for android as a shared library, both armeabi-v7a and x86, and one of my project depends on it. I have set "LOCAL_SHARED_LIBRARIES := libcurl", the problem is where should I put those libcurl.so files?
I tried putting them under (project)/jni/lib/(platform)/libcurl.so, and ndk-build gives me a whole load of linking error. (project)/lib/(platform)/libcurl.so will not work too because ndk-build will clear this directory before build.
So I tried again, building 1 platform at a time, however I still have no idea where to put it. jni/libcurl.so will not work.
Simple, follow this, download curl source from http://curl.haxx.se/
- prepare the toolchain of the Android NDK for standalone use; this can
be done by invoking the script:
./build/tools/make-standalone-toolchain.sh
which creates a usual cross-compile toolchain. Lets assume that you put
this toolchain below /opt then invoke configure with something like:
export PATH=/opt/arm-linux-androideabi-4.4.3/bin:$PATH
./configure --host=arm-linux-androideabi [more configure options]
make
Done.

Cannot build static library with Android NDK R8

I have been building a shared library with the Android NDK and now want to build it as a static library. I assumed that all I had to do was change BUILD_SHARED_LIBRARY to BUILD_STATIC_LIBRARY in Android.mk but now when I run ndk-build, absolutely nothing happens. It just comes right back to the command prompt without displaying anything. I tried ndk-build -n and it shows 3 rm commands being executed and nothing else. I tried ndk-build -B and it makes no difference. I tried ndk-build -d and there is nothing in the output related to my source files or the name of the library.
If I change the make file back to build the shared library, it compiles the source and links the .so with no problems.
Anyone have any ideas what could be wrong?
It seems that in order to build a static library, it must be a dependency of something. I was able to build my library as static by adding an Application.mk file with the following line:
APP_MODULES = mylib

Building SDL2 with NDK toolchain

I wonder if anyone did managed to build the fresh SDL2 with the toolchain of the Android NDK(r8d).
SDL2 seems to be very close to the release (since yesterday it isn't "UNDER CONSTROCTION anymore: http://hg.libsdl.org/SDL/rev/0a3d2ec7af6d). It comes with an Android.mk and just compiles fine following the instructions in the bundled README.android file. My question is whether there's really no working automake based build is available or will be available to compile it on Android, or something's wrong with my toolchain setup?
I have installed the NDK toolchain following the instructions of the documentation located at $NDK/doc/STANDALONE-TOOLCHAIN.html. I'm using gcc 4.6. Here's one environment i use:
#!/bin/sh
export TOOLCHAIN=$HOME/Android/android-14-arm
export PATH=$TOOLCHAIN/bin:$PATH
export SYSROOT=$TOOLCHAIN/sysroot
export CROSS_COMPILE="arm-linux-androideabi"
export CC=$CROSS_COMPILE-gcc
export CXX=$CROSS_COMPILE-g++
export CPP=$CROSS_COMPILE-cpp
export CFLAGS="-march=armv7-a -mfloat-abi=softfp -mfpu=neon"
export LDFLAGS="-march=armv7-a -Wl,--fix-cortex-a8"
echo "Compiler set up for ARM 14"
The configure params:
./configure --host=arm-linux-androideabi --prefix=$SYSROOT/usr/local
With the same configuration i successfully built libjpeg-turbo v8 and SDL_image.
The configure script recognizes the cross-compiler, and builds the makefile, however, it finds X11 support, can't see the OpenGL ES... The make fails:
In file included from /usr/include/features.h:378:0,
from /usr/include/sys/types.h:27,
from ./include/SDL_stdinc.h:35,
...
I checked the configure log, i have no idea where the "/usr/include" comes from.
But in fact, the generated makefile adds that line in the EXTRA_CFLAGS to the compiler.
The NDK doc refers the --with-sysroot=$SYSROOT as optional, i've included it to see if it solves the problem, but that didn't help.
As a last effort i manually edited the Makefile, fixing that reference, and now the compiler complained about X11.h.
AFAIK Android has nothing to do with X11, so i guess the whole build-tree completely inappropriate to use with NDK.
I have also tried a different configuration, found in an older thread here.
Neither defining -DANDROID -mandroid -fomit-frame-pointer nor changing back to -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -mthumb" solved the problem.
On previous projects, i had to refresh config.guess, and config.sub in order to get my compiler recognized. SDL doesn't seem to use those. Furthermore no Makefile.ac or Makefile.am comes with SDL to work with, and no templates for other platform could be used for a good starting point to create my own makefile. Additionally, i've never had to deal with makefiles, i really have no chance to sort out these problems. Even if it succeeds, i will probably need a configure tool as well, since i have no idea how ndk-build manages to install SDL2 without configure scripts.
Compiling the SDL sources with the project together is the only working - but ugly solution. I would like to deploy the necessary lib and header files by make install.
I hope the solution is something really easy and obvious thing that i just didn't think about...
This issue has been fixed at http://hg.libsdl.org/SDL/rev/4e57cfd9fca8 and expected for the 2.0.4 release. Note there are newer revisions with some related fixes about defines.

Resources