CPU 体系结构CPU Architectures

Xamarin 支持多个 CPU 体系结构,包括32位和64位设备。本文介绍如何将应用定位到一个或多个支持 Android 的 CPU 体系结构。Xamarin.Android supports several CPU architectures, including 32-bit and 64-bit devices. This article explains how to target an app to one or more Android-supported CPU architectures.

CPU 体系结构概述CPU Architectures Overview

准备要发布的应用时,必须指定应用支持的平台 CPU 体系结构。When you prepare your app for release, you must specify which platform CPU architectures your app supports. 单个 APK 可包含计算机代码,以支持多个不同的体系结构。A single APK can contain machine code to support multiple, different architectures. 特定于体系结构的代码的每个集合都与应用程序二进制接口(ABI)相关联。Each collection of architecture-specific code is associated with an Application Binary Interface (ABI). 每个 ABI 定义在运行时此机器代码如何与 Android 进行交互。Each ABI defines how this machine code is expected to interact with Android at run time. 有关其工作原理的详细信息,请参阅多核心设备 & XamarinFor more information about how this works, see Multi-Core Devices & Xamarin.Android.

如何指定支持的体系结构How to Specify Supported Architectures

通常,当您的应用程序配置为发布时,您可以明确地选择一个体系结构(或体系结构)。Typically, you explicitly select an architecture (or architectures) when your app is configured for Release. 当你的应用程序配置为进行调试时,将启用 "使用共享运行时" 和 "使用快速部署" 选项,这将禁用显式体系结构选择。When your app is configured for Debug, the Use Shared Runtime and Use Fast Deployment options are enabled, which disable explicit architecture selection.

在 Visual Studio 中,右键单击 "解决方案资源管理器下的项目,然后选择"属性"。In Visual Studio, right-click on your project under the Solution Explorer and select Properties. 在 " Android 选项" 页下,检查 "打包属性" 部分,并验证是否禁用了 "使用共享运行时" (关闭此选项可明确选择要支持的 abi)。Under the Android Options page check the Packaging properties section and verify that Use Shared Runtime is disabled (turning this off allows you to explicitly select which ABIs to support). 单击 "高级" 按钮,在 "支持的体系结构" 下,检查要支持的体系结构:Click the Advanced button and, under Supported architectures, check the architectures that you want to support:

选择 armeabi 和 armeabi-armeabi-v7aSelecting armeabi and armeabi-v7a

Xamarin.Android 支持以下体系结构:Xamarin.Android supports the following architectures:

  • armeabi – 基于 ARM 的 cpu,这些 cpu 至少支持 ARMv5TE 指令集。armeabi – ARM-based CPUs that support at least the ARMv5TE instruction set. 请注意,armeabi 不是线程安全的,因此不应在多 CPU 设备上使用。Note that armeabi is not thread-safe and should not be used on multi-CPU devices.

备注

Xamarin 9.2中,不再支持 armeabiAs of Xamarin.Android 9.2, armeabi is no longer supported.

  • armeabi-armeabi-v7a – 基于 ARM 的 cpu,其中包含硬件浮点操作和多 CPU (SMP)设备。armeabi-v7a – ARM-based CPUs with hardware floating-point operations and multiple CPU (SMP) devices. 请注意,armeabi-v7a 的计算机代码不会在 ARMv5 设备上运行。Note that armeabi-v7a machine code will not run on ARMv5 devices.

  • arm64-arm64-v8a基于64位 ARMv8 体系结构 – cpu。arm64-v8a – CPUs based on the 64-bit ARMv8 architecture.

  • 支持 x86 (或 IA-32)指令集的x86 – cpu。x86 – CPUs that support the x86 (or IA-32) instruction set. 此指令集等效于 Pentium Pro 的说明,包括 MMX、SSE、SSE2 和 SSE3 指令。This instruction set is equivalent to that of the Pentium Pro, including MMX, SSE, SSE2, and SSE3 instructions.

  • x86_64支持64位 x86 (也称为x64AMD64)指令集的 cpu。x86_64 CPUs that support the 64-bit x86 (also referred as x64 and AMD64) instruction set.

对于发布版本,Xamarin 默认值为 armeabi-v7aXamarin.Android defaults to armeabi-v7a for Release builds. 此设置比 armeabi提供明显更好的性能。This setting provides significantly better performance than armeabi. 如果以64位 ARM 平台为目标(例如结点9),请选择 "arm64-v8a"。If you are targeting a 64-bit ARM platform (such as the Nexus 9), select arm64-v8a. 如果要将应用部署到 x86 设备,请选择 "x86"。If you are deploying your app to an x86 device, select x86. 如果目标 x86 设备使用64位 CPU 体系结构,请选择 x86_64If the target x86 device uses a 64-bit CPU architecture, select x86_64.

面向多个平台Targeting Multiple Platforms

若要面向多个 CPU 体系结构,可以选择多个 ABI (但代价是 APK 文件大小较大)。To target multiple CPU architectures, you can select more than one ABI (at the expense of larger APK file size). 对于每个受支持的体系结构,可以使用 "根据所选 ABI 生成一个包(. apk) " 选项(如设置打包属性中所述)来创建单独的 apk。You can use the Generate one package (.apk) per selected ABI option (described in Set Packaging Properties) to create a separate APK for each supported architecture.

无需选择arm64-arm64-v8ax86_64以面向64位设备;在64位硬件上运行你的应用程序不需要64位支持。You do not have to select arm64-v8a or x86_64 to target 64-bit devices; 64-bit support is not required to run your app on 64-bit hardware. 例如,64位 ARM 设备(例如结点 9)可以运行为 armeabi-v7a配置的应用。For example, 64-bit ARM devices (such as the Nexus 9) can run apps configured for armeabi-v7a. 启用64位支持的主要优点是使应用程序能够处理更多的内存。The primary advantage of enabling 64-bit support is to make it possible for your app to address more memory.

备注

自 2018 年 8 月起新应用需要面向 API 级别 26,自 2019 年 8 月起,除 32 位版本之外,应用还需要提供 64 位版本From August 2018 new apps will be required to target API level 26, and from August 2019 apps will be required to provide 64-bit versions in addition to the 32-bit version.

其他信息Additional Information

在某些情况下,您可能需要为每个体系结构创建一个单独的 APK (以减小 APK 的大小,或者因为您的应用程序具有特定于特定 CPU 体系结构的共享库)。In some situations, you may need to create a separate APK for each architecture (to reduce the size of your APK, or because your app has shared libraries that are specific to a particular CPU architecture). 有关此方法的详细信息,请参阅生成 ABI 特定的 apkFor more information about this approach, see Build ABI-Specific APKs.