Google Play Services (Froyo) Xamarin Component - doesn't work in Release Mode??

Hi all,

I've been using the Google Play Services (Froyo) component in my project for a good while now with no problems during development.

However, I've just tried to build in Release for the first time, having always built in Debug before. Attempting to build produces a linker error:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: Error: Error executing task LinkAssemblies: error XA2006: Reference to metadata item 'Android.App.Fragment' (defined in 'GooglePlayServicesFroyoLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') from 'GooglePlayServicesFroyoLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved.

I was originally using Rev 10 of the component, I've tried updating my Android SDK, and installing instead new Rev 12 version of the Google Play Services (Froyo) 12 Xamarin Component - but still no joy. It builds in Debug, but not release.

Any ideas??

Posts

  • NickTalbotNickTalbot USMember
    edited September 2013

    Fixed it - now builds.

    In release mode, the standard Linker setting is 'Link SDK assemblies'

    I've changed it to 'Link all assemblies' and the solution now builds.

    There's obviously some reflection/trickery going on with the Google Play component that only works if 'full fat linking' is done.

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    I'm surprised the component works with rev 12 of Google Play Services - the linker must be stripping out the parts that are breaking your build.

    Currently the component only supports rev 10 of Google Play Services.

  • NickTalbotNickTalbot USMember
    edited September 2013

    Hi Tom, I've been working with the Rev 10 version up until just right now. Why is there a Rev 12 version of the component in the Xamarin Component store then? (which I've just installed)

    Edit: Hmm, I;m not convinced I'm building this correctly, no APK is being produced. I'll get back to you ...

    Edit Edit: Ah! Have to do 'Publish Android Application' in Xamarin Studio!

  • NickTalbotNickTalbot USMember
    edited September 2013

    Hmm .. ok, I can build and deploy a release build to a device, but when it runs it crashes immediately.

    Logcat reveals:

    [monodroid-gc] GREF GC Threshold: 46800
    [] Missing method .ctor in assembly System.Core.dll, type System.CLSCompliantAttribute
    [] Can't find custom attr constructor image: System.Core.dll mtoken: 0x0a000fb6
    [] * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/bdc709d1/source/mono/mono/metadata/class.c:5594, condition     `!mono_loader_get_last_error ()' not met
    

    Any ideas??

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Can you post the entirely of logcat?

  • NickTalbotNickTalbot USMember

    Hi Tom, there sin't much more than that:

    [monodroid-gc] GREF GC Threshold: 46800
    [] Missing method .ctor in assembly System.Core.dll, type System.CLSCompliantAttribute
    [] Can't find custom attr constructor image: System.Core.dll mtoken: 0x0a000fb6
    [] * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/bdc709d1/source/mono/mono/metadata/class.c:5594, condition `!mono_loader_get_last_error ()' not met
    [mono-rt] Stacktrace:
    [mono-rt] 
    [mono-rt] 
    [mono-rt] =================================================================
    [mono-rt] Got a SIGSEGV while executing native code. This usually indicates
    [mono-rt] a fatal error in the mono runtime or one of the native libraries 
    [mono-rt] used by your application.
    [mono-rt] =================================================================
    [mono-rt] 
    
  • NickTalbotNickTalbot USMember

    Ok, panic over, I have managed to get a release version buidling and running now.

    Had to add to the Release Linker Options for Ignore Assemblies: mscorlib

    Now runs.

  • NickTalbotNickTalbot USMember

    Spoke to soon! The first activity works and runs, but another has a similar problem now:

    [] Missing method .ctor in assembly System.Core.dll, type System.ComponentModel.EditorBrowsableAttribute [] Can't find custom attr constructor image: System.Core.dll mtoken: 0x0a00006f [] Missing method .ctor in assembly System.Core.dll, type System.ComponentModel.EditorBrowsableAttribute [] Can't find custom attr constructor image: System.Core.dll mtoken: 0x0a00006f [] * Assertion at /Users/builder/data/lanes/monodroid-mlion-monodroid-4.8.2-branch/bdc709d1/source/mono/mono/metadata/class.c:5594, condition '!mono_loader_get_last_error ()' not met [mono-rt] Stacktrace: [mono-rt] [mono-rt] at <unknown> <0xffffffff> [mono-rt] at SocketIOClient.EndPointClient.Emit (string,object,System.Action1) <0x001df>`

  • NickTalbotNickTalbot USMember

    Hmm, I got a bit further again by setting the ignore assemblies to mscorlib;System

    But then I just a got a different crash instead.

    For now, I've removed those ignore assembly options, and just changed the Release Android Build Linker Optiion behaviour to 'Don't Link'.

    My app now works in Release mode as it does in Debug (which has 'Don't link' by default)

    The app size has grown from 15Mb to 31Mb though - but it does run at least.

    Maybe later I can set the option back to Link all assemblies, and ignore the ones that I need to?

    Btw, this is now working with Rev 12 of the Froyo Google Play Component now.

  • PedroPachoPedroPacho ESMember

    I have the same problem with the revision 10 and 12.
    Maybe the error is because of this?
    The library GooglePlayServicesFroyoLib can't load Mono.Android, like the image shows.

  • NickTalbotNickTalbot USMember

    Hi Pedro - yep I've sees the same thing. I gave up and changed Release linking to 'Don't Link'. This increases your release size, but it does run properly release mode then.

  • PedroPachoPedroPacho ESMember

    Thanks Nick for your help but I don't want to upload an app to the Google Play Store too big.
    Why this error happens?

  • NickTalbotNickTalbot USMember
    edited September 2013

    I feel the same, but setting 'Don't link' is the only cast-iron way to get a fully working Release Build.

    The alternative (as I tried, explained earlier above in the thread) is to set the Release Linker option to 'Link all assemblies'. This will then at least build, but not run properly. The default setting of 'Link SDK assemblies' doesn't even build.

    With the linker set to 'Link all assemblies', the Linker attempts to scan the built application, and remove library code that is not called by your app. This is how it gets the size of the application down, by removing unneccesary unused library code.

    However, it does based on looking at what code is statically called, but NOT dynamic or reflection-invoked code. So, any code called this way will not run, as the linker doesn't think that code is necessary, where it really is needed.

    The Google Play component obviously uses code in this way, as a release build with the linker turned on doesn't run due to missing library code.

    It is possible to manually inform the linker that seemingly unneeded libraries should in fact be kept. You do this by filling in the 'Ignore Libraries' field ('Ignore' as in 'ignore this from the strip-it-out process). Unforuntately, you will have to keep fully testing your application to see what doesn't work and figuring out what assemblies should be listed in the ignore field.

    I got as far as Ignore assemblies: mscorlib;System - This got some of my app running but not all. I haven't got time to figure it out right now, so I went with 'Don't link' - my app is bigger but DOES run in release mode.

    If I have time before release (on a deadline) I'll have another go at figuring out the needed assmeblies. You'd have to do the same.

    Of course when running, you don't have the debugger, so to figure out the missing assemblies you'll have to run 'adb logcat' in a console with the phone connected by USB while running/testing the app in release mode, installed on your device.

    Good luck.

  • JaredKellsJaredKells AUMember ✭✭
    edited October 2013

    I'm not sure if this will help you but I've needed to create my own bindings as I want to link against Revision 18 of the support library from the component store instead of the one bundled with Xamarin Android.

    My bindings for google play services are here:
    https://github.com/jkells/xamarin-android-googleplayservices-binding

    I've been testing it on a Samsung Galaxy S1 running Android 2.2 and it seems to be working OK. I am only using the Maps part of the library however. ( This is with full linking, SDK and user assemblies )

  • PedroPachoPedroPacho ESMember

    Hi Nick! Thanks a lot for your explanation, it's very helpful.
    I was thinking in binding the Google play services client library manually because I can't upload an app so big to the Google store, and also I reckon it could be easier than using the option "link all assemblies" and after manually add all the libraries that I need.
    I don't really see the advantage of the Xamarin component option, in fact I have lost a lot time trying to solve this problem.

  • CTPAXCTPAX USMember

    @PedroPacho,

    This is showstopper for me as well. But I believe Xamarin Team should fix that in the nearest future. Hope it will be soon.

    Any comments from Xamarin Team?

  • SteveWhiteSteveWhite GBMember ✭✭

    I'm seeing the same thing. I've just had to ship a 30MB apk to my beta test team so they can at least test it. But there's no way I can ship this to the store.

    Any got any solution to this?

  • NickTalbotNickTalbot USMember

    I finally got a running release build by filling in the 'Ignore Assemblies' with the 'Link all Assemblies' option.

    I had to ignore mscorlib;System and one of my own self built assemblies. Does seem to run now.

  • NickTalbotNickTalbot USMember

    OK - This linker problem is still a Major Problem!!

    More testing has revealed that in Release Mode, using the above 'Ignore Assemblies' with the 'Link all Assemblies' option, our app has a Maps Bug:

    When the device is rotated and the fragments recreated, the map fragment does not work properly - the items that we manually draw onto the map do not appear.

    In both Debug AND Release-Do No Link - the app behaves perfectly.

    There is a MAJOR problem in the Release Linker somewhere - please help Xamarin!!

    As It stands, I will have to ship a 30MB 'Do not link' Release version!!

  • KarenCateKarenCate USMember ✭✭

    That's interesting... My app will only link with "Link SDK assemblies only". I don't use Google Play. If I try to link all assemblies, I get an error that I need to include a reference to Mono.Android.Export.dll if I use ExportAttribute or ExportFieldAttribute. I do have a reference to Mono.Android.Export.dll. I tried listing Mono.Android.Export (with and without the .dll) on the Ignore assemblies line, but that didn't help.

    Anyway, I wanted to agree that there are some significant linker problems at the moment. By linking the SDK assemblies, I got my app from 24MB to 5.5MB, but it really shouldn't even be that big.

    Also, if you right click on the error message, there is an option to "Show Error Reference", which brings up the Apple help tool, but no information on this error can be found. The name of the assembly that can be added to the Ignore assemblies line would be handy.

  • SteveWhiteSteveWhite GBMember ✭✭

    Any chance of some help for this from someone at Xamarin?

    I've tried all versions of the Froyo component and I can't get any of them to build in Release with linking SDK assemblies.

    The build failure is: Failed to resolve Android.App.Fragment

  • NickTalbotNickTalbot USMember

    Agreed .. bump ..

  • CTPAXCTPAX USMember

    I got the answer from xamarin support. The issue is reproduced on examples:
    https://github.com/xamarin/monodroid-samples/tree/master/MapsAndLocationDemo_v2

    You can correct the binding by using the "old" style of building the Google
    Play Services binding (rather than the Play Services component).

    1. Open the MapsAndLocationDemo_v2 sample directory.

    2. Run the shell script to build the Google Play Services library project:
      ANDROID_HOME=/Users/user/Library/Developer/Xamarin/android-sdk-mac_x86 sh
      add_play_services.sh

    3. Open the GooglePlayServices_Froyo project in the MapsAndLocationDemo2
      solution.

    4. Add the following line to Transforms/Metadata.xml:

    5. Build the GooglePlayServices_Froyo project.

    6. Copy the generated "GooglePlayServicesFroyo.dll" from the
      GooglePlayServices_Froyo/bin/ folder to the MapsAndLocationDemo_v3 project
      directory.

    7. Delete the Google Play Services component & reference from the
      MapsAndLocationDemo_v3 SimpleMapDemo_Froyo project.

    8. Add a reference to GooglePlayServicesFroyo.dll.

    9. Build SimpleMapDemo_Froyo in Release mode, with "Link SDK assemblies only."

    ======

    Note: if you're using the beta Xamarin.Android version 4.8.3, you don't need to
    modify the Metadata.xml at all. The bindings generator in Xamarin.Android 4.8.3
    has been corrected so that it automatically leaves out the MapFragment class.

    Once Xamarin.Android 4.8.3 is released to the stable channel, an updated
    version of the Google Play Services component will be built and released. That
    new version of the component should eliminate this bug.

    =====

    I have no change to build another binding because under Windows it takes additional efforts.
    Will try soon.

  • NickTalbotNickTalbot USMember

    Ok, I'll try this later on this week or weekend. Before the Xamarin Google Play component was available, I did get the 'create a binding project yourself' version working. I'll have to gid that back out and update it and try again it looks like then

  • CTPAXCTPAX USMember

    @coachingsessions.net have solution here by using Alpha channel:
    http://forums.xamarin.com/discussion/comment/29756#Comment_29756

    Hope it helps.

  • SteveWhiteSteveWhite GBMember ✭✭

    I'm still seeing this with the following:

    • Xamarin Android 4.8.3
    • Google Play Services rev 12 in SDK Manager
    • Google Play Services (Froyo) Rev 12 Xamarin Component
    • Mono.Android.Support.v4 via References

    • Build in Release with linker as 'Link SDK assemblies only'

    • Clean All
    • Build All

    Error:

    Reference to metadata item 'Android.App.Fragment' (defined in 'GooglePlayServicesFroyoLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') from 'GooglePlayServicesFroyoLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' could not be resolved.

    The error has changed from my previous try, but this is still stopping building in Release with linking. I need to get this sorted because I can't ship to the store with a 30MB product!

    Any help please?

  • NickTalbotNickTalbot USMember
    edited October 2013

    Hiya Steve, I've just shipped with a 29MB APK - I couldn't wait!

    Hope it gets fixed soon for an upgrade

  • SteveWhiteSteveWhite GBMember ✭✭

    Hi Nick, I just tested the above with the linker set to 'Link all assemblies' to see what would happen.

    It built with an apk size of 10MB!

    I'm going to do further testing and ship this out, I can live with that.

  • NickTalbotNickTalbot USMember

    I couldn't get a build to compile with Link all assemblies due to a missing attribute - but if you can then give it a whirl!

    Really hope Xamarin get this linker problem fixed soon

  • CTPAXCTPAX USMember

    It's available in the component store today, and the MapFragment type is no longer present!
    You can use GooglePlayServicesFroyo 12.0.1 component right from Xamarin component store and it works fine with SDK Only linker option.

    I just submitted my version to the store and happy with it. Good Luck

  • NickTalbotNickTalbot USMember

    Hi Ctpax - I've posted some comments here: http://forums.xamarin.com/discussion/8943/google-play-services-froyo-xamarin-component-update-incl-actionbarsherlock#latest

    The GooglePlay Services component does seems to be fixed now! However, I need the same treatment for the Xamarin ActionBarSherlock component too until I can use the 'Link SDK' option.

  • CTPAXCTPAX USMember

    Nick, thanks for update. I had to avoid using ActionSherlockBar and implement my own lightweight bar because I was unable to use it in my app powered by MvvmCross.

  • NickTalbotNickTalbot USMember

    We're all at the bleeding edge (even further than the cutting edge!) unfortunately :-/

    I'm sure in the next few months this will have all calmed down - the V4 native ActionCompatiblity library will be available by then in Xamarin (which it currently isn't). That's why I had to go with ActionBarSherlock, but as we're currently seeing, it doesn't play nicely with the existing Xamarin Google Play component.

    I'm waiting for an updated Xamarin ActionBarSherlock and any updated Android Linker to have moved to Beta from Alpha - I can't convince myself to publish a release using Alpha software!

  • dror.4552dror.4552 USMember

    I've been able to find a workaround.
    Try my dll:
    http://wikisend.com/download/371206/Google.PlayServices.Froyo.dll

  • NickTalbotNickTalbot USMember

    Hi Dror, what's the workaround?

  • dror.4552dror.4552 USMember

    Well actually all I had to do is link the java library myself.

  • MatthewSanders.7587MatthewSanders.7587 AUMember
    edited December 2013

    Hi, I've just posted a solution to my similar problem :http://forums.xamarin.com/discussion/10443/application-won-t-start-in-release-mode-can-t-find-custom-attr-constructor-image-system-core-dll#latest
    I hope it helps you solver your issues. (or move you on to the next one at least)

  • van8tkavan8tka RUMember ✭✭

    After 3 years that problem is not resolve.. anybody has answer, how fix this problem?

Sign In or Register to comment.