无法为 android 源代码创建 Xamarin 组件 [英] Not able to create a Xamarin-component for android Source code

查看:29
本文介绍了无法为 android 源代码创建 Xamarin 组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

• 我已经使用了命令

xamarin-component.exe package C:cmpAndroidComponentcomponent 

用于创建 Xamarin 组件.在构建示例 android 项目时,它显示以下错误.(我已经使用命令 xamarin-component.exe package C:cmpAndroidComponentcomponent -verbose 来详细显示错误信息).

for creating Xamarin component.While building the Sample android project, it is showing the below error. (I have used the command xamarin-component.exe package C:cmpAndroidComponentcomponent -verbose to display the error message in detail).

错误信息:

C:程序文件(x86)MSBuildXamarinAndroidXamarin.Android.Bindings.targets(155,2):错误 MSB3644:框架的参考程序集未找到MonoAndroid,Version=v1.0".要解决此问题,请安装此框架版本的 SDK 或 Targeting Pack 或重新定位您的应用到您拥有 SDK 的框架版本或已安装目标包.请注意,程序集将被解析来自全局程序集缓存 (GAC) 并将用于代替参考程序集.因此您的组装可能不正确针对您想要的框架.[C:cmpAndroidComponentcomponentsamplesApp17VidyoClientAndroidVidyoClientAndroid.csproj]

C:Program Files (x86)MSBuildXamarinAndroidXamarin.Android.Bindings.targets(155,2): error MSB3644: The reference assemblies for framework "MonoAndroid,Version=v1.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:cmpAndroidComponentcomponentsamplesApp17VidyoClientAndroidVidyoClientAndroid.csproj]

注意:

我能够成功地为 iOS 源代码创建 Xamarin 组件.• 在为 Android 源代码创建 Xamarin 组件时,从 64 位文件夹(C:Program Files (x86)MSBuild14.0in**amd64**msbuild.exe "/p:Configuration=Release" "C:cmpAndroidComponentcomponentsamplesApp17App17.sln"...).• 构建android 项目时,从路径C:Program Files (x86)MSBuild14.0Binmsbuild.exe"(32 位) 调用msbuild.exe 时构建成功明确的.

I am able to create a Xamarin component for iOS source code successfully. • While creating the Xamarin component for Android source code, internally msbuild.exe is getting called from 64 bit folder(C:Program Files (x86)MSBuild14.0in**amd64**msbuild.exe "/p:Configuration=Release" "C:cmpAndroidComponentcomponentsamplesApp17App17.sln"...). • Build is successful when msbuild.exe is called from path: "C:Program Files (x86)MSBuild14.0Binmsbuild.exe"(32 bit) explicitly while building the android project explicity.

推荐答案

我们遇到了同样的问题;您已经接近正确的答案,而论坛也有正确的答案.

We ran into the same issue; you were close to the right answer, and the forums had the correct one.

首先让我们看一下出错的代码部分(Xamarin.Android.Common.targets;在较新版本的 Xamarin 中,此代码要低得多):

First lets look at the portion of code that is erroring (Xamarin.Android.Common.targets; in the newer versions of Xamarin this code is much further down):

<Target Name="_GetReferenceAssemblyPaths">
<GetReferenceAssemblyPaths
        TargetFrameworkMoniker="$(TargetFrameworkIdentifier),Version=v1.0"
        RootPath="$(TargetFrameworkRootPath)">
    <Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_XATargetFrameworkDirectories" />
</GetReferenceAssemblyPaths>

这里最重要的部分是

$(TargetFrameworkRootPath)

当通过命令行运行 NuGet 时,我们看到它正在使用 64 位 MSBuild 可执行文件:

When NuGet is ran via the command line we see that it is using the 64bit MSBuild Executable:

MSBuild 自动检测:使用来自C:Program Files (x86)MSBuild14.0inamd64"的 msbuild 版本14.0".

MSBuild auto-detection: using msbuild version '14.0' from 'C:Program Files (x86)MSBuild14.0inamd64'.

(您在上面自己正确识别了这一点)但只是为了让任何跟随的人都清楚.

(You correctly identified this yourself above) but just to be clear for anyone following along.

当您使用 64 位版本的 MSBuild $(TargetFrameworkRootPath) 被定义为 C:Program FilesReference AssembliesMicrosoftFramework 但是 Xamarin 不安装任何框架实用程序到该目录;取而代之的是这里的 x86 版本 C:Program Files (x86)Reference AssembliesMicrosoftFramework

When you use the 64bit version of MSBuild $(TargetFrameworkRootPath) gets defined as C:Program FilesReference AssembliesMicrosoftFramework However Xamarin does not install any of the Framework Utilities to that directory; instead everything lives in the x86 version here C:Program Files (x86)Reference AssembliesMicrosoftFramework

当您在线阅读时,很多人通过安装 Visual Studio 2017 解决了这个问题;但这是一个红鲱鱼,它只能工作,因为它会导致 NuGet 使用 MSBuild 15,它与 Visual Studio 2017 一起提供,显然不受此错误的影响.

When you read online a ton of people get this problem solved by installing Visual Studio 2017; but that is a red-herring it only works because it causes NuGet to use MSBuild 15 which ships with Visual Studio 2017 which apparently is not affected by this bug.

有几种方法可以解决此问题:

There are a few ways to fix this issue:

  1. 使用此处所述的可选 -MSBuildPath 参数在还原时告诉 NuGet 使用 x86 MSBuild 我如何告诉 NuGet 使用什么 MSBuild 可执行文件?
  2. 升级到 Visual Studio 2017 以获取 MSBuild 15
  3. 定义 $(TargetFrameworkRootPath)C:Program Files (x86)Reference AssembliesMicrosoftFramework;这可以随心所欲地完成,最大的锤子是在执行之前将其设置为环境中的环境变量.请注意,如果您不小心,这可能会导致一堆意想不到的副作用. <- 不要这样做,即使按照表格中的建议.
  1. Tell NuGet to use the x86 MSBuild when you Restore using the optional -MSBuildPath argument as described here How Can I Tell NuGet What MSBuild Executable to Use?
  2. Upgrade to Visual Studio 2017 to get MSBuild 15
  3. Define $(TargetFrameworkRootPath) to be C:Program Files (x86)Reference AssembliesMicrosoftFramework; this can be done however you please, the biggest hammer is to set it as an environment variable in the environment prior to execution. Note this will probably cause a bunch of unintended side-affects if you're not careful. <- DON'T DO THIS, Even as suggested in the forms.

这篇关于无法为 android 源代码创建 Xamarin 组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆