当使用第 3 方 Xamarin 组件时,Xamarin 应用仅在调试模式而非发布模式下编译
Xamarin app only compiles in debug mode, not release mode, when using 3rd party Xamarin component
我正在尝试将 Localytics SDK(通过他们的 Xamarin component)集成到我的 Xamarin Android 应用程序中。它在调试模式下编译,但是如果我切换到发布版本,那么它会在编译时出错:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets:
Error: Error executing task LinkAssemblies: error XA2006: Could not
resolve reference to 'Android.Gms.Gcm.Iid.InstanceIDListenerService'
(defined in assembly 'LocalyticsXamarin.Android, Version=4.2.0.29760,
Culture=neutral, PublicKeyToken=null') with scope
'Xamarin.GooglePlayServices.Gcm, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'. When the scope is different from the defining
assembly, it usually means that the type is forwarded.
(com.rpr.mobile.droid)
如果我将 Linker Behavior 从 Link SDK assemblies only 切换到 Don't link 然后它编译正常,但是这不是一个选项,因为然后 apk太大了。如果我切换回仅 Link SDK 程序集并将 "LocalyticsXamarin.Android" 添加到忽略程序集列表,它仍然会给出相同的编译错误。
此错误似乎暗示我的应用程序和 Localytics Xamarin 包装器之间的 Google Play 服务版本控制不匹配,但是他们向我发送了使用最新版本 (42.1001.0) 的包装器的更新版本我已经确认它与我们的应用程序匹配。此外,他们自己的示例 Android 项目编译得很好。我梳理了他们的示例 Android 项目中的每个设置,并将其更改为与我的相匹配,但他们的仍然可以编译,而我的不能。
这是我的 Android 项目中的 packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="modernhttpclient" version="2.4.2" targetFramework="MonoAndroid60" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="MonoAndroid60" />
<package id="Rx-Core" version="2.2.5" targetFramework="monoandroid70" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="monoandroid70" />
<package id="Rx-Linq" version="2.2.5" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Fragment" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Media.Compat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v13" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Build.Download" version="0.4.3" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Common" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Iid" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Base" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Basement" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gcm" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Iid" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Location" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Maps" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.TagManager.V4.Impl" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Tasks" version="42.1001.0" targetFramework="monoandroid70" />
</packages>
下面是有效的示例 Localytics 项目的 packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Design" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Fragment" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Media.Compat" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Transition" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v4" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.CardView" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.MediaRouter" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.Palette" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Build.Download" version="0.4.3" targetFramework="MonoAndroid70" />
<package id="Xamarin.Forms" version="2.3.3.193" targetFramework="MonoAndroid70" />
<package id="Xamarin.GooglePlayServices.Base" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Basement" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Clearcut" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gass" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gcm" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Iid" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Tasks" version="42.1001.0" targetFramework="monoandroid70" />
</packages>
要重现问题...
Here 是 Localytics SDK Xamarin 包装器的最新代码,构建得很好。您需要获取 .xam 文件并使用 Xamarin-Component 将其安装到 Xamarin Studio。
Here 是我的 Android 项目代码的精简版。
对于我的项目的大小,我深表歉意,我删除了所有代码和资源,但由于组件和包的原因,它仍然很大,我不想删除它们,因为它们与问题相关。您需要打开 RPR Mobile - Android.sln 解决方案,更改为 Release-Prod,然后尝试构建,您会看到错误。
有什么想法吗?
此 PATCHED
版本附带的组件似乎未更新以包含您需要的参考,例如 Xamarin.GooglePlayServices.Iid
。
您很可能需要重新制作此组件或让供应商为您重新制作。关于最终 .dll
被添加到您的项目中,这里似乎存在缓存问题。
我正在尝试将 Localytics SDK(通过他们的 Xamarin component)集成到我的 Xamarin Android 应用程序中。它在调试模式下编译,但是如果我切换到发布版本,那么它会在编译时出错:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Could not resolve reference to 'Android.Gms.Gcm.Iid.InstanceIDListenerService' (defined in assembly 'LocalyticsXamarin.Android, Version=4.2.0.29760, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.GooglePlayServices.Gcm, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded. (com.rpr.mobile.droid)
如果我将 Linker Behavior 从 Link SDK assemblies only 切换到 Don't link 然后它编译正常,但是这不是一个选项,因为然后 apk太大了。如果我切换回仅 Link SDK 程序集并将 "LocalyticsXamarin.Android" 添加到忽略程序集列表,它仍然会给出相同的编译错误。
此错误似乎暗示我的应用程序和 Localytics Xamarin 包装器之间的 Google Play 服务版本控制不匹配,但是他们向我发送了使用最新版本 (42.1001.0) 的包装器的更新版本我已经确认它与我们的应用程序匹配。此外,他们自己的示例 Android 项目编译得很好。我梳理了他们的示例 Android 项目中的每个设置,并将其更改为与我的相匹配,但他们的仍然可以编译,而我的不能。
这是我的 Android 项目中的 packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="modernhttpclient" version="2.4.2" targetFramework="MonoAndroid60" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="MonoAndroid60" />
<package id="Rx-Core" version="2.2.5" targetFramework="monoandroid70" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="monoandroid70" />
<package id="Rx-Linq" version="2.2.5" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Fragment" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Media.Compat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v13" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v4" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.1" targetFramework="monoandroid70" />
<package id="Xamarin.Build.Download" version="0.4.3" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Common" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.Firebase.Iid" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Analytics.Impl" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Base" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Basement" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gcm" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Iid" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Location" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Maps" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.TagManager.V4.Impl" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Tasks" version="42.1001.0" targetFramework="monoandroid70" />
</packages>
下面是有效的示例 Localytics 项目的 packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Xamarin.Android.Support.Compat" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Core.UI" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Core.Utils" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Design" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Fragment" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Media.Compat" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Transition" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v4" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.CardView" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.MediaRouter" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.Palette" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="25.1.1" targetFramework="MonoAndroid70" />
<package id="Xamarin.Build.Download" version="0.4.3" targetFramework="MonoAndroid70" />
<package id="Xamarin.Forms" version="2.3.3.193" targetFramework="MonoAndroid70" />
<package id="Xamarin.GooglePlayServices.Base" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Basement" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Clearcut" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gass" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Gcm" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Iid" version="42.1001.0" targetFramework="monoandroid70" />
<package id="Xamarin.GooglePlayServices.Tasks" version="42.1001.0" targetFramework="monoandroid70" />
</packages>
要重现问题...
Here 是 Localytics SDK Xamarin 包装器的最新代码,构建得很好。您需要获取 .xam 文件并使用 Xamarin-Component 将其安装到 Xamarin Studio。
Here 是我的 Android 项目代码的精简版。
对于我的项目的大小,我深表歉意,我删除了所有代码和资源,但由于组件和包的原因,它仍然很大,我不想删除它们,因为它们与问题相关。您需要打开 RPR Mobile - Android.sln 解决方案,更改为 Release-Prod,然后尝试构建,您会看到错误。
有什么想法吗?
此 PATCHED
版本附带的组件似乎未更新以包含您需要的参考,例如 Xamarin.GooglePlayServices.Iid
。
您很可能需要重新制作此组件或让供应商为您重新制作。关于最终 .dll
被添加到您的项目中,这里似乎存在缓存问题。