Using System.getProperty(“os.arch”) to check if it

2019-05-01 07:13发布

问题:

I'm having the following issue with RenderScript on some old 4.2.2- devices (galaxy s3 mini, galaxy ace 3, galaxy fresh, etc.) - Android - Renderscript Support Library - Error loading RS jni library.

I want to implement the suggested solution but what exactly will be the value returned by

System.getProperty("os.arch");

for armeabi devices (not armeabi-v7 devices).

Thanks.

回答1:

The method System.getProperty is a generic method of Java, here you can find the documentation.

On Linux it returns the same value obtained from the command uname -m. The possible values are for example armv5t, armv5te, armv5tej, armv5tejl, armv6, armv7, armv7l, i686 and many more. There isn't an exact value for the armeabi devices because it slightly differs from cpu to cpu.

There is a better alternative to System.getProperty and it is the field Build.CPU_ABI (or Build.SUPPORTED_ABIS in newer devices):

String abi = null;

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    abi = Build.CPU_ABI;
} else {
    abi = Build.SUPPORTED_ABIS[0];
}

The possible values are armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips, mips64.

As you can see the number of possible results is much lower than System.getProperty, and you can check directly for armeabi.