问题
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?
回答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.
来源:https://stackoverflow.com/questions/36507269/how-to-get-a-compile-time-error-instead-of-nosuchmethoderror-run-time-error-for