简体   繁体   English

Xamarin.Android通过AAR绑定的Google Play服务依赖性

[英]Xamarin.Android Google Play Services dependency via AAR Binding

I am using Visual Studio 2015 Update 3 to write a Xamarin cross-platform app for Android and iOS. 我正在使用Visual Studio 2015 Update 3编写适用于Android和iOS的Xamarin跨平台应用程序。 I need to make use of a 3rd party SDK written in Java for functionality related to Push messaging. 我需要利用Java编写的第三方SDK来实现与Push消息相关的功能。 For the Android side of the solution, I have tried many, many things (over the course of days now), but have not been successful. 对于该解决方案的Android方面,我已经尝试了很多很多事情(现在已经过了几天),但是没有成功。 I would like to solve for the following solution: 我想解决以下问题:

  • Have a PCL/Portable "myApp" library for common code/UI features. 有一个PCL /便携式“ myApp”库,用于通用代码/ UI功能。
  • Have the PCL/Portable library reference a "myApp.Android" assembly for Android-specific code. 让PCL / Portable库引用针对Android特定代码的“ myApp.Android”程序集。
  • Have the "myApp.Android" library reference a "myApp.Android.BindSDK" assembly for wrapping/binding to the 3rd party SDK. 让“ myApp.Android”库引用一个“ myApp.Android.BindSDK”程序集,用于包装/绑定到第三方SDK。
    The myApp.Android.BindSDK assembly should (I believe): myApp.Android.BindSDK程序集应该(我相信):
  • Use Xamarin's binding features to bind/wrap/include my 3rd party's SDK written in Java. 使用Xamarin的绑定功能来绑定/包装/包含我用Java编写的第三方SDK。
    It has late bound dependencies on classes/functionality from Google Play services. 它对Google Play服务的类/功能具有后期绑定依赖关系。
  • Use NuGet to include Xamarin.GooglePlayServices.Gcm into the ".Android.BindSDK" project. 使用NuGet将Xamarin.GooglePlayServices.Gcm包含到“ .Android.BindSDK”项目中。

Ever since including Google Play Services to the myApp.Android.BindSDK project via NuGet, I get the following compilation error: 自从通过NuGet将Google Play服务包含到myApp.Android.BindSDK项目中以来,我收到以下编译错误:

error APT0000: No resource found that matches the given name 
(at 'value' with value '@integer/google_play_services_version').

I have tried a lot of things posted on forums like cleaing the solution, deleting bin and obj folders, extracting the version.xml file from the JAR inside the AAR for Google Play, etc, etc, etc. It still gets this build error. 我已经尝试了很多在论坛上发布的内容,例如关闭解决方案,删除bin和obj文件夹,从AAR中的JAR中的JAR中提取version.xml文件以用于Google Play等,等等。它仍然会收到此构建错误。

Does anyone have a good example of how to create a Xamarin binding wrapper for an android/Java SDK that (itself) has dependencies on Google Play Services? 有没有人有一个很好的例子说明如何为本身依赖于Google Play服务的android / Java SDK创建Xamarin绑定包装?

Check to see if your binding project's .csproj contains the Xamarin.GooglePlayServices.Basement.targets as the resource task within that package is the one that extracts the Play Services version and adds it to your library's resources: 检查您的绑定项目的.csproj包含Xamarin.GooglePlayServices.Basement.targets因为该包中的资源任务是提取Play服务版本并将其添加到库资源中的任务:

Example: 例:

<Import Project="..\packages\Xamarin.GooglePlayServices.Basement.42.1001.0\build\MonoAndroid70\Xamarin.GooglePlayServices.Basement.targets" Condition="Exists('..\packages\Xamarin.GooglePlayServices.Basement.42.1001.0\build\MonoAndroid70\Xamarin.GooglePlayServices.Basement.targets')" />

Also check that the binding project manifest does not already contain an entry for com.google.android.gms.version as this should be auto-generated/merged by the build process: 此外,检查结合项目清单尚未包含一个条目com.google.android.gms.version ,因为这应该是自动生成/编译过程合并:

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

Workaround: 解决方法:

Note: I have never had to do this manually in my binding projects that included Play Services, I have come across some client's binding projects that cause the .aar resources merge process to fail on referenced packages (assuming there is a conflicting Play Services resource in the .aar but modifying the 3rd-party .aar is usually not worth it) 注意:我从来没有在包含Play Services的绑定项目中手动执行此操作,遇到了一些客户端的绑定项目,这些项目会导致.aar资源合并过程在引用的程序包上失败(假设在其中存在冲突的Play Services资源.aar但修改第三方.aar通常不值得)

In the Resources directory, create a values folder and add a values.xml file with the google_play_services_version integer value: Resources目录中,创建一个values文件夹,并添加一个带有google_play_services_version整数值的values.xml文件:

<integer name="google_play_services_version">10084000</integer>

Note: If the Google Play Services version changes you need to update the version value otherwise your app will end up throwing strange errors especially if you do InApp purchases.... 注意:如果Google Play服务版本更改,则需要更新版本值,否则您的应用最终会引发奇怪的错误,尤其是在您进行InApp购买时。

After much trial and error, I was able to create a working solution. 经过反复试验,我能够创建一个可行的解决方案。

How-To is provided in this post in detail . 这篇文章中详细提供了操作方法

Key: The thing that I had been missing above seems to have been to include the 3rd party SDK's dependencies not in the Binding Assembly eg: "myApp.Android.BindSDK" used to wrap the SDK, but instead via NuGet into the Solution's Android assembly that was referencing the Binding Assembly eg: "myApp.Android". 关键:我上面遗漏的东西似乎是在绑定程序集中不包含第三方SDK的依赖项,例如:用于包装SDK的“ myApp.Android.BindSDK”,而是通过NuGet进入解决方案的Android程序集引用绑定程序集,例如:“ myApp.Android”。

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

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