优质博文:IT-BLOG-CN
问题
我一直在 Windows 计算机上设置 Visual Studio 以进行 .NET MAUI 开发,但在设置过程中一直遇到问题。具体问题涉及 OpenJDK v8 无法安装。这是我看到的情况:
Couldn't install OpenJDKv8
我尝试过几种方法来解决这个问题,但都没有什么效果。以下是我已经尝试过的方法的简要列表:
以管理员身份运行安装程序:我以管理员权限运行了 Visual Studio 安装程序,以为它可能会修复权限问题。,但这没有奏效。
手动安装 OpenJDK:我从 AdoptOpenJDK 网站获取了 OpenJDK v8,并自行设置了 JAVA_HOME 变量。尽管我可以自行安装,但 Visual Studio 仍然无法自行安装 OpenJDK。
检查文件夹权限:我确保 C:\Program Files\Android\jdk\ 文件夹未设置为读取,并且我检查了我的帐户是否具有完全访问权限。但我仍然卡住了。
清除安装程序缓存::我通过删除 ProgramData\Microsoft\VisualStudio\Packages 中的所有内容来清除 Visual Studio 安装程序的缓存,但安装仍然失败。
这是我在安装过程中收到的完整错误消息:
Package 'OpenJDKv8,version=8.0.302.8,chip=x64' failed to install.
Return code: -2147024891
Return code details: Access to the path 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08\bin\klist.exe' is denied.
安装错误
Something went wrong with the install.
You can troubleshoot the package failures by:
1. Search for solutions using the search URL below for each package failure
2. Modify your selections for the affected workloads or components and then retry the installation
3. Remove the product from your machine and then install again
If the issue has already been reported on the Developer Community, you can find solutions or workarounds there. If the issue has not been reported, we encourage you to create a new issue so that other developers will be able to find solutions or workarounds. You can create a new issue from within the Visual Studio Installer in the upper-right hand corner using the "Provide feedback" button.
================================================================================
Package 'OpenJDKv8,version=8.0.302.8,chip=x64' failed to install.
Search URL
https://aka.ms/VSSetupErrorReports?q=PackageId=OpenJDKv8;PackageAction=Install;ReturnCode=-2147024891
Details
Return code: -2147024891
Return code details: Access to the path 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08\bin\klist.exe' is denied.
Log
C:\Users\User\AppData\Local\Temp\dd_setup_20240904132622_002_OpenJDKv8.log
Impacted workloads
.NET Multi-platform App UI development (Microsoft.VisualStudio.Workload.NetCrossPlat,version=17.11.35102.94)
Impacted components
.NET MAUI (Microsoft.VisualStudio.ComponentGroup.Maui.All,version=17.11.35102.94)
.NET MAUI development tools (Microsoft.VisualStudio.ComponentGroup.Maui.Shared,version=17.11.35102.94)
.NET MAUI for Android (Microsoft.VisualStudio.ComponentGroup.Maui.Android,version=17.11.35102.94)
OpenJDK (Microsoft distribution) (Component.OpenJDK,version=17.11.35102.94)
相关日志片段:
[4100:0009][2024-09-04T13:26:36] Started: Extracting C:\ProgramData\Microsoft\VisualStudio\Packages\OpenJDKv8,version=8.0.302.8,chip=x64\OpenJDK8U-jdk_x64_windows_hotspot_8u302b08.zip to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/ASSEMBLY_EXCEPTION to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/ASSEMBLY_EXCEPTION
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/ASSEMBLY_EXCEPTION to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/ASSEMBLY_EXCEPTION
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/ASSEMBLY_EXCEPTION'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/jrunscript.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jrunscript.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/jrunscript.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jrunscript.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jrunscript.exe'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/jsadebugd.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jsadebugd.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/jsadebugd.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jsadebugd.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jsadebugd.exe'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/jstat.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jstat.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/jstat.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jstat.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jstat.exe'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/jstatd.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jstatd.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/jstatd.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jstatd.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/jstatd.exe'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/keytool.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/keytool.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/keytool.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/keytool.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/keytool.exe'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/kinit.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/kinit.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/kinit.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/kinit.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/kinit.exe'.
[4100:0009][2024-09-04T13:26:36] Started: Copying file jdk8u302-b08/bin/klist.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/klist.exe
[4100:0009][2024-09-04T13:26:36] Completed: Copying file jdk8u302-b08/bin/klist.exe to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/klist.exe
[4100:0009][2024-09-04T13:26:36] Timestamp updated for file 'C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08/bin/klist.exe'.
[4100:0009][2024-09-04T13:26:36] Completed: Extracting C:\ProgramData\Microsoft\VisualStudio\Packages\OpenJDKv8,version=8.0.302.8,chip=x64\OpenJDK8U-jdk_x64_windows_hotspot_8u302b08.zip to C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot
系统信息:
操作系统:Windows 11 Pro(64位)
Visual Studio 版本:2022(专业版,版本 17.11.2)
.NET SDK 版本:8.0.401
工作负载:.NET 多平台应用程序 UI (MAUI)
有人经历过这种情况吗?我想知道是否有办法完全通过 Visual Studio 绕过 OpenJDK 安装,只需在 MAUI 中手动设置 Android 开发即可。还是我错过了一些简单的东西?
解决方案
听起来您在 Visual Studio 中设置 .NET MAUI 时遇到了 OpenJDK v8 安装的权限问题。由于您已经尝试了几种解决方案,因此以下是几种重点方法:
手动 JDK 设置:由于您已手动安装了 OpenJDK,请确保 JAVA_HOME 和 PATH 环境变量指向您的 JDK 安装。然后,在 Visual Studio 安装程序中,取消选择 OpenJDK 组件以防止进一步冲突。
文件夹权限:仔细检查 C:\Program Files\Android\jdk\ 是否对您的帐户具有完全控制权限。尝试在安全模式下运行安装或禁用防病毒软件以绕过任何限制。
解决方法:如果问题仍然存在,请考虑将其与日志一起报告给开发者社区以获得进一步的帮助。
这应该可以解决冲突并允许您继续进行 .NET MAUI 开发。