下面列出了android.os.Build#SUPPORTED_ABIS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Helper method to create a salt for the crash identifier.
*
* @param context the context to use. Usually your Activity object.
*/
@SuppressLint("InlinedApi")
@SuppressWarnings("deprecation")
private static String createSalt(Context context) {
String abiString;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
abiString = Build.SUPPORTED_ABIS[0];
} else {
abiString = Build.CPU_ABI;
}
String fingerprint = "HA" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10) +
(abiString.length() % 10) + (Build.PRODUCT.length() % 10);
String serial = "";
try {
serial = android.os.Build.class.getField("SERIAL").get(null).toString();
} catch (Throwable t) {
}
return fingerprint + ":" + serial;
}
private static String checkAbiArgument(String abi) {
if (TextUtils.isEmpty(abi)) {
throw new IllegalArgumentException("Missing ABI argument");
}
if ("-".equals(abi)) {
return abi;
}
final String[] supportedAbis = Build.SUPPORTED_ABIS;
for (String supportedAbi : supportedAbis) {
if (supportedAbi.equals(abi)) {
return abi;
}
}
throw new IllegalArgumentException("ABI " + abi + " not supported on this device");
}
private static ArrayList<String> getSupportedAbis() {
ArrayList<String> abiList = new ArrayList<>();
String defaultAbi = (String) RefInvoker.getField(FairyGlobal.getHostApplication().getApplicationInfo(), ApplicationInfo.class, "primaryCpuAbi");
abiList.add(defaultAbi);
if (Build.VERSION.SDK_INT >= 21) {
String[] abis = Build.SUPPORTED_ABIS;
if (abis != null) {
for (String abi: abis) {
abiList.add(abi);
}
}
} else {
abiList.add(Build.CPU_ABI);
abiList.add(Build.CPU_ABI2);
abiList.add("armeabi");
}
return abiList;
}
private boolean isCPUArchitectureSupported(String alias) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
for (String supportedAlias : Build.SUPPORTED_ABIS) {
if (supportedAlias.equals(alias))
return true;
}
return false;
} else {
return Build.CPU_ABI.equals(alias);
}
}
public static List<String> getAllInstructionSets() {
final String[] allAbis = Build.SUPPORTED_ABIS;
final List<String> allInstructionSets = new ArrayList<String>(allAbis.length);
for (String abi : allAbis) {
final String instructionSet = VMRuntime.getInstructionSet(abi);
if (!allInstructionSets.contains(instructionSet)) {
allInstructionSets.add(instructionSet);
}
}
return allInstructionSets;
}
/**
* Verifies that the given string {@code isa} is a valid supported isa on
* the running device.
*/
public static boolean checkISA(String isa) {
for (String abi : Build.SUPPORTED_ABIS) {
if (VMRuntime.getInstructionSet(abi).equals(isa)) {
return true;
}
}
return false;
}
private static void assertValidInstructionSet(String instructionSet)
throws InstallerException {
for (String abi : Build.SUPPORTED_ABIS) {
if (VMRuntime.getInstructionSet(abi).equals(instructionSet)) {
return;
}
}
throw new InstallerException("Invalid instruction set: " + instructionSet);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static String[] getABIList21() {
final String[] abis = Build.SUPPORTED_ABIS;
if (abis == null || abis.length == 0)
return getABIList();
return abis;
}
public static String[] getABIs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_ABIS;
} else {
if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
return new String[]{Build.CPU_ABI};
}
}
/**
* 获取支持的指令集 如: [arm64-v8a, armeabi-v7a, armeabi]
* @return 支持的指令集
*/
public static String[] getABIs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_ABIS;
} else {
if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
return new String[]{Build.CPU_ABI};
}
}
/**
* Return an ordered list of ABIs supported by this device. The most preferred ABI is the first
* element in the list.
*
* @return an ordered list of ABIs supported by this device
*/
public static String[] getABIs() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return Build.SUPPORTED_ABIS;
} else {
if (!TextUtils.isEmpty(Build.CPU_ABI2)) {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
return new String[]{Build.CPU_ABI};
}
}
/**
* 获取设备支持的abi列表
*/
public static String[] getSupportAbis() {
String[] cpuAbis;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cpuAbis = Build.SUPPORTED_ABIS;
} else {
cpuAbis = new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
// avoid NPE
if (cpuAbis == null) {
cpuAbis = new String[0];
}
return cpuAbis;
}
@DoNotOptimize
public static String[] getSupportedAbis() {
String[] supportedAbis = Build.SUPPORTED_ABIS;
TreeSet<String> allowedAbis = new TreeSet<>();
try {
// Some devices report both 64-bit and 32-bit ABIs but *actually* run
// the process in 32-bit mode.
//
// Determine the current process bitness and use that to filter
// out incompatible ABIs from SUPPORTED_ABIS.
if (is64Bit()) {
allowedAbis.add(MinElf.ISA.AARCH64.toString());
allowedAbis.add(MinElf.ISA.X86_64.toString());
} else {
allowedAbis.add(MinElf.ISA.ARM.toString());
allowedAbis.add(MinElf.ISA.X86.toString());
}
} catch (ErrnoException e) {
Log.e(
TAG,
String.format(
"Could not read /proc/self/exe. Falling back to default ABI list: %s. errno: %d Err msg: %s",
Arrays.toString(supportedAbis), e.errno, e.getMessage()));
return Build.SUPPORTED_ABIS;
}
// Filter out the incompatible ABIs from the list of supported ABIs,
// retaining the original order.
ArrayList<String> compatibleSupportedAbis = new ArrayList<>();
for (String abi : supportedAbis) {
if (allowedAbis.contains(abi)) {
compatibleSupportedAbis.add(abi);
}
}
String[] finalAbis = new String[compatibleSupportedAbis.size()];
finalAbis = compatibleSupportedAbis.toArray(finalAbis);
return finalAbis;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static String[] getSupportedAbis() {
return Build.SUPPORTED_ABIS;
}
private void savePhoneInfo(PrintWriter pw) throws Exception {
// 应用的版本名称和版本号
PackageManager pm = mContext.getPackageManager();
PackageInfo pi = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_ACTIVITIES);
pw.println("Device info:");
pw.print("App Version Name: ");
pw.println(pi.versionName);
pw.print("App Version Code: ");
pw.println(pi.versionCode);
// android版本号
pw.print("SDK: ");
pw.println(Build.VERSION.SDK_INT);
pw.print("OS Version: ");
pw.println(Build.VERSION.RELEASE);
// 手机制造商
pw.print("Vendor: ");
pw.println(Build.MANUFACTURER);
// 手机型号
pw.print("Model: ");
pw.println(Build.MODEL);
// cpu架构
pw.print("CPU ABI: ");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//noinspection SpellCheckingInspection
final String[] abis = Build.SUPPORTED_ABIS;
if (null != abis && abis.length > 0) {
StringBuilder sb = new StringBuilder();
for (String abi : abis) {
sb.append(abi).append(" ");
}
pw.println(sb.toString());
}
} else {
//noinspection deprecation
pw.println(Build.CPU_ABI);
}
pw.println("------------------------------------");
pw.println();
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String[] getSupportedABIsLollipop() {
return Build.SUPPORTED_ABIS;
}
@Override
protected void initView() {
super.initView();
StringBuilder sb = new StringBuilder();
sb.append("\n\n");
sb.append("===================\n");
sb.append(Build.MANUFACTURER).append(" ").append(Build.MODEL).append("\n");
sb.append("===================\n\n");
sb.append("===== CPU =====\n\n");
String str;
try {
FileReader fr = new FileReader("/proc/cpuinfo");
BufferedReader br = new BufferedReader(fr);
while ((str = br.readLine()) != null) {
sb.append(str).append("\n");
}
br.close();
} catch (IOException e) {
//ignore
}
sb.append("\n");
sb.append("===== ABI =====\n\n");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
String[] abis = Build.SUPPORTED_ABIS;
for (int i = 0; i < abis.length; i++) {
sb.append("CPU ABI").append(i).append(":").append(abis[i]).append("\n");
}
}
sb.append("\n");
sb.append("===== Codecs =====\n\n");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
int numCodecs = MediaCodecList.getCodecCount();
for (int i = 0; i < numCodecs; i++) {
MediaCodecInfo codecInfo = MediaCodecList.getCodecInfoAt(i);
String[] types = codecInfo.getSupportedTypes();
for (String type : types) {
sb.append(type).append("\n");
sb.append(codecInfo.getName()).append("\n\n");
}
}
}
mCpuInfo.setText(sb.toString());
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static String[] getSupportedABIsLollipop() {
return Build.SUPPORTED_ABIS;
}
public static String unzipLibraryFile(String zipFile, String targetDir) {
StringBuilder builder = new StringBuilder();
String cpu = '/' + Build.SUPPORTED_ABIS[0] + '/';
int buffer = 4096; // 这里缓冲区我们使用4KB,
String strEntry; // 保存每个zip的条目名称
try (FileInputStream fis = new FileInputStream(zipFile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis))) {
ZipEntry entry; // 每个zip条目的实例
while ((entry = zis.getNextEntry()) != null) {
int count;
byte[] data = new byte[buffer];
strEntry = entry.getName();
if (!strEntry.endsWith(".so") || !strEntry.contains(cpu)) {
continue;
}
File entryFile = new File(targetDir + strEntry);
File entryDir = new File(entryFile.getParent());
if (!entryDir.exists()) {
entryDir.mkdirs();
}
try (FileOutputStream fos = new FileOutputStream(entryFile);
BufferedOutputStream dest = new BufferedOutputStream(fos, buffer)) {
while ((count = zis.read(data, 0, buffer)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
builder.append(entryDir.getAbsolutePath());
builder.append(",");
}
}
builder.deleteCharAt(builder.length() - 1);
return builder.toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String[] getAbis() {
return Build.SUPPORTED_ABIS;
}