1

I have an Android Xamarin appliation with android:minSdkVersion="15" and android:targetSdkVersion="21". Turned out that IDE (xamarin studio, visual studio) and compilation process just ignore if I'm using something above API 15 which is not expected behavior here.

For example there is a method Path.addArc(float,float,float,float,float,float) from API 21 and I was able to use it with the manifest settings above which gave me a run-time error NoSuchMethodError.

There is an easy fix to use an overload Path.addArc(RectF,float,float) from API 1 but my question is more about how to get a compile time error instead or a run-time.

[UPDATE]

Basically I want to maintain the backward compatibility for API 15 (minimum android version) while having API 21 as a target android version. And I want to get an IDE support when I'm trying to use any method above API 15. That means I need a warning saying that I'm using a method which doesn't exist in the minimum android version defined so please do a run-time version check.

Is it possible?

Mando
  • 11,414
  • 17
  • 86
  • 167

1 Answers1

1

To get compile time warnings you need to set your Target Framework to the min SDK you want to support. This will give you errors when you try to use higher level apis. Open Project Options dialog. In this dialog, click Build > General

You can read about api levels here https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/#Target_Framework

If you just want to get an error while keeping the target framework the same you can modify your IDE preferences to throw a compile time error vs a warning. enter image description here

Andres Castro
  • 1,848
  • 16
  • 16
  • Thank you for the link, and you are absolutely right, to get a compile time error you have to switch compilation API level to a desired one. Probably my question was not clear, I will refine it, but basically I want to maintain that backward compatibility for API 15 (minimum android version) while having API 21 as a target android version. And I want to get an IDE support when I'm trying to use any method above API 15. That means I need a warning saying that I'm using a method which doesn't exist in the minimum android version defined so please do a run-time version check. Is it possible? – Mando Apr 08 '16 at 20:12
  • 1
    Updated the answer. You can change your settings in Xamarin studio to accomplish this. – Andres Castro Apr 08 '16 at 20:16
  • sweet, that's exactly what I need. Funny thing here is that it's marked as error (I chose error) with a redline but allows me to run the build (and crash of course). But anyway, this is already enough to detect those kind of issues during development. – Mando Apr 08 '16 at 20:30