简体   繁体   English

如何使用 Visual Studio 从 Xamarin.Forms 项目生成 .apk 文件?

[英]How to generate an .apk file from Xamarin.Forms Project using Visual Studio?

I have a Xamarin.Forms project that I'd like to distribute as an apk ;我有一个 Xamarin.Forms 项目,我想将其作为apk分发; however I cannot find how to generate a .apk file in Visual Studio - how would I do this?但是我找不到如何在 Visual Studio 中生成.apk文件 - 我该怎么做?

When using Visual Studio 2015 Update 3 with the latest Xamarin tools (which is v4.2.2.6 when writing this answer), right click your Android project and select " Archive... " as described here:将 Visual Studio 2015 Update 3 与最新的 Xamarin 工具(编写此答案时为 v4.2.2.6)一起使用时,右键单击您的 Android 项目并选择“存档... ”,如下所述:

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/#Compile https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/#Compile

This will open the Archive Manager and begins the process of archiving the App bundle.这将打开存档管理器并开始存档应用程序包的过程。 When the archiving is finished, you can click on the button " Distribute... " at the right bottom corner of the Archive Manager to create a signed APK.存档完成后,您可以点击存档管理器右下角的“分发... ”按钮来创建一个已签名的 APK。 This is described here:这是在此处描述的:

https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_2_-_signing_the_android_application_package/ https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_2_-_signing_the_android_application_package/

Note: if you do not use a signed APK, you will probably get a parse error if try to install on an Android device.注意:如果您不使用已签名的 APK,则在尝试在 Android 设备上安装时可能会出现解析错误。

Try The Following Steps:尝试以下步骤:

  1. You need to change Your Project Mode from debug to release.您需要将您的项目模式从调试更改为发布。

  2. Rebuild your project.重建你的项目。

  3. Go to Build --> Archive --> Distribute -- AdHoc --> Sign & Add Details --> Save As转到构建 --> 存档 --> 分发 -- AdHoc --> 签名并添加详细信息 --> 另存为

The APK is Ready To Publish in Play Store :) APK 已准备好在 Play 商店中发布 :)

首先您的项目应该处于发布模式然后只需右键单击您的android项目并选择图像中显示的“导出Android包(.apk)”您的.apk文件将在您的项目目录中创建

You can find your APK or IPA file in your bin folder from your project.您可以在项目的 bin 文件夹中找到您的 APK 或 IPA 文件。 So in Android it is located here: Project.Droid/bin/MyAppName.apk所以在 Android 中它位于: Project.Droid/bin/MyAppName.apk

This might not be the case when you build with the App Store configuration or maybe there are other problems with the Xamarin IDE.当您使用 App Store 配置进行构建时,情况可能并非如此,或者 Xamarin IDE 可能存在其他问题。 In that case you can do a right click on your project and choose Archive for Publishing which will save your artefact here ~/Library/Developer/Xamarin/Archives/ .在这种情况下,您可以右键单击您的项目并选择Archive for Publishing ,这将在此处保存您的人工制品~/Library/Developer/Xamarin/Archives/ Alternatively right click on your project and choose View Archives或者右键单击您的项目并选择查看档案

Steps to Create APK in Visual Studio 2022:在 Visual Studio 2022 中创建 APK 的步骤:

  1. Build app in RELEASE mode.在 RELEASE 模式下构建应用程序。
  2. Right Click on Android Project > Properties > Android Options > Uncheck “Use Fast Deployment”, if checked.右键单击 Android 项目 > 属性 > Android 选项 > 取消选中“使用快速部署”(如果已选中)。
  3. Right Click on Android Project > Archive.右键单击 Android 项目 > 存档。
  4. Distribute > AdHoc > Add signing Identity by clicking on "+" icon and fill the details as shown in image below.分发 > AdHoc > 通过单击“+”图标添加签名身份并填写详细信息,如下图所示。
  5. Save the app and you're done.保存应用程序,你就完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM