Ljd*_*son 34 android cpu-architecture
作为我的应用程序的一部分,我正在使用NDK,并想知道是否值得将x86和mips二进制文件与标准ARM二进制文件一起捆绑.
我认为最好的方法是跟踪用户实际拥有的内容,是否有API调用以获取处理器架构,以便将其传回我的Google分析实例?
谢谢
3c7*_*c71 66
实际上,您可以在不需要反射的情况下获得架构:
String arch = System.getProperty("os.arch");
Run Code Online (Sandbox Code Playgroud)
从我的测试中它返回armv71并且i686.
编辑:
在MIPS架构上,它返回'mips'或'mips64'
在64位ARM/Intel上,它分别返回'arch64'或'x86_64'.
she*_*hem 16
你也可以使用android SDK,看一下这个Build类:
/** 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");
Run Code Online (Sandbox Code Playgroud)
tom*_*bee 10
您可以使用adb命令
adb shell getprop ro.product.cpu.abi adb shell getprop ro.product.cpu.abi2
并参考[site]:如何在Android棒棒糖中以编程方式知道应用程序的进程是32位还是64位?
如果您正在寻找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));
Run Code Online (Sandbox Code Playgroud)
试试这个命令:
adb shell getprop ro.product.cpu.abi
Run Code Online (Sandbox Code Playgroud)
它告诉cpu是ARM还是Intel,64或86_64
termux-app使用不同的方法并有解释:
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));
}
Run Code Online (Sandbox Code Playgroud)
来自: https: //github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/TermuxInstaller.java
| 归档时间: |
|
| 查看次数: |
28683 次 |
| 最近记录: |