29

It may be a duplicated question, but i'm unable to find it. I wonder how we can get what's the ABI of a phone, using code. I know that there's different Interface that may dictated in gradle file. But the problem is how i can get exactly the ABI of a certain device, so that i can manually copy it to system/lib/ folder using SuperSU. Thank you.

android.productFlavors {
        // for detailed abiFilter descriptions, refer to "Supported ABIs" @
        // https://developer.android.com/ndk/guides/abis.html#sa
        create("arm") {
            ndk.abiFilters.add("armeabi")
        }
        create("arm7") {
            ndk.abiFilters.add("armeabi-v7a")
        }
        create("arm8") {
            ndk.abiFilters.add("arm64-v8a")
        }
        create("x86") {
            ndk.abiFilters.add("x86")
        }
        create("x86-64") {
            ndk.abiFilters.add("x86_64")
        }
        create("mips") {
            ndk.abiFilters.add("mips")
        }
        create("mips-64") {
            ndk.abiFilters.add("mips64")
        }
        // To include all cpu architectures, leaves abiFilters empty
        create("all")
    }
Cuong Phan
  • 311
  • 1
  • 4
  • 8

4 Answers4

37

There are two ways that you can do this. One is deprecated but still works while the other requires the phone to be running Android 5.0 or greater.

The Deprecated Way

If you want to support all current phones you can use:

import android.os.Build;
String ABI = Build.CPU_ABI;

The Newer Way

The newer way actually will provide a list of all supported ABIs, the first index being the most preferred ABI to use (API Reference):

import android.os.Build;
String ABI = Build.SUPPORTED_ABIS[0];

Both ways have been tested to work on Android 5.1.1, they will return one of the following:

  • armeabi
  • armeabi-v7a
  • armeabi-v7a-hard
  • arm64-v8a
  • x86
  • x86_64
  • mips
  • mips64

Future ABIs should be listed here: https://developer.android.com/ndk/guides/abis.html#sa

elliereiselt
  • 516
  • 5
  • 9
26

Look up here:

enter image description here

not there?

Through ADB shell:

adb shell getprop ro.product.cpu.abi

Though Java code:

import android.os.Build;
Log.d("myabi", Build.SUPPORTED_ABIS[0]);
ishandutta2007
  • 16,676
  • 16
  • 93
  • 129
7

TLDR: Here is a combined version of bandoncontortion's solution, which works on all Android versions:

public String getAbi() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        // on newer Android versions, we'll return only the most important Abi version
        return Build.SUPPORTED_ABIS[0];
    }
    else {
        // on pre-Lollip versions, we got only one Abi
        return Build.CPU_ABI;
    }
}
Johnson_145
  • 1,994
  • 1
  • 17
  • 26
0

If you are interested in the ABI that current process/runtime is running under (e.g. an arm64/x86_64 processor can run a 32-bit app_process to save memory), you should use CPU_ABI, CPU_ABI2 as it will return the correct result.

If you do not want to use deprecated API but is ok with using internal (core platform) APIs, you can also use reflection and access dalvik.runtime.VMRuntime.getRuntime().is64Bit() (or getCurrentInstructionSet) and filter SUPPORTED_ABIS by yourself. See the source code for static constructor of android.os.Build for more information.

Mygod
  • 2,077
  • 1
  • 19
  • 43