NewApi error : Finds API accesses to APIs that are not supported in all targeted API versions


❗️ NewApi error: Finds API accesses to APIs that are not supported in all targeted API versions

The above lint error message is displayed for your Android project when you use a method form an API that is not supported by all the Android APIs levels that you target.

Solution

You can either change the minSdkVersion and targetSdkVersion in your AndroidManifest.xml for unsupported APIs.

If you want to support all versions that you have stated in AndroidManifest then you need to use "Conditional execution" i.e. add conditions in your code based on the API level.

if (android.os.Build.VERSION.RELEASE.startsWith("2.")  {
  //Some code
}
else if (android.os.Build.VERSION.RELEASE.startsWith("3.")  {
  //Some code
}
 else {
  //Some code
 }

You can also use @TargetApi annotation to set the SDK level to apply to your code, example

@TargetApi(18)
public class DoSomething {
   //You Code
}

The above code will consider API level 18 rather than what is being defined in the AndroidManifest.xml file. But not that you cannot use @TargetApi for a method.

✌️ You can use tools:targetApi="" in the Android XML files to support certain API levels.

Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency