locked
Issues trying to debug on 4.0.3 device RRS feed

  • Question

  • User343482 posted

    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!

    Thursday, October 1, 2020 10:38 AM

Answers

  • User89714 posted

    @clopez said: 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;

    According to https://docs.microsoft.com/en-us/dotnet/api/android.widget.textview.linespacingmultiplier?view=xamarin-android-sdk-9 , getLineSpacingMultiplier first appeared in API 16, which means Android 4.1. You won't be able to use that method on Android 4.0.3 and need to build against at least SDK 16 to use it with later Android versions.

    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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, October 1, 2020 3:52 PM
  • User369979 posted

    As @JohnHardman said, the lowest supported version is 4.4. The official documentation has clearly clarified this. Maybe you could run it on some lower version devices but there may be some potential issues. And we won't support this sort of issue. 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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, October 2, 2020 6:13 AM

All replies

  • User343482 posted

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

    Thursday, October 1, 2020 1:13 PM
  • User89714 posted

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

    Thursday, October 1, 2020 3:41 PM
  • User89714 posted

    @clopez said: 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;

    According to https://docs.microsoft.com/en-us/dotnet/api/android.widget.textview.linespacingmultiplier?view=xamarin-android-sdk-9 , getLineSpacingMultiplier first appeared in API 16, which means Android 4.1. You won't be able to use that method on Android 4.0.3 and need to build against at least SDK 16 to use it with later Android versions.

    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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, October 1, 2020 3:52 PM
  • User343482 posted

    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.

    Thursday, October 1, 2020 4:00 PM
  • User369979 posted

    As @JohnHardman said, the lowest supported version is 4.4. The official documentation has clearly clarified this. Maybe you could run it on some lower version devices but there may be some potential issues. And we won't support this sort of issue. 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.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, October 2, 2020 6:13 AM
  • User343482 posted

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

    Friday, October 2, 2020 10:05 AM
  • User89714 posted

    @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

    Friday, October 2, 2020 10:42 AM
  • User343482 posted

    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.

    Monday, October 5, 2020 8:46 AM