作为我的应用程序的一部分,我正在使用NDK,并且想知道是否值得将x86和mips二进制文件与标准ARM二进制文件一起捆绑。
我认为最好的方法是跟踪用户实际拥有的内容,是否有API调用以获取处理器架构,以便将其传回我的Google分析实例?
由于
答案 0 :(得分:60)
实际上,您可以在不需要反思的情况下获得架构:
String arch = System.getProperty("os.arch");
从我的测试中,它返回armv71
和i686
。
编辑:
在MIPS架构上,它返回'mips'或'mips64'
在64位ARM / Intel上,它分别返回'arch64'或'x86_64'。
答案 1 :(得分: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");
答案 2 :(得分:10)
您可以使用adb命令
adb shell getprop ro.product.cpu.abi adb shell getprop ro.product.cpu.abi2
并参考[site]:How to know a process of an app is 32-bit or 64-bit programmatically in Android lollipop?
如果您正在寻找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));
答案 3 :(得分:8)
答案 4 :(得分:6)
您要查找的值是
ro.product.cpu.abi
和
ro.product.cpu.abi2
这些可以使用内部api SystemProperties.get获得所以你必须在SystemProperties上使用Reflection。
如果您不太热衷于反射,可以使用函数getSystemProperty。检查here
答案 5 :(得分:6)
尝试此命令:
adb shell getprop ro.product.cpu.abi
它告诉cpu是ARM还是Intel,64或86_64
答案 6 :(得分:3)
matches
使用不同的方法并有解释:
termux-app
答案 7 :(得分:2)
我的代码看起来像这样
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;
}