As part of my app I'm using the NDK and was wondering if it's worth bundling x86 and mips binaries alongside the standard ARM binaries.
I figured the best way would be to track what my users actually have, is there an API call to grab the processor architecture so I can pass this back to my Google analytics instance?
Thanks
Actually, you can get the architecture without the need for reflexion at all:
String arch = System.getProperty("os.arch");
From my tests it returned armv71 and i686.
EDIT:
On MIPS architecture, it either returns 'mips' or 'mips64'
On 64 bit ARM/Intel, it returns 'arch64' or 'x86_64' respectively.
You can also use android SDK, take a look on the Build class:
/** The name of the instruction set (CPU type + ABI convention) of native code. */
public static final String CPU_ABI = getString("ro.product.cpu.abi");
/** The name of the second instruction set (CPU type + ABI convention) of native code. */
public static final String CPU_ABI2 = getString("ro.product.cpu.abi2");
You can use adb command
adb shell getprop ro.product.cpu.abi adb shell getprop ro.product.cpu.abi2
and refer the [site]: How to know a process of an app is 32-bit or 64-bit programmatically in Android lollipop?
If you're looking for the Lollipop API
import android.os.Build;
Log.i(TAG, "CPU_ABI : " + Build.CPU_ABI);
Log.i(TAG, "CPU_ABI2 : " + Build.CPU_ABI2);
Log.i(TAG, "OS.ARCH : " + System.getProperty("os.arch"));
Log.i(TAG, "SUPPORTED_ABIS : " + Arrays.toString(Build.SUPPORTED_ABIS));
Log.i(TAG, "SUPPORTED_32_BIT_ABIS : " + Arrays.toString(Build.SUPPORTED_32_BIT_ABIS));
Log.i(TAG, "SUPPORTED_64_BIT_ABIS : " + Arrays.toString(Build.SUPPORTED_64_BIT_ABIS));
The values you are looking for are
ro.product.cpu.abi
and
ro.product.cpu.abi2
These can be got using internal api SystemProperties.get So you will have to use Reflection on SystemProperties.
You could use the function getSystemProperty if you are not too keen on reflection. Check it here
Try this command:
adb shell getprop ro.product.cpu.abi
It tells whether cpu is ARM or Intel , 64 or 86_64
termux-app uses a different approach and has an explanation:
private static String determineTermuxArchName() {
// Note that we cannot use System.getProperty("os.arch") since that may give e.g. "aarch64"
// while a 64-bit runtime may not be installed (like on the Samsung Galaxy S5 Neo).
// Instead we search through the supported abi:s on the device, see:
// http://developer.android.com/ndk/guides/abis.html
// Note that we search for abi:s in preferred order (the ordering of the
// Build.SUPPORTED_ABIS list) to avoid e.g. installing arm on an x86 system where arm
// emulation is available.
for (String androidArch : Build.SUPPORTED_ABIS) {
switch (androidArch) {
case "arm64-v8a": return "aarch64";
case "armeabi-v7a": return "arm";
case "x86_64": return "x86_64";
case "x86": return "i686";
}
}
throw new RuntimeException("Unable to determine arch from Build.SUPPORTED_ABIS = " +
Arrays.toString(Build.SUPPORTED_ABIS));
}
My Code looks like this
private String cpuinfo()
{
String arch = System.getProperty("os.arch");
String arc = arch.substring(0, 3).toUpperCase();
String rarc="";
if (arc.equals("ARM")) {
rarc= "This is ARM";
}else if (arc.equals("MIP")){
rarc= "This is MIPS";
}else if (arc.equals("X86")){
rarc= "This is X86";
}
return rarc;
}
来源:https://stackoverflow.com/questions/11989629/api-call-to-get-processor-architecture