将 Xamarin.Android 安装为系统应用Installing Xamarin.Android as a System App

本指南将讨论系统应用和用户应用之间的区别,以及如何将 Xamarin.Android 应用作为系统应用安装。本指南适用于自定义 Android ROM 映像的作者。它将说明如何创建自定义 ROM。This guide will discuss the differences between a system app and a user app, and how to install a Xamarin.Android application as a system application. This guide applies to authors of custom Android ROM images. It will not explain how to create a custom ROM.

系统应用System App

自定义 Android ROM 映像的作者或 Android 设备制造商在分发 ROM 或设备时,可能希望将 Xamarin.Android 应用包含为一个系统应用 。Authors of custom Android ROM images or manufacturers of Android devices may wish to include a Xamarin.Android application as a system app when distributing a ROM or a device. 系统应用是被认为对设备运行非常重要或提供自定义 ROM 作者始终希望可用的功能的一款应用。A system app is an app that is considered to be important to the functioning of the device or provide functionality that the custom ROM author always wants to be available.

系统应用安装在“/system/app/” 文件夹中(文件系统的一个只读目录),用户无法将其删除或移动,除非该用户具有根目录访问权限。System apps are installed in the folder /system/app/ (a read-only directory on the file system) and cannot be deleted or moved by the user unless that user has root access. 与此相反,由用户安装的应用程序(通常是从 Google Play 或通过旁加载应用进行安装)称为“用户应用” 。In contrast, an application that is installed by the user (typically from Google Play or by sideloading the app) is known as a user app. 用户应用可以被用户删除,并且在许多情况下可以移动到设备上的其他位置(如某类外部存储)。User apps can be deleted by the user and in many cases can be moved to a different location on the device (such as some kind of external storage).

系统应用的行为与用户应用的完全一致,但具有以下值得注意的例外情况:System apps behave exactly like user apps, but have the following notable exceptions:

  • 系统应用可以像正常用户应用 一样进行升级。System apps are upgradable just like a normal user app. 但是,因为应用副本一直存在于“/system/app/” 中,该应用始终可以回退到原始版本。However, because a copy of the app always exists in /system/app/, it is always possible to roll back the application to the original version.

  • 系统应用可能被授予对用户应用不可用的某些仅限系统的权限。System apps may be granted certain system-only permissions that are not available to a user app. 仅限系统权限的一个示例是 BLUETOOTH_PRIVILEGED,它允许应用程序与蓝牙设备配对,而无需与任何用户进行交互。An example of a system-only permission is BLUETOOTH_PRIVILEGED, which allows applications to pair with Bluetooth devices without any user interaction.

可以将 Xamarin.Android 应用作为系统应用程序分发。It is possible to distribute a Xamarin.Android app as a system application. 除了向自定义 ROM 提供 APK,还有两个共享库,libmonodroid.so 和 libmonosgen 2.0.so ,必须将其手动从 APK 复制到 ROM 映像的文件系统。In addition to providing an APK to the custom ROM, there are two shared libraries, libmonodroid.so and libmonosgen-2.0.so that must be manually copied from the APK to the filesytem of the ROM image. 本指南将说明所涉及的步骤。This guide will explain the steps involved.

限制Restrictions

本指南适用于自定义 Android ROM 映像的作者。This guide applies to authors of custom Android ROM images. 它将说明如何创建自定义 ROM。It will not explain how to create a custom ROM.

本指南假定你熟悉打包适用于 Xamarin.Android 的发布 APK,并了解 Android 应用程序的 CPU 体系结构This guide assumes familiarity with packaging a release APK for a Xamarin.Android and an understanding of CPU Architectures for Android applications.

将 Xamarin.Android 应用安装为系统应用Install a Xamarin.Android App as a System App

以下步骤介绍如何将 Xamarin.Android 应用作为系统应用进行安装。The following steps describe how to install a Xamarin.Android app as a system app.

  1. 打包 Xamarin.Android 应用的发布 APK – 发布应用程序指南对此进行了详述。Package a release APK of the Xamarin.Android app – This is described in more detail by the Publishing an Application guide.

  2. 从 APK 提取共享库 – 使用任何 ZIP 实用程序,打开 APK 文件并检查 /lib/ 文件夹的内容。Extract shared libraries from the APK – Using any ZIP utility program, open up the APK file and examine the contents of the /lib/ folder. 此文件夹的每个应用程序二进制接口 (ABI) 都将有一个受该应用程序支持的子目录;此文件夹内容将包含该特定 ABI 上应用程序所需的所有共享库:This folder will have a subdirectory for each application binary interface (ABI)that is supported by the application; the contents of this folder will include all of the shared libraries that are required by the app on that particular ABI:

    taskypro.zip 的 armeabi-v7a 文件夹中 .so 文件的屏幕截图

    在上面的屏幕截图中,只有一个支持的 ABI (armeabi-v7a ) 持有两个应用所需的 .so 文件。In the previous screenshot, there is only one supported ABI (armeabi-v7a) holding the two .so files that are required by the app. 请注意,它只用来提取适用于设备或设备 ROM 目标体系结构的 ABI 文件,也就是说,不将 .so 文件从 x86 文件夹复制到 armeabi-v7a 设备或 ROM。Note that it is only necessary to extract the ABI files that are appropriate for the device or the target architecture of the device ROM, i.e. do not copy .so files from the x86 folder to an armeabi-v7a device or ROM.

  3. 将 .so 文件复制到 /system/lib – 将上一步中从 APK 提取的 .so 文件复制到自定义 ROM 上的 /system/lib/ 文件夹中。Copy .so files to /system/lib – Copy the .so files that were extracted from the APK in the previous step to the /system/lib/ folder on the custom ROM.

  4. 将 APK 文件复制到 /system/app – 最后一步是将 APK 文件复制到 ROM 上的 /system/app 文件夹 。Copy the APK file to /system/app – The final step is to copy the APK file to the /system/app folder on the ROM.

总结Summary

本指南讨论了系统应用 和用户应用 之间的区别,并介绍了如何将 Xamarin.Android 应用作为系统应用安装。This guide discussed the difference between a system app and a user app, and explained how to install a Xamarin.Android application as a system app.