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

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

问题描述

•我已经使用了命令

xamarin-component.exe package C:\cmp\AndroidComponent\component 

用于创建Xamarin组件.在构建示例android项目时,它显示以下错误. (我已经使用命令xamarin-component.exe程序包C:\ cmp \ AndroidComponent \ component -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:\cmp\AndroidComponent\component -verbose to display the error message in detail).

错误消息:

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

C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.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:\cmp\AndroidComponent\component\samples\App17\VidyoClientAndroid\VidyoClientAndroid.csproj]

注意:

我能够为iOS源代码成功创建Xamarin组件. •在创建用于Android源代码的Xamarin组件时,从 64位文件夹(C:\ Program Files(x86)\ MSBuild \ 14.0 \ bin ** amd64 ** \ msbuild.exe"/p:Configuration = Release""C:\ cmp \ AndroidComponent \ component \ samples \ App17 \ App17.sln" ...). •在构建android项目时,从以下路径显式调用msbuild.exe:"C:\ Program Files(x86)\ MSBuild \ 14.0 \ Bin \ msbuild.exe"( 32 bit ),构建成功.明确的.

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)\MSBuild\14.0\bin**amd64**\msbuild.exe "/p:Configuration=Release" "C:\cmp\AndroidComponent\component\samples\App17\App17.sln"...). • Build is successful when msbuild.exe is called from path: "C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.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)\ MSBuild \ 14.0 \ bin \ amd64'的msbuild版本'14 .0'.

MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin\amd64'.

(您在上面正确地标识了自己),但请注意以下内容.

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

当使用MSBuild的64位版本时,$(TargetFrameworkRootPath)被定义为C:\Program Files\Reference Assemblies\Microsoft\Framework.但是Xamarin不会在该目录中安装任何Framework Utilities.相反,所有内容都保存在x86版本的此处C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework

When you use the 64bit version of MSBuild $(TargetFrameworkRootPath) gets defined as C:\Program Files\Reference Assemblies\Microsoft\Framework 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 Assemblies\Microsoft\Framework

当您在线阅读大量信息时,可以通过安装Visual Studio 2017来解决此问题;但这是一条红鲱鱼,它只能工作,因为它会导致NuGet使用Visual Studio 2017附带的MSBuild 15,显然不受此bug的影响.

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. 告诉NuGet在使用可选的-MSBuildPath参数还原时使用x86 MSBuild,如此处所述
  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 Assemblies\Microsoft\Framework; 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天全站免登陆