简体   繁体   中英

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. I need to make use of a 3rd party SDK written in Java for functionality related to Push messaging. For the Android side of the solution, I have tried many, many things (over the course of days now), but have not been successful. I would like to solve for the following solution:

  • Have a PCL/Portable "myApp" library for common code/UI features.
  • Have the PCL/Portable library reference a "myApp.Android" assembly for Android-specific code.
  • Have the "myApp.Android" library reference a "myApp.Android.BindSDK" assembly for wrapping/binding to the 3rd party SDK.
    The myApp.Android.BindSDK assembly should (I believe):
  • Use Xamarin's binding features to bind/wrap/include my 3rd party's SDK written in Java.
    It has late bound dependencies on classes/functionality from Google Play services.
  • Use NuGet to include Xamarin.GooglePlayServices.Gcm into the ".Android.BindSDK" project.

Ever since including Google Play Services to the myApp.Android.BindSDK project via NuGet, I get the following compilation error:

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.

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?

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:

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:

<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)

In the Resources directory, create a values folder and add a values.xml file with the google_play_services_version integer value:

<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....

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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