Issue
I'm developing an Android app that uses NDK features. My app defines android:minSdkVersion
and android:targetSdkVersion
in AndroidManifest.xml
and APP_PLATFORM
in jni/Application.mk.
My current understanding is that android:minSdkVersion
decalres minimal supported OS version, android:targetSdkVersion
declares Java library version to be linked against, and APP_PLATFORM
declares C++ library to be linked against.
Two questions:
Is my understanding correct?
Is it Ok for
APP_PLATFORM
to be greater thatandroid:minSdkVersion
? Or they must be equal each other?
The reason for my question: I want my app to be available for devices with API >= 10, but I need to use NDK functions (like AMotionEvent_getAxisValue
) that are defined in platforms\android-13
folder in NDK. So I use android:minSdkVersion=10
and APP_PLATFORM=13
. Project compiles successfully, but would it be runnable on API 10-12 devices?
Solution
android:minSdkVersion
is the minimum OS version that your app expects.android:targetSdkVersion
is essentially the maximum OS version that you've designed your app to work with. Here's an example of how this works. Imagine that you tested your app fine with API 19 and you release your app withandroid:targetSdkVersion
=19. Then Google decides to release API 20 with a change in behavior of some API, but they don't want to change the behavior for old apps (to prevent from breaking them). So when your app starts up, Android sees that your app hastargetSdkVersion
=19, so it gives you the old API behavior, but if some other app saystargetSdkVersion
=20, Android will give it the new API behavior.APP_PLATFORM
is the version of the native headers and libraries that the NDK will compile your native code with. If you setAPP_PLATFORM
to a specific value and you use APIs that are only available in that platform version, then your app will not run properly on older platforms. SoAPP_PLATFORM
is a minimum value. The solution is to use a lower value and not use those newer APIs, or to write code that decides at runtime whether to call the new APIs or not (and probably usedlopen
/dlsym
).
It seems like in general it doesn't make sense to use an APP_PLATFORM
value newer than android:minSdkVersion
, unless you're doing some special (like being careful not to call new APIs by checking the version at runtime, plus making sure not to link to new APIs and instead using dlopen
/dlsym
).
So if you use APP_PLATFORM=13
and you call AMotionEvent_getAxisValue
(which is not in earlier platform headers, implying that it isn't available at runtime on earlier platforms), your app will not run on devices with API < 13. The one caveat would be if AMotionEvent_getAxisValue
is actually available on older versions, but it just wasn't in the header/library files or it just wasn't documented. But I don't know if that's the case for this particular API (basically, that would require more research and risk analysis of whether you want to depend on something unsupported).
Answered By - Xargs
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.