-1

I have Android SDK installed in two different folders (slightly different versions) two copies of the same project open in both (that is, SDK1 - Project1; SDK2 -> Copy of Project1). SDK1 works fine, but SDK2 shows an error

Call requires API level 13 (current min is 8): android.view.Display#getSize  

at the line

getWindowManager().getDefaultDisplay().getSize(p);  

In the MainActivity class. How do I remove this?
(I am pretty sure this has something to do with the compiler options or something; SDK2 suggests that I just add @SuppressWarning to onCreate() while I don't need to do anything with SDK1; would simply suppressing warning be enough, or would it break my program in unexpected ways later)?

user13267
  • 6,871
  • 28
  • 80
  • 138
  • change your min sdk to 13 in manifest – Raghunandan Oct 08 '13 at 10:05
  • Based on the error message, it's possible that your app will break if the user is using HoneyComb (API 12) or older since the method is not existed yet in those version. – Andrew T. Oct 08 '13 at 10:06
  • like I said, it is a copy of a project that runs without error in SDK1. Why doesn't SDK1 how any errors though? By the way, SDK1 is the slightly older version. – user13267 Oct 08 '13 at 10:32

2 Answers2

2

this warning tells you that the app can be run on SDK lower than 13, getDefaultDisplay() is available since API 13, so if you run it on lower SDK, you will get some kind of ClassNotFound or MethodNotFound exception. You have to manage this code for lower API levels.

To manage this, you can use the android.os.Build.VERSION.SDK_INT which returns the current API level and add the @SuppressWarning annotation

EDIT: the reason you get this warning is that you use higher targetSdkVersion than minSdkVersion in your manifest

mihail
  • 2,173
  • 19
  • 31
  • like I said, it is a copy of a project that runs without error in SDK1. Why doesn't SDK1 how any errors though? By the way, SDK1 is the slightly older version. – user13267 Oct 08 '13 at 10:32
  • because the SDK become smarter - new warnings are added to make it easier for you to manage such kind of issues – mihail Oct 08 '13 at 10:49
  • in other words, if you compile it with the older SDK, this doesn't fix the problem, you just don't get informed about it. – mihail Oct 08 '13 at 10:50
  • so that means, at least for my test device, SDK2 should work the same as SDK1, if I just add the `@SuppressWarnings` ? – user13267 Oct 08 '13 at 11:06
  • 1
    SDK1 and SDK2 will run with no difference. The warnings has nothing to do with the final application. They are a product of code analyzer that informs you for potential problems. – mihail Oct 08 '13 at 11:22
2

The error explain itself you are calling a method or a class that doesn't exist before API 13 and your min API is 8! change to these lines in manifest.xml

<uses-sdk
    android:minSdkVersion="13"
    android:targetSdkVersion="13" />

you can keep your android:targetSdkVersion="13" in your project if its above 13

Ahmad Dwaik 'Warlock'
  • 5,953
  • 5
  • 34
  • 56
  • `android:minSdkVersion="8"` in SDK1 as well. Why isn't it showing any errors there? (By the way, SDK1 is the slightly older version.) – user13267 Oct 08 '13 at 10:31
  • yes its maybe the version difference between sdk1 and sdk2 or maybe you are missing some other details. check the project.properties file and let me know if you differece – Ahmad Dwaik 'Warlock' Oct 08 '13 at 10:43
  • project.properties files are exactly same, and has `target=android-18` below the #'ed comments – user13267 Oct 08 '13 at 11:07
  • but it looks like Mihail's post above answers the question – user13267 Oct 08 '13 at 11:12
  • accoring to http://developer.android.com/guide/topics/manifest/uses-sdk-element.html "Despite its name, this element is used to specify the API Level, not the version number of the SDK (software development kit) or Android platform" So it is the version difference between sdk1 and sdk2 – Ahmad Dwaik 'Warlock' Oct 08 '13 at 11:12
  • yes it seems to be due to the version difference; apparently this new error notification was added in the newer SDK – user13267 Oct 08 '13 at 11:13