Android NDK - armeabi vs armeabi-v7a folder - android

There are some questions like mine.
why I need put *.so files in both armeabi-v7a and armeabi folders?
Why armeabi-v7a conflicts with armeabi of another module?
Why use armeabi-v7a code over armeabi code?
But I am not clear yet. I have many .so files for armeabi and armeabi-v7a.
// binaries
armeabi/libarmeabi-v7a-module1.so
armeabi/libarmeabi-v7a-module2.so
// Application.mk file
APP_ABI := armeabi
APP_PLATFORM := android-19
APP_STL := gnustl_shared
// Android.mk file
include $(CLEAR_VARS)
LOCAL_MODULE := module1
LOCAL_SRC_FILES := $(LOCAL_PATH)/armeabi/libarmeabi-v7a-module1.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := module2
LOCAL_SRC_FILES := $(LOCAL_PATH)/armeabi/libarmeabi-v7a-module2.so
include $(PREBUILT_SHARED_LIBRARY)
This settings work fine on armeabi-v7a devices.
But my app crashes when I set armeabi-v7a abi in Application.mk file. Crash message is below:
A/libc:
/Volumes/Android/buildbot/src/android/ndk-release-r16/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:73:
abort_message: assertion "Pure virtual function called!" failed

armeabi is for up to ARM architecture version V6, while armeabi-v7a specifies architecture version version 7, with the suffix A for application processors such as Cortex-A15.
V7 has quite different pipleline behavior plus handful of nice and compiler friendly instructions compare to V6, such as ubfx.
e.g.:
a = (b>>5) & 0x3ff;
// armv6:
lsl a, b, #17
lsr a, a, #22
// armv7:
ubfx a, b, #5, #10 // unsigned bit-field extract from bit 5, ten bits long
As you can see above, you need two instructions with dependency on V6, while V7 only requires one single instruction which is remarkable considering how compiler friendly these new instructions are unlike the DSP-like ones new on V6 which mostly never got utilized by compilers.
And since the compiler has to decide which instructions to use and how to schedule them, the generated machine codes are different, so are the .so files, so are the folders.
I'd exclude armeabi altogether by abiFilters since there are virtually no Android phone with less than V7.

armeabi is armv5. It's no longer supported. You can just pretend it doesn't exist.
armeabi-v7a is armv7. This (along with at least arm64-v8a) is what you should be building for.
The fact that your app is crashing is a different problem, and the error message tells you what's happening: there's a pure virtual function that's being called. Some child class isn't implementing a virtual function that it needs to implement.
There's also a third problem. Your APP_STL is gnustl_shared, but the error message indicates that one of your libraries was built with libc++. These two are incompatible. You must use the same STL for the entire app (and since you use more than one shared library, it must be the shared variant).

Related

Android NDK - Build Trying to Link Non-Existent Prebuilt Library

I just inherited some legacy code, which is currently able to build on our build server and I am trying to get it run on Android Studio, and it is having issue where the build fails because it is trying to point to a (non-existent) MIPS version of a prebuilt library.
I get the following error:
libraryname: LOCAL_SRC_FILES points to a missing file.
Check that .../libraryname/mips/libraryname.so exists.
This file does not exist, but I don't understand why the build tool is looking for it.
My Application.mk file has this entry:
APP_ABI := armeabi armeabi-v7a x86 x86_64
My Android.mk file has this entry (library name generalized):
include $(CLEAR_VARS)
LIBRARY_NAME_PATH := libraryname/$(TARGET_ARCH_ABI)
LOCAL_MODULE := modulename
LOCAL_SRC_FILES := $(LIBRARY_NAME_PATH)/mobulename.so
include $(PREBUILT_SHARED_LIBRARY)
Confusingly, TARGET_ARCH_ABI doesn't seem to be set anywhere, so I'm not really sure what is happening there.
Other notes, when I build this from the command line with NDK-build, it works just fine, only creating the 4 architectures requested.
As I mentioned, there should be no need for any code changes, since this exact code is successfully building on our build server. I am assuming I just have something configured wrong.
Traditionally, NDK used APP_ABIS setting (usually defined in Application.mk file) to choose the list of architectures to build. NDK supports today ARM, Intel and MIPS processors in 32 and 64-bit modes.
The gradle plugin used by Android Studio ignores APP_ABIS and you must define abiFilters in your build.gradle to specify the architectures to build.
This is especially important when your project uses prebuilt third-party libraries, because quite often, as in your case, these libraries are available only to a subset of all possible architectures.
ndk-build invokes the Android.mk script in a loop, each time setting $(TARGET_ARCH_ABI) to chosen architecture, one of arm64-v8a
x86_64
mips64
armeabi-v7a
armeabi
x86
mips

How to build libvpx for android arm as well as x86?

I have been building our Android app for armeabi-v7a. Now, to add support for x86 as well, I extended Application.mk:
APP_ABI := armeabi-v7a x86
The first problem I am running into is that libvpx can be configured either for arm or for x86:
$ ./libvpx/configure --target=armv7-android-gcc ...
OR
$ ./libvpx/configure --target=x86-android-gcc
Wondering how to deal with multiple platforms. Does one create two different libvpx directories for two platforms and use if-then-else logic in Android.mk to pick the right directory? Is there a better way?
Yes, pretty much. If you store the build product (as produced by make install) in parallel directories named according to the android ABIs, you can simplify using it from an Android.mk file like this:
include $(CLEAR_VARS)
LOCAL_MODULE := libvpx
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libvpx/$(TARGET_ARCH_ABI)/include
LOCAL_SRC_FILES := libvpx/$(TARGET_ARCH_ABI)/lib/libvpx.a
include $(PREBUILT_STATIC_LIBRARY)
Since the public headers probably are (should be) free of anything arch specific, you should also be able to share one copy of them instead of having one copy per arch.

Compiling native code for different architectures(to reduce size)

I have a native library that I am using in my Android app. It has 4 .so files(armeabi,armeabi-v7a, mips, x86) in the libs folder. Now, the thing is, each .so file is close to 10 mb. This is making the total apk size around 40 mb. I want to include just one .so file for the relevant architecture and not include the other .so files at all .
This is my application.mk :
# When we build for google play, we build 4 different apk's, each with
# a different version, by uncommenting one of the pairs of lines below.
# Suppose our base version is X:
# Version X: armeabi
#APP_PLATFORM=android-8
#APP_ABI := armeabi
# Version X+1: armeabi-v7a (Much faster due to the availability of hardware
# FP, but cannot be run in the emulator).
APP_PLATFORM=android-8
APP_ABI := armeabi
# Version X+2: x86 (Requires android-9, so a change needs to be made in
# AndroidManifest.xml too)
#APP_PLATFORM=android-9
#APP_ABI := x86
# Version X+3: mips (Requires android-9, so a change needs to be made in
# AndroidManifest.xml too)
#APP_PLATFORM=android-9
#APP_ABI := mips
ifdef NDK_PROFILER
# The profiler doesn't seem to receive ticks when run on release code.
# Accordingly, we need to build as debug - but this turns optimisations
# off, which is less than ideal.
APP_OPTIM := debug
APP_CFLAGS := -O2
else
APP_OPTIM := release
endif
ifdef V8_BUILD
APP_STL := stlport_static
endif
ifdef MEMENTO
APP_CFLAGS += -DMEMENTO -DMEMENTO_LEAKONLY
endif
# If the ndk is r8b then workaround bug by uncommenting the following line
#NDK_TOOLCHAIN_VERSION=4.4.3
# If the ndk is newer than r8c, try using clang.
#NDK_TOOLCHAIN_VERSION=clang3.1
I am new at ndk, so I might be going wrong somewhere, but I have a hunch that this Application.mk doesnt get executed at all. How do I get this to run? Because even though APP_ABI := armeabi is there, I get ALL the .so files in my compiled apk(opened using winrar).
My question is, How do I tell the .mk to build for specific architectures? And how are my changes going to be reflected? I just click on RUN (the green triangle in eclipse).
PS:
This is a 3rd party library that I have downloaded, so I dont really know the code inside

NDK - Build ARMv5/ARMv7 shared libraries from static ones

I have two static libraries that I built from a specified project.
ARMv5 / myLib.a
ARMv7 / myLib.a
Now, I want to use those libraries and build two shared library for ARMv5 and ARMV7 platforms.
Is there a way to specify the fact that I want to use two versions of my static library ?
For now, I'm doing a bad trick in my ANT Script which just consists in:
Copy the static ARMv5 library.
Build the shared library (ARMv5).
Delete ARMv5 static lib and copy ARMv7 version.
Build again a shared library (ARMv7).
I know there is
"APP_ABI := armeabi armeabi-v7a"
but how to tell him that I want to build from two separated static lib and not just from one?
Regards,
Might not be the best approach but, you can try using if else statements in your Android.mk and check for APP_ABI values and use the corresponding libraries.
ifeq ($(APP_ABI), armeabi-v7a)
LOCAL_SRC_FILES := ARMv7/myLib.a
else
LOCAL_SRC_FILES := ARMv5/myLib.a
endif
Or use LOCAL_STATIC_LIBRARIES in case you directly link them. Of course, your Application.mk should include the line that you stated:
APP_ABI := armeabi armeabi-v7a

Android different ABI compatibility

For example let build static library called "some".
LibSome Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := some
LOCAL_SRC_FILES := some.c
include $(BUILD_STATIC_LIBRARY)
LibSome Application.mk
APP_MODULES := somelib
APP_OPTIM := release
And get armeabi version of our lib in LibSome/obj/local/armeabi/libsome.a
So now we need to drop our lib to mainProject jni folder and use it
MainProject Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := some
LOCAL_SRC_FILES := libsome.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/some
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := mainProject
LOCAL_SRC_FILES := mainProject.c
LOCAL_STATIC_LIBRARIES := some
include $(BUILD_SHARED_LIBRARY)
But there are different ABI like mips, x86, armeabi-v7a and we can get all supported versions of somelib by current ndk just adding
APP_ABI:= all
to SomeLib Application.mk, so we get LibSome/obj/local/armeabi-v7a/libsome.a, LibSome/obj/local/x86/libsome.a etc
Main question - do i really need to think about different ABI and create project for every supported ABI like mainProjectx86, mainProjectMIPS with different ABI builded libs?
And secondary questions are:
If i build project for armeabi ABI (default) how many devices will be cut out? Can armeabi-v7a ABI device run armeabi ABI app?
If there is a way to have one project with different set of pre-builded libs? So if you build mainProject for ameabi-v7a it will use armeabi-v7a libs and so on?
Ok, So firstly, if your are using standard C calls without any architecture specific assembly language embedded, it's safe to use APP_ABI := all. This will allow gcc to create libs for all architectures and your app will have no problems running.
if however, you are using something specific to ARM, e.g. NEON architecture calls for optimized math or Intel x86 SSE3 calls for optimized math, then APP_ABI := all may not be a good idea. This might lead to runtime errors which are very difficult to understand. Then you may be required to maintain different projects for different architectures.
Coming to secondary question:
1. Most of the latest devices are armeabi-v7a, so only the older devices will be cut out. Also parallel x86 and MIPS devices will also be cut out. But since most flagships like Samsung, HTC and Sony ship with ARM, your app will be reachable to a big percentage.
Not much clue on the second one for now.
All ARM devices run armeabi. The older and slower ones use ARMv6, and cannot use armeabi-v7a libraries. But it is possible to mix armeabi and ameabi-v7a shared libraries in one application. This may come useful if you have a huge native library which you don't want to ship in two copies, and also some very specific function that is a performance bottleneck which may be vastly accelerated with NEON optimizations. So, in the end you have the following structure in your project folder:
libs/
armeabi/
libhuge.so
libslow.so
armeabi-v7a/
libfast.so

Categories

Resources