Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Issues trying to debug on 4.0.3 device

clopezclopez ESMember ✭✭✭

Hello there!

I have a project that was working OK. I was testing on a device with Android 4.1.1, so I have set the Android configuration with that version as the minimum. Compilation SDK and target are set as 9.0. So far, so good.

But now, I need to try it on a 4.0.3 Android device and I'm having issues.
Of course, I changed minimum version, I installed Android SDK PLatform 15 from SDK Manager in Visual Studio 17, cleaned project, restart... But when I try to debug, this exception appears:

Java.Lang.NoSuchMethodError: no method with name='getLineSpacingMultiplier' signature='()F' in class Landroid/widget/TextView;

I was googling for half and an hour looking for some clue. Of course, it looks like some methods are no working because it's a very old version of Android, but I have no choice but to make it works in this device, with no chance of updating it.
The most similar answer I got was this thread:
https://forums.xamarin.com/discussion/161342/java-lang-nosuchmethoderror-no-method-with-name-getlinespacingmultiplier-signature-f-in-class
But setting Minimum version to 4.1.1 doesn't let me debug on the device (and I need to check some HW behaviour).

What can I do?
Is there a way to override all the non-existing methods like the above mentioned, if there is no way I can set the environment to test it?

Thank you!

Best Answers

Answers

  • clopezclopez ESMember ✭✭✭
    edited October 1

    So, after two hours and a half, I can isolate the error. Any label of my first xaml page is throwing this exception, even if the label XAML code is totally empty, so there's something in Android \<Label> that is not backwards compatible.

    I don't know how to solve this. Is there a way to add the attribute to Label manually if SDK version is <16? I can't do an APP without labels.

  • JohnHardmanJohnHardman GBUniversity admin
    edited October 1

    @clopez

    Officially (according to documentation at https://docs.microsoft.com/en-us/xamarin/get-started/supported-platforms ), the minimum Android version supported by Xamarin.Forms is 4.4 . Having said that, I still have Xamarin.Forms code running successfully on Android 4.2.2 (I tested it this week and a large, complex app built with XF 4.8 worked fine). I'm sure I used to have code running on even earlier 4.x versions, but I don't have a suitable physical test device handy to check that the code still runs on those. But, for anything before 4.4, there are no guarantees that things will work, and an expectation that we have to do more work implementing workarounds to get things operational.

  • clopezclopez ESMember ✭✭✭

    Documentation has a lot of not updated pages, so I don't know if it's very reliable :D
    Jokes asides, I was able to run another APP I did in this device. Just run, not fully tested.
    It turns out that the APP that runs was done with Xamarin.Forms v3.0.0.561731, but in my current APP, I upgraded it to 3.4.0.1009999. I just tried to "downgrade" it in order to test if it runs, but I have to do a lot of changes just to see if it will works, so is not worth the effort (unless it's mandatory to use this device).

    If I could override methods and properties missing in older versions of SDK, I wouldn't have this problem, but I don't know if it's possible or not, and how.

  • clopezclopez ESMember ✭✭✭

    @JohnHardman said:
    To run against 4.0.3, you'd need to prevent calls being made to getLineSpacingMultiplier (there may be other methods too). The easiest thing is probably to search the XF source code to see where it is used and then to implement custom renderers etc to avoid it being called. It may be (it probably is) more work than it's worth though.

    Well, since I checked that just an empty label just calls "getLineSpacingMultiplier", then it's impossible for me to avoid that issue.
    I didn't check the minimum version because, well, Visual Studio allows me to use even Android 2.6. I don't know if it's because I'm not updated or something like this, but since you and LandLu said so, I will try to update the HW.

    @LandLu said:
    Besides, Xamarin Forms has reached 4.8. I highly recommend using the latest version of Xamarin Forms. It has fixed lots of issues that could exist in the older versions.

    Yes, I know, and I know there are a lot of new amazing features, but I can't use latests versions, because I don't have time to deal with compatibility issues.
    As usual, I have pretty big projects I'm developing alone, and solving obsolete functions, different behaviours in others, etc in APPs I'm deploying, will take a lot of effort. Also, "customers" usually have pretty old devices, as I shown in the main post, so I'm afraid that if I update to the last version, I couldn't develop to 4.4, or have performance issues.

    In almost 3 years, I went from 3.0 to 3.4, and it was because I'm doing a new project, but I was afraid to do a very big jump with so many time to finish it.

  • JohnHardmanJohnHardman GBUniversity admin

    @clopez said:
    Well, since I checked that just an empty label just calls "getLineSpacingMultiplier", then it's impossible for me to avoid that issue.

    Not impossible at all, just a maintenance headache. Having just done a quick search, LineSpacingMultiplier (in the version of the codebase that I checked) is only present in the Android LabelRenderer implementations (the classic one and the fast one). For the classic one, a custom renderer that overrides OnElementChanged should do the trick. For the fast one, you'd need to pretty much replicate the existing one, but leaving out use of LineSpacingMultiplier. Neither is difficult, but both introduce fragility when you update XF versions, hence the maintenance headache.

    TBH, if you're aiming to support Android pre 4.4, Xamarin.Forms may not be the thing to use. I try to keep my code running on old versions of Android, but if it does work on those versions I consider that a bonus. If it were essential that my code run on those versions I wouldn't be using Xamarin.Forms

  • clopezclopez ESMember ✭✭✭

    I never tried to override a Xamarin element before (nor needed to do a custom renderer), but as far as I read about this, I should create a new tool, derive the label, then override the methods I don't want to use getLineSpacingMultiplier and then change the basic Label with my NewLabel. Am I wrong?

    But then, what about >4.4 versions of Android? Can I use the overriden method instead of the override one?
    No, I think I should go with 4.4 devices and up only... and ask about this just for learning.

Sign In or Register to comment.