APP_PLATFORM,android:minSdkVersion和android:targetSdkVersion之间是什么关系? [英] What is the relation between APP_PLATFORM, android:minSdkVersion and android:targetSdkVersion?

查看:128
本文介绍了APP_PLATFORM,android:minSdkVersion和android:targetSdkVersion之间是什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用NDK功能的Android应用程序.我的应用在jni/Application.mk中的AndroidManifest.xmlAPP_PLATFORM中定义了android:minSdkVersionandroid:targetSdkVersion.

我目前的理解是android:minSdkVersion降低了支持的最低操作系统版本,android:targetSdkVersion声明了要链接的Java库版本,而APP_PLATFORM声明了要链接的C ++库.

两个问题:

  1. 我的理解正确吗?

  2. APP_PLATFORM大于android:minSdkVersion还可以吗?还是必须彼此平等?

我提出问题的原因:我希望我的应用程序可用于具有 API> = 10 的设备,但我需要使用在AMotionEvent_getAxisValue) > NDK中的文件夹.所以我用android:minSdkVersion=10APP_PLATFORM=13.项目可以成功编译,但是可以在API 10-12设备上运行吗?

解决方案

  1. android:minSdkVersion是您的应用程序期望的最低操作系统版本.

  2. android:targetSdkVersion本质上是您设计应用程序可以使用的最高操作系统版本.这是一个如何工作的示例.假设您使用API​​ 19对应用程序进行了良好的测试,并使用android:targetSdkVersion = 19发布了应用程序.然后,Google决定发布API 20并更改某些API的行为,但他们不想更改旧应用程序的行为(以防止破坏它们).因此,当您的应用程序启动时,Android会发现您的应用程序具有targetSdkVersion = 19,因此它为您提供了旧的API行为,但是如果其他一些应用程序将其显示为targetSdkVersion = 20,则Android将为其提供新的API行为./p>

  3. APP_PLATFORM是NDK用来编译本机代码的本机头和库的版本.如果将APP_PLATFORM设置为特定值,并且使用仅在该平台版本中可用的API,则您的应用将无法在旧平台上正常运行.因此APP_PLATFORM是最小值.解决方案是使用较低的值而不使用那些较新的API,或者编写在运行时决定是否调用新API的代码(可能使用dlopen/dlsym).

通常来说,使用比android:minSdkVersion更新的APP_PLATFORM值似乎没有任何意义,除非您做了一些特殊的操作(例如注意不要通过在运行时检查版本来调用新的API,并确保不要链接到新的API,而是使用dlopen/dlsym).

因此,如果您使用APP_PLATFORM=13并调用AMotionEvent_getAxisValue(在较早的平台标头中不存在,这意味着它在较早的平台上无法在运行时使用),则您的应用程序将无法在API< 13.一个警告是,如果AMotionEvent_getAxisValue实际上在较旧的版本中可用,但是它没有出现在头文件/库文件中,或者只是没有记录在文件中.但是我不知道这种特定的API是否会出现这种情况(基本上,这需要进行更多的研究和风险分析,以确定是否要依赖不受支持的内容).

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:

  1. Is my understanding correct?

  2. Is it Ok for APP_PLATFORM to be greater that android: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?

解决方案

  1. android:minSdkVersion is the minimum OS version that your app expects.

  2. 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 with android: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 has targetSdkVersion=19, so it gives you the old API behavior, but if some other app says targetSdkVersion=20, Android will give it the new API behavior.

  3. APP_PLATFORM is the version of the native headers and libraries that the NDK will compile your native code with. If you set APP_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. So APP_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 use dlopen/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).

这篇关于APP_PLATFORM,android:minSdkVersion和android:targetSdkVersion之间是什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆