Skip to main content

Android Native CPU ABI


Every piece of native code generated with the Android NDK matches a given ABI(Application Binary Interface). ABI defines exactly how machine code is expected to interact with the system at runtime.
ABI describes following things at runtime:
  • the CPU instruction set that the machine code should use
  • the endianness of memory stores and loads at runtime
  • the format of executable binaries (shared libraries, programs, etc...) and what type of content is allowed/supported in them.
  • various conventions used to pass data between your code and the system (e.g. how registers and/or the stack are used when functions are called, alignment constraints, etc...)
  • alignment and size constraints for enum types, structure fields and arrays.
  • the list of function symbols available to your machine code at runtime, generally from a very specific selected set of libraries.
Android Supported ABIs:

1.armeabi: This ABI is for ARM-based CPUs that support at least the ARMv5TE instruction set.It is the ARM Architecture.
2.armeabi-v7a: Thi is an extension of armeabi for ARM-based CPUs which has included a few cpu instruction.
3.X86: This is the name of an ABI for CPUs supporting the instruction set which targets Pentium Pro instruction set.Generated code is optimized for Atom CPU
4.mips: This is the name of an ABI for MIPS-based CPUs that support at least the MIPS32r1 instruction set. It includes MIPS32 revision 1 ISA, Little-Endian, O32, Hard-Float, no DSP application specific extensions.

By default, The Android NDK generats machine code for 'armeabi' ABI.However we can define APP_ABI in Application.mk file to generate ABI for compatible machine code. For more this.

When we install apk, the package manager service will scan the .apk and look for any shared library form:

lib/<primary-abi>/lib<name>.so

If anyone is found, then it's copy under $APPDIR/lib/lib<name>.so, where $APPDIR corresponds to the application's specific data directory.
If none is found, and a secondary ABI is defined, the service will then scan for shared libraries of the form: 
lib/<secondary-abi>/lib<name>.so
If anything is found, then it's copy under $APPDIR/lib/lib<name>.so

This automatically extract the best machine code for the target device from the package at installation time.

Comments

Popular posts from this blog

Android O New Features Overview

This post assumes, you are an experienced developer who wants to get started with the latest version of Android. Android O is not a huge update to the OS and application framework like M but it still has many useful features for both developer and an user. Android O has focus on below areas. Notification redesigned Picture-in-Picture(PIP)  Visual adaption for different devices  Battery life improved Setting app reorganized Notification redesigned: Android O notification changes includes more easy and manageable way to manager your notification behavior and settings. It includes: Notification Channel: Notification channel allows you to create user customizable channel for each type of notification you wanna display. A single application can have multiple channel, a separate channel for each type of notification you wanna display. Having said this, you can create s separate channel for audio & image notification. User can disable specific notification channel instead

Java 8 Overview

Java 1.8 has introduced major features for the Java developers. It includes various upgrade to the Java programming, JVM, Tools and libraries. The main purpose of Java 1.8 release has been to simplify programming, utilize functional programming benefits and enable parallel programming/processing in Java programming language. Java 1.8 feature  Lambda(->) Expression Functional interfaces Default Methods in interface static method inside interface     Pre defined functional interfaces Predicate Function Consumer ::(Method reference and constructor reference by using double colon(::)operator) Stream API Date & Time API

Overview of how to develop native code with Android NDK:

  Create a jni directory and place native source code under $PROJECT/jni/... Create Android.mk directory and place it under $PROJECT/jni/... to describe source code to the NDK build system. Create Application.mk and place it under $PROJECT/jni/...to describe project in more details to the NDK build system.It is an optional. Finally need to build native source code by running '$NDK/ndk-build' from project directory or it's sub-directory. Android.mk An Android.mk file is a small build script that we write to describe sources to the NDK build system. It's syntax is like this... LOCAL_PATH:=$(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE:=hello-jni LOCAL_SRC_FILES:=hello-jni.c include $(BUILD_SHARED_LIBRARY) NDK groups your sources into "modules", where each module can be one of the following: Static library Shared library We can write several module in a single 'Android.mk' or can write seve