Code Droid
Code Droid

Reputation: 10472

Android Detecting Atom Processor at runtime to select right NDK compiled library?

Many Android Devices will be using Atom processor in future. This means that when creating an app that could be deployed to on an Atom processor device, it will be necessary to include a native library for atom as well as x86 processor. So my question is how can one detect which processor is on the device before deciding which native library to load? What is the best way to select which library to load?

Upvotes: 0

Views: 831

Answers (1)

Mārtiņš Možeiko
Mārtiņš Možeiko

Reputation: 12927

You don't need to dected anything manually. Just build your library targeted x86 by specifiying correct APP_ABI in Application.mk file (read the docs\Application-mk.html file from ndk distribution):

APP_ABI := armeabi armeabi-v7a x86

Using that you will get three libraries under libs folder. Android will automatically pick correct one during runtime.

If you need to detect at runtime, you can use cpufeatures library that is distributed with NDK. It provides following function:

typedef enum {
    ANDROID_CPU_FAMILY_UNKNOWN = 0,
    ANDROID_CPU_FAMILY_ARM,
    ANDROID_CPU_FAMILY_X86,
    ANDROID_CPU_FAMILY_MAX  /* do not remove */
} AndroidCpuFamily;

/* Return family of the device's CPU */
extern AndroidCpuFamily   android_getCpuFamily(void);

If you need to perform same functionality in Java side you should read /proc/cpuinfo file and analyze its contents.

Upvotes: 2

Related Questions