# 构建(Building)AAPS ## Build yourself instead of download **由于医疗器械相关法规的限制,AAPS应用(一个apk文件)无法提供下载。 It is legal to build the app for your own use, but you must not give a copy to others!** See [FAQ page](../UsefulLinks/FAQ.md) for details. (Building-APK-recommended-specification-of-computer-for-building-apk-file)= ## 构建AAPS所需的计算机和软件规格。 * A specific **[Android Studio](https://developer.android.com/studio/)** version may be required to build the apk. See table below : | AAPS Version | Preferred
Android Studio
Version | Alternative
Android Studio
Version | Gradle | JVM | | ----------------------- | ---------------------------------------------------- | ------------------------------------------------------ | ------ |:--- | | 2.6.2 | 3.6.1 | | 5.6 | 11 | | 2.8.2.1 | 4.1.1 | | 6.1 | 13 | | 3.1.0.3 | 2020.3.1 | up to Meerkat | 7.3 | 17 | | [3.2.0.4](#version3200) | Hedgehog (2023.1.1) | up to Meerkat | 8.2 | 19 | | [3.3](#version3300) | Ladybug (2024.2.1) | up to Meerkat | 8.9 | 21 | | [3.3.1.3](#version3300) | Ladybug Feature Drop (2024.2.2) | up to Meerkat | 8.10 | 21 | | 3.3.2 | Meerkat (2024.3.1) | | 8.11 | 21 | The "preferred version" is packaged with the appropriate JVM version. The preferred version is also the minimal version you can use to build **AAPS**. You will **NOT** be able to build on a version older than the "preferred" one. If using a different version, you may encounter issues related to JVM version. See the [Troubleshooting Android Studio](#troubleshooting_androidstudio-uncommitted-changes) page to help solve these issues. If your current Android Studio version is not listed in the table, you must update it first. The Gradle version is linked to the source code, you will always get the correct Gradle version when downloading / updating the source code. It is mentioned here for reference only, you don't have to take action on it. * Android Studio 不支持 [Windows 32位系统](#troubleshooting_androidstudio-unable-to-start-daemon-process)。 请牢记,**64位CPU和64位操作系统是必要条件**。 如果您的系统不满足这一条件,您需要更换相应的硬件、软件或整个系统。
操作系统 (仅限 64 位) Windows 8 或更新版 Mac OS 10.14 或更新版 任何支持Gnome、KDE或Unity桌面环境的Linux系统;  GNU C库2.31或更高版本。

CPU(仅限64位)

x86_64 CPU架构;第二代Intel Core或更新版本,或支持
Windows Hypervisor的AMD CPU。
基于ARM的芯片,或第二代Intel Core或更新版本(需支持
Hypervisor.Framework)。
x86_64 CPU架构;第二代Intel Core或更新版本,或支持AMD虚拟化(AMD-V)和SSSE3的AMD处理器。

内存(RAM)

8GB 或更多

硬盘

至少30GB的可用空间。 建议使用SSD(固态硬盘)。

分辨率

至少1280 x 800

网络连接

宽带

**强烈建议(非强制)使用固态硬盘(SSD)而非机械硬盘(HDD),因为这将减少你构建AAPS apk文件所需的时间。**不过,在构建**AAPS** apk文件时,你仍然可以使用机械硬盘。 如果使用机械硬盘,构建过程可能会需要很长时间才能完成,但是一旦开始,你就可以让它无人值守地运行。 ## 构建过程中的帮助和支持 如果在构建**AAPS**应用的过程中遇到困难,有一个专门的[**Android Studio故障排除**](../GettingHelp/TroubleshootingAndroidStudio)部分,请先参考该部分。 如果你认为构建说明中有错误、遗漏或令人困惑的地方,或者你仍然在努力解决问题,请联系[Facebook](https://www.facebook.com/groups/AndroidAPSUsers)或[Discord](https://discord.gg/4fQUWHZ4Mw)上的其他**AAPS**用户组。 如果你想自己更改某些内容(如更新截图_等_),请提交一个[拉取请求(PR)](../SupportingAaps/HowToEditTheDocs.md)。 ## 构建AAPS应用的逐步指南。 ```{admonition} WARNING :class:警告 如果你之前已经构建过AAPS,则无需再次执行以下所有步骤。 请直接跳转到[更新指南](../Maintenance/UpdateToNewVersion.md)! ``` ```{contents} The overall steps for building the **AAPS** apk file :depth: 1 :local: true ``` 在本指南中,您将看到构建**AAPS** apk文件的_示例_截图。 由于我们用于构建**AAPS** apk的软件**Android Studio**会定期更新,这些截图可能与您的安装界面不完全一致,但您仍然可以按照它们进行操作。 **Android Studio**可在Windows、Mac OS X和Linux平台上运行,因此不同平台的步骤可能会存在细微差异。 (install-git-if-you-dont-have-it)= ### Git安装步骤 ```{admonition} Why Git? :class: 下拉菜单(dropdown?) Git是一个“_版本控制系统_”(VCS)。\ Git是一个程序,允许您跟踪代码中的更改并与他人协作。 您将使用Git从GitHub网站将**AAPS**源代码的副本复制到您的本地计算机。 然后,您将在计算机上使用Git来构建**AAPS**应用程序(apk)。 ``` (BuildingAaps-steps-for-installing-git)= #### 安装Git的步骤 1. 检查**Git**是否已安装 **Settings**(Windows上)或**Android Studio** > **Preferences**(Mac上)。 这将打开以下窗口,点击展开名为**Version Control**(1)的下拉菜单,然后选择**Git** ![Version_control_Git](../images/Building-the-App/038_SettingsGit.png) 检查**Android Studio**是否可以自动定位正确的**Git可执行文件路径**,方法是点击“Test”按钮(1): ![Git Executable](../images/Building-the-App/039_GitTest.png) 如果自动设置成功,你当前版本的**Git**将显示在路径旁边。 ![Git_version_displayed](../images/Building-the-App/039_GitTestSuccess.png) 如果你发现**git.exe**没有自动找到,或者点击“Test”导致错误(1),你可以要么 * 手动输入你[之前](#BuildingAaps-steps-for-installing-git)保存的路径,要么 * 点击文件夹图标(1),然后手动导航到之前[已安装](#BuildingAaps-steps-for-installing-git)**git.exe**的目录。 * 使用Test按钮验证你的设置! ![Git not found](../images/Building-the-App/039_GitTestError.png) (Building-APK-generate-signed-apk)= ### 构建AAPS的“签名版”APK文件 ```{admonition} Why does the AAPS app need to be "signed"? :class:下拉菜单(dropdown?) Android要求每个应用都必须被_签名_,以确保它只能在以后从发布原始应用的同一可信来源更新。 有关此主题的更多信息,请访问[这个链接] (https://developer.android.com/studio/publish/app-signing.html#generate-key). 这意味着我们生成一个签名或“keystore”文件,并在构建**AAPS**应用时使用它。 ``` **重要提示:在进行下一步之前,请确保Gradle同步已成功完成!** 点击左上角的汉堡菜单以打开菜单栏。 选择**Build**(1),然后选择**Generate Signed App Bundle / APK**(2)。 ![Build apk](../images/Building-the-App/040_GenerateSignedAPK.png) 选择“APK”而不是“Android App Bundle”,然后点击“下一步”: ![APK instead of bundle](../images/Building-the-App/041_APK.png) 在下一个屏幕中,确保“模块”设置为“AAPS.app”(1)。 (Building-APK-wearapk)= ```{admonition} INFORMATION! :class: 信息 如果您要为手表创建APK,现在需要选择AAPS.wear! ``` ![Create_key_store](../images/Building-the-App/042_CreateNewKey.png) 点击“创建新的...” (2)以开始创建您的密钥库。 ```{admonition} INFORMATION! :class: information 您只需要创建一次keystore。 如果您之前已经构建过AAPS,请不要创建新的keystore,而是选择您现有的keystore并输入其密码! ``` **_注意:_** keystore是一个文件,用于存储签名应用的信息。 它是加密的,并且信息通过密码保护。 ![Create key store](../images/Building-the-App/043_Keystore.png) * 点击“文件夹”图标(1)以选择您计算机上的一个路径来保存您的密钥库。 **不要**使用存储源代码的目录,而是选择您也会转移到新计算机上的某个目录。 ```{admonition} WARNING! :class:警告 请务必记下您的keystore存储位置。 在构建下一个AndroidAPS更新时,您将需要它! ``` * 现在选择一个简单的密码(并记下它),在密码框(2)中输入它,并确认密码(2)。 密钥库和密钥的密码不需要非常复杂。 如果您将来丢失了密码,请参阅[丢失keystore的故障排除](#troubleshooting_androidstudio-lost-keystore)。 * 默认的密钥别名(3)是“key0”,请保持不变。 * 现在您需要为您的密钥设置一个密码。 为了简单起见,如果您愿意,可以使用与上面设置的密钥库相同的密码。 输入密码(4)并确认它。 ```{admonition} WARNING! :class:警告 记下这些密码! 在构建下一个AAPS更新时,您将需要它们! ``` * 有效期默认为25年,保持不变。 * 输入您的名字和姓氏(5)。 其他信息无需填写,但您可以根据需要自行添加(6-7)。 * 点击“确定”(8)以继续: 在**Generate signed App Bundle or APK**页面上,现在将显示您的keystore的路径。 现在重新输入密钥库密码(1)和密钥密码(2),并勾选方框(3)以记住密码,这样您在下次构建APK时(例如,更新到新的AAPS版本时)就不用再次输入这些密码。 点击“下一步”(4): ![Remember passwords](../images/Building-the-App/044_RememberPwd.png) 在下一个屏幕中,选择构建变量“完全版本(fullRelease)”(2),然后点击“创建”(3)。 您应该记住在(1)处显示的目录,因为之后您可以在那里找到构建好的APK文件! ![Select build variant](../images/Building-the-App/045_BuildPath.png) Android Studio现在将构建AAPS apk。 在右下角会显示“Gradle 构建运行中”(2)。 此过程需要一些时间,具体取决于您的计算机和互联网连接,因此**请耐心等待!**如果您想查看构建进度,请点击Android Studio底部的“build”小锤子图标(1): ![Gradle Running](../images/Building-the-App/046_BuildRunning.png) 现在您可以查看构建进度: ![Android_Studio_building](../images/Building-the-App/047_BuildDetails.png) 构建完成后,Android Studio 将显示“构建成功”的信息。 您可能会看到一个弹出通知,您可以点击它以选择“定位”。 如果您错过了这个通知,请点击通知图标(1),然后在屏幕最底部点击**locate**(2)以打开通知列表: ![Build finished](../images/Building-the-App/049_ReopenNotification.png) **_如果构建不成功,请参阅[Android Studio故障排除部分](../GettingHelp/TroubleshootingAndroidStudio)。_** 在通知框中,点击蓝色链接“定位”: ![Locate build](../images/Building-the-App/048_BuildFinished.png) 构建成功后,您将收到通知,并可以通过点击通知中的链接来定位您的apk文件。 ![File location apk](../images/Building-the-App/050_LocateAPK.png) Congratulations! 现在您已经构建了AAPS apk文件,接下来您将把这个文件传输到您的智能手机上。 ```{tip} 如果您认为将来可能会使用Android Wear智能手表,那么现在是构建AAPS Wear apk的最佳时机,以确保它与您的AAPS apk同步。 ``` 接下来,请转到下一阶段[传输和安装**AAPS**](../SettingUpAaps/TransferringAndInstallingAaps.md)。