-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make check for __ANDROID_API__ run time instead of compile time #1262
Comments
You can do this with dlopen/dlsym, but it's not the most ergonomic thing in the world. We've occasionally talked about making this a bit easier by making weak symbols for everything, but that doesn't help when the whole library is unavailable in your minSdkVersion. Plus, since there are no strong checks for this, it would be really, really easy to forget the condition (or more likely not even know it's required). My preferred answer to this problem is to hide all the ugliness in jetpack. It can do all the dlsym crap on your behalf and provide a fallback implementation when it's not available, or have some easier conditional access method when no fallback is possible. |
(had closed because I'm fairly certain we already have something open for this, but I don't want to dig it up on my phone so I'll try to find it tomorrow) |
I always tought the Android NDK Native APIs .so files come with the Android OS and only the header files are distributed via gradle & NDK ? If you are worried about accidental use what about replacing
With something like that:
Then every app developer can use it like this:
|
I did some experiments. First, I tried to recreate the above idea by re-defining macros. This did not work. Snippet:
However, manually passing Is there any disadvantage to manually specifying |
A scary looking macro only solves part of the problem (you still have no way to weakly load the library that didn't exist in your minSdkVersion), and there's no way to ensure that some third party dependency won't infect the user's build. If you depend on libfoo and foo.h does |
Here's the original bug: #837. Going to move this discussion over there. |
I'm always frustrated when I cannot use newly introduced NDK features because I am limited by my minSdkVersion . I understand that it is not possible to support them on older devices, but I don't understand why I cannot use NDK features introduced after my minSdkVersion on Devices where the OS is higher than my minSdkVersion.
E.g. I want to do somtehing like this:
But NOT evaluated at compile time but rather at run time.
Is that possible ? You could compile your native code multiple times for each minSdkVersion but that seems like unneccesary hustle to me.
The text was updated successfully, but these errors were encountered: