Skip to content

fix: don't use @RequiresApi with old SDK versions#1107

Merged
kirillzyusko merged 4 commits intomainfrom
fix/requires-api-compilation-failures
Aug 29, 2025
Merged

fix: don't use @RequiresApi with old SDK versions#1107
kirillzyusko merged 4 commits intomainfrom
fix/requires-api-compilation-failures

Conversation

@kirillzyusko
Copy link
Copy Markdown
Owner

@kirillzyusko kirillzyusko commented Aug 29, 2025

📜 Description

Removed @RequiresApi annotations usage.

💡 Motivation and Context

When I was getting compilation issues due to usage of API which is not available in older versions I was constantly using first option provided by Android Studio: to add @RequiresApi annotation.

However it has some downsides:

  • if you mark one method with this annotation - all other methods must use the same annotation if they call this method;
  • this method is kind of semantic, and if you somehow accidentally call this method on older devices it will lead to crash.

So to make code structure a little bit cleaner I decided to remove those annotations and switch to if-statements. Initially the idea was to fix #1104, but turned out that [ObsoleteSdkInt] checks also if-statements. So for me as a library author there is only one reliable way to fix the issue is to suppress those warnings (if people set linter to treat warnings as errors it will prevent the lib from being compiled)

Closes #1104

📢 Changelog

Android

  • rewrite @RequiresApi to if-statements;
  • suppress new if-statements lint warnings via @SuppressLint;

🤔 How Has This Been Tested?

Tested in example app.

📝 Checklist

  • CI successfully passed
  • I added new mocks and corresponding unit-tests if library API was changed

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Aug 29, 2025

📊 Package size report

Current size Target Size Difference
212955 bytes 212959 bytes -4 bytes 📉

@kirillzyusko kirillzyusko merged commit 1edf41f into main Aug 29, 2025
16 checks passed
@kirillzyusko kirillzyusko deleted the fix/requires-api-compilation-failures branch August 29, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android Build failed on RN 0.81, ObsoleteSdkInt

1 participant