API call to get processor architecture

后端 未结 8 2028
野的像风
野的像风 2020-12-05 01:59

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 woul

相关标签:
8条回答
  • 2020-12-05 03:02

    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));
    }
    

    From: https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/TermuxInstaller.java

    0 讨论(0)
  • 2020-12-05 03:05

    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 'aarch64' or 'x86_64' respectively.

    0 讨论(0)
提交回复
热议问题